comparison src/org/eclipse/jetty/server/handler/ContextHandler.java @ 995:0eba8f555c19

remove Server.Graceful
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 18 Oct 2016 18:38:05 -0600
parents 4e9d373bf6e9
children 7d28be82ab75
comparison
equal deleted inserted replaced
994:4e9d373bf6e9 995:0eba8f555c19
65 import org.eclipse.jetty.io.Buffer; 65 import org.eclipse.jetty.io.Buffer;
66 import org.eclipse.jetty.server.AbstractHttpConnection; 66 import org.eclipse.jetty.server.AbstractHttpConnection;
67 import org.eclipse.jetty.server.Handler; 67 import org.eclipse.jetty.server.Handler;
68 import org.eclipse.jetty.server.HandlerContainer; 68 import org.eclipse.jetty.server.HandlerContainer;
69 import org.eclipse.jetty.server.Request; 69 import org.eclipse.jetty.server.Request;
70 import org.eclipse.jetty.server.Server;
71 import org.eclipse.jetty.util.AttributesMap; 70 import org.eclipse.jetty.util.AttributesMap;
72 import org.eclipse.jetty.util.StringUtil; 71 import org.eclipse.jetty.util.StringUtil;
73 import org.eclipse.jetty.util.TypeUtil; 72 import org.eclipse.jetty.util.TypeUtil;
74 import org.eclipse.jetty.util.URIUtil; 73 import org.eclipse.jetty.util.URIUtil;
75 import org.eclipse.jetty.util.component.AggregateLifeCycle; 74 import org.eclipse.jetty.util.component.AggregateLifeCycle;
83 * ContextHandler. 82 * ContextHandler.
84 * 83 *
85 * This handler wraps a call to handle by setting the context and servlet path. 84 * This handler wraps a call to handle by setting the context and servlet path.
86 * 85 *
87 */ 86 */
88 public final class ContextHandler extends HandlerWrapper implements Server.Graceful 87 public final class ContextHandler extends HandlerWrapper
89 { 88 {
90 private static final Logger LOG = LoggerFactory.getLogger(ContextHandler.class); 89 private static final Logger LOG = LoggerFactory.getLogger(ContextHandler.class);
91 90
92 private String _contextPath = "/"; 91 private String _contextPath = "/";
93 private Resource _baseResource; 92 private Resource _baseResource;
94 private Logger _logger; 93 private Logger _logger;
95
96 private boolean _shutdown = false;
97 private volatile int _availability; // 0=STOPPED, 1=AVAILABLE, 2=SHUTDOWN, 3=UNAVAILABLE
98
99 private final static int __STOPPED = 0, __AVAILABLE = 1, __SHUTDOWN = 2;
100 94
101 public ContextHandler() 95 public ContextHandler()
102 { 96 {
103 super(); 97 super();
104 } 98 }
130 { 124 {
131 return _contextPath; 125 return _contextPath;
132 } 126 }
133 127
134 /* ------------------------------------------------------------ */ 128 /* ------------------------------------------------------------ */
135 /**
136 * Set shutdown status. This field allows for graceful shutdown of a context. A started context may be put into non accepting state so that existing
137 * requests can complete, but no new requests are accepted.
138 *
139 * @param shutdown
140 * true if this context is (not?) accepting new requests
141 */
142 public void setShutdown(boolean shutdown)
143 {
144 synchronized (this)
145 {
146 _shutdown = shutdown;
147 _availability = isRunning()?(_shutdown?__SHUTDOWN:__AVAILABLE):__STOPPED;
148 }
149 }
150
151 /* ------------------------------------------------------------ */
152 /* 129 /*
153 * @see org.eclipse.thread.AbstractLifeCycle#doStart() 130 * @see org.eclipse.thread.AbstractLifeCycle#doStart()
154 */ 131 */
155 @Override 132 @Override
156 protected void doStart() throws Exception 133 protected void doStart() throws Exception
157 { 134 {
158 _availability = __STOPPED;
159
160 if (_contextPath == null) 135 if (_contextPath == null)
161 throw new IllegalStateException("Null contextPath"); 136 throw new IllegalStateException("Null contextPath");
162 137
163 _logger = LoggerFactory.getLogger(getContextPath()); 138 _logger = LoggerFactory.getLogger(getContextPath());
164 139
165 super.doStart(); 140 super.doStart();
166
167 synchronized(this)
168 {
169 _availability = _shutdown?__SHUTDOWN:__AVAILABLE;
170 }
171 } 141 }
172 142
173 /* ------------------------------------------------------------ */ 143 /* ------------------------------------------------------------ */
174 /* 144 /*
175 * @see org.eclipse.thread.AbstractLifeCycle#doStop() 145 * @see org.eclipse.thread.AbstractLifeCycle#doStop()
176 */ 146 */
177 @Override 147 @Override
178 protected void doStop() throws Exception 148 protected void doStop() throws Exception
179 { 149 {
180 _availability = __STOPPED;
181
182 super.doStop(); 150 super.doStop();
183 LOG.info("stopped {}",this); 151 LOG.info("stopped {}",this);
184 } 152 }
185 153
186 private boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response) throws IOException, ServletException 154 private boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response) throws IOException, ServletException
187 { 155 {
188 switch (_availability) 156 if (baseRequest.isHandled())
189 { 157 return false;
190 case __STOPPED:
191 case __SHUTDOWN:
192 return false;
193 default:
194 if (baseRequest.isHandled())
195 return false;
196 }
197 158
198 // Are we not the root context? 159 // Are we not the root context?
199 if (_contextPath.length() > 1) 160 if (_contextPath.length() > 1)
200 { 161 {
201 // reject requests that are not for us 162 // reject requests that are not for us