1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */

17 package org.apache.coyote;
18
19 public enum ErrorState {
20
21     /**
22      * Not in an error state.
23      */

24     NONE(false, 0, truetrue),
25
26     /**
27      * The current request/response is in an error state and while it is safe to
28      * complete the current response it is not safe to continue to use the
29      * existing connection which must be closed once the response has been
30      * completed. For multiplexed protocols, the channel must be closed when the
31      * current request/response completes but the connection may continue.
32      */

33     CLOSE_CLEAN(true, 1, truetrue),
34
35     /**
36      * The current request/response is in an error state and it is not safe to
37      * continue to use them. For multiplexed protocols (such as HTTP/2) the
38      * stream/channel must be closed immediately but the connection may
39      * continue. For non-multiplexed protocols (AJP, HTTP/1.x) the current
40      * connection must be closed.
41      */

42     CLOSE_NOW(true, 2, falsetrue),
43
44     /**
45      * An error has been detected that impacts the underlying network
46      * connection. It is not safe to continue using the network connection which
47      * must be closed immediately. For multiplexed protocols (such as HTTP/2)
48      * this impacts all multiplexed channels.
49      */

50     CLOSE_CONNECTION_NOW(true, 3, falsefalse);
51
52     private final boolean error;
53     private final int severity;
54     private final boolean ioAllowed;
55     private final boolean connectionIoAllowed;
56
57     private ErrorState(boolean error, int severity, boolean ioAllowed,
58             boolean connectionIoAllowed) {
59         this.error = error;
60         this.severity = severity;
61         this.ioAllowed = ioAllowed;
62         this.connectionIoAllowed = connectionIoAllowed;
63     }
64
65     public boolean isError() {
66         return error;
67     }
68
69     /**
70      * Compare this ErrorState with the provided ErrorState and return the most
71      * severe.
72      *
73      * @param input The error state to compare to this one
74      *
75      * @return The most severe error state from the the provided error state and
76      *         this one
77      */

78     public ErrorState getMostSevere(ErrorState input) {
79         if (input.severity > this.severity) {
80             return input;
81         } else {
82             return this;
83         }
84     }
85
86     public boolean isIoAllowed() {
87         return ioAllowed;
88     }
89
90     public boolean isConnectionIoAllowed() {
91         return connectionIoAllowed;
92     }
93 }
94