comparison src/org/eclipse/jetty/server/Server.java @ 812:700317ba03ad

remove SessionIdManager
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Sep 2016 21:44:37 -0600
parents 3428c60d7cfc
children 8e9db0bbf4f9
comparison
equal deleted inserted replaced
811:1bedcd0ec275 812:700317ba03ad
55 * 55 *
56 * @org.apache.xbean.XBean description="Creates an embedded Jetty web server" 56 * @org.apache.xbean.XBean description="Creates an embedded Jetty web server"
57 */ 57 */
58 public class Server extends HandlerWrapper implements Attributes 58 public class Server extends HandlerWrapper implements Attributes
59 { 59 {
60 private static final Logger LOG = Log.getLogger(Server.class); 60 private static final Logger LOG = Log.getLogger(Server.class);
61 61
62 private static final String __version; 62 private static final String __version;
63 static 63 static
64 { 64 {
65 if (Server.class.getPackage()!=null && 65 if (Server.class.getPackage()!=null &&
66 "Eclipse.org - Jetty".equals(Server.class.getPackage().getImplementationVendor()) && 66 "Eclipse.org - Jetty".equals(Server.class.getPackage().getImplementationVendor()) &&
67 Server.class.getPackage().getImplementationVersion()!=null) 67 Server.class.getPackage().getImplementationVersion()!=null)
68 __version=Server.class.getPackage().getImplementationVersion(); 68 __version=Server.class.getPackage().getImplementationVersion();
69 else 69 else
70 __version=System.getProperty("jetty.version","8.y.z-SNAPSHOT"); 70 __version=System.getProperty("jetty.version","8.y.z-SNAPSHOT");
71 } 71 }
72 72
73 private final Container _container=new Container(); 73 private final Container _container=new Container();
74 private final AttributesMap _attributes = new AttributesMap(); 74 private final AttributesMap _attributes = new AttributesMap();
75 private ThreadPool _threadPool; 75 private ThreadPool _threadPool;
76 private Connector[] _connectors; 76 private Connector[] _connectors;
77 private SessionIdManager _sessionIdManager; 77 private boolean _sendServerVersion = true; //send Server: header
78 private boolean _sendServerVersion = true; //send Server: header 78 private boolean _sendDateHeader = false; //send Date: header
79 private boolean _sendDateHeader = false; //send Date: header 79 private int _graceful=0;
80 private int _graceful=0; 80 private boolean _stopAtShutdown;
81 private boolean _stopAtShutdown; 81 private boolean _dumpAfterStart=false;
82 private boolean _dumpAfterStart=false; 82 private boolean _dumpBeforeStop=false;
83 private boolean _dumpBeforeStop=false; 83 private boolean _uncheckedPrintWriter=false;
84 private boolean _uncheckedPrintWriter=false; 84
85 85
86 86 /* ------------------------------------------------------------ */
87 /* ------------------------------------------------------------ */ 87 public Server()
88 public Server() 88 {
89 { 89 setServer(this);
90 setServer(this); 90 }
91 } 91
92 92 /* ------------------------------------------------------------ */
93 /* ------------------------------------------------------------ */ 93 /** Convenience constructor
94 /** Convenience constructor 94 * Creates server and a {@link SelectChannelConnector} at the passed port.
95 * Creates server and a {@link SelectChannelConnector} at the passed port. 95 */
96 */ 96 public Server(int port)
97 public Server(int port) 97 {
98 { 98 setServer(this);
99 setServer(this); 99
100 100 Connector connector=new SelectChannelConnector();
101 Connector connector=new SelectChannelConnector(); 101 connector.setPort(port);
102 connector.setPort(port); 102 setConnectors(new Connector[]{connector});
103 setConnectors(new Connector[]{connector}); 103 }
104 } 104
105 105 /* ------------------------------------------------------------ */
106 /* ------------------------------------------------------------ */ 106 /** Convenience constructor
107 /** Convenience constructor 107 * Creates server and a {@link SelectChannelConnector} at the passed address.
108 * Creates server and a {@link SelectChannelConnector} at the passed address. 108 */
109 */ 109 public Server(InetSocketAddress addr)
110 public Server(InetSocketAddress addr) 110 {
111 { 111 setServer(this);
112 setServer(this); 112
113 113 Connector connector=new SelectChannelConnector();
114 Connector connector=new SelectChannelConnector(); 114 connector.setHost(addr.getHostName());
115 connector.setHost(addr.getHostName()); 115 connector.setPort(addr.getPort());
116 connector.setPort(addr.getPort()); 116 setConnectors(new Connector[]{connector});
117 setConnectors(new Connector[]{connector}); 117 }
118 } 118
119 119
120 120 /* ------------------------------------------------------------ */
121 /* ------------------------------------------------------------ */ 121 public static String getVersion()
122 public static String getVersion() 122 {
123 { 123 return __version;
124 return __version; 124 }
125 } 125
126 126 /* ------------------------------------------------------------ */
127 /* ------------------------------------------------------------ */ 127 /**
128 /** 128 * @return Returns the container.
129 * @return Returns the container. 129 */
130 */ 130 public Container getContainer()
131 public Container getContainer() 131 {
132 { 132 return _container;
133 return _container; 133 }
134 } 134
135 135 /* ------------------------------------------------------------ */
136 /* ------------------------------------------------------------ */ 136 public boolean getStopAtShutdown()
137 public boolean getStopAtShutdown() 137 {
138 { 138 return _stopAtShutdown;
139 return _stopAtShutdown; 139 }
140 } 140
141 141 /* ------------------------------------------------------------ */
142 /* ------------------------------------------------------------ */ 142 public void setStopAtShutdown(boolean stop)
143 public void setStopAtShutdown(boolean stop) 143 {
144 { 144 //if we now want to stop
145 //if we now want to stop 145 if (stop)
146 if (stop) 146 {
147 { 147 //and we weren't stopping before
148 //and we weren't stopping before 148 if (!_stopAtShutdown)
149 if (!_stopAtShutdown) 149 {
150 { 150 //only register to stop if we're already started (otherwise we'll do it in doStart())
151 //only register to stop if we're already started (otherwise we'll do it in doStart()) 151 if (isStarted())
152 if (isStarted()) 152 ShutdownThread.register(this);
153 ShutdownThread.register(this); 153 }
154 } 154 }
155 } 155 else
156 else 156 ShutdownThread.deregister(this);
157 ShutdownThread.deregister(this); 157
158 158 _stopAtShutdown=stop;
159 _stopAtShutdown=stop; 159 }
160 } 160
161 161 /* ------------------------------------------------------------ */
162 /* ------------------------------------------------------------ */ 162 /**
163 /** 163 * @return Returns the connectors.
164 * @return Returns the connectors. 164 */
165 */ 165 public Connector[] getConnectors()
166 public Connector[] getConnectors() 166 {
167 { 167 return _connectors;
168 return _connectors; 168 }
169 } 169
170 170 /* ------------------------------------------------------------ */
171 /* ------------------------------------------------------------ */ 171 public void addConnector(Connector connector)
172 public void addConnector(Connector connector) 172 {
173 { 173 setConnectors((Connector[])LazyList.addToArray(getConnectors(), connector, Connector.class));
174 setConnectors((Connector[])LazyList.addToArray(getConnectors(), connector, Connector.class)); 174 }
175 } 175
176 176 /* ------------------------------------------------------------ */
177 /* ------------------------------------------------------------ */ 177 /**
178 /** 178 * Conveniance method which calls {@link #getConnectors()} and {@link #setConnectors(Connector[])} to
179 * Conveniance method which calls {@link #getConnectors()} and {@link #setConnectors(Connector[])} to 179 * remove a connector.
180 * remove a connector. 180 * @param connector The connector to remove.
181 * @param connector The connector to remove. 181 */
182 */ 182 public void removeConnector(Connector connector) {
183 public void removeConnector(Connector connector) { 183 setConnectors((Connector[])LazyList.removeFromArray (getConnectors(), connector));
184 setConnectors((Connector[])LazyList.removeFromArray (getConnectors(), connector)); 184 }
185 } 185
186 186 /* ------------------------------------------------------------ */
187 /* ------------------------------------------------------------ */ 187 /** Set the connectors for this server.
188 /** Set the connectors for this server. 188 * Each connector has this server set as it's ThreadPool and its Handler.
189 * Each connector has this server set as it's ThreadPool and its Handler. 189 * @param connectors The connectors to set.
190 * @param connectors The connectors to set. 190 */
191 */ 191 public void setConnectors(Connector[] connectors)
192 public void setConnectors(Connector[] connectors) 192 {
193 { 193 if (connectors!=null)
194 if (connectors!=null) 194 {
195 { 195 for (int i=0;i<connectors.length;i++)
196 for (int i=0;i<connectors.length;i++) 196 connectors[i].setServer(this);
197 connectors[i].setServer(this); 197 }
198 } 198
199 199 _container.update(this, _connectors, connectors, "connector");
200 _container.update(this, _connectors, connectors, "connector"); 200 _connectors = connectors;
201 _connectors = connectors; 201 }
202 } 202
203 203 /* ------------------------------------------------------------ */
204 /* ------------------------------------------------------------ */ 204 /**
205 /** 205 * @return Returns the threadPool.
206 * @return Returns the threadPool. 206 */
207 */ 207 public ThreadPool getThreadPool()
208 public ThreadPool getThreadPool() 208 {
209 { 209 return _threadPool;
210 return _threadPool; 210 }
211 } 211
212 212 /* ------------------------------------------------------------ */
213 /* ------------------------------------------------------------ */ 213 /**
214 /** 214 * @param threadPool The threadPool to set.
215 * @param threadPool The threadPool to set. 215 */
216 */ 216 public void setThreadPool(ThreadPool threadPool)
217 public void setThreadPool(ThreadPool threadPool) 217 {
218 { 218 if (_threadPool!=null)
219 if (_threadPool!=null) 219 removeBean(_threadPool);
220 removeBean(_threadPool); 220 _container.update(this, _threadPool, threadPool, "threadpool",false);
221 _container.update(this, _threadPool, threadPool, "threadpool",false); 221 _threadPool = threadPool;
222 _threadPool = threadPool; 222 if (_threadPool!=null)
223 if (_threadPool!=null) 223 addBean(_threadPool);
224 addBean(_threadPool); 224 }
225 } 225
226 226 /**
227 /** 227 * @return true if {@link #dumpStdErr()} is called after starting
228 * @return true if {@link #dumpStdErr()} is called after starting 228 */
229 */ 229 public boolean isDumpAfterStart()
230 public boolean isDumpAfterStart() 230 {
231 { 231 return _dumpAfterStart;
232 return _dumpAfterStart; 232 }
233 } 233
234 234 /**
235 /** 235 * @param dumpAfterStart true if {@link #dumpStdErr()} is called after starting
236 * @param dumpAfterStart true if {@link #dumpStdErr()} is called after starting 236 */
237 */ 237 public void setDumpAfterStart(boolean dumpAfterStart)
238 public void setDumpAfterStart(boolean dumpAfterStart) 238 {
239 { 239 _dumpAfterStart = dumpAfterStart;
240 _dumpAfterStart = dumpAfterStart; 240 }
241 } 241
242 242 /**
243 /** 243 * @return true if {@link #dumpStdErr()} is called before stopping
244 * @return true if {@link #dumpStdErr()} is called before stopping 244 */
245 */ 245 public boolean isDumpBeforeStop()
246 public boolean isDumpBeforeStop() 246 {
247 { 247 return _dumpBeforeStop;
248 return _dumpBeforeStop; 248 }
249 } 249
250 250 /**
251 /** 251 * @param dumpBeforeStop true if {@link #dumpStdErr()} is called before stopping
252 * @param dumpBeforeStop true if {@link #dumpStdErr()} is called before stopping 252 */
253 */ 253 public void setDumpBeforeStop(boolean dumpBeforeStop)
254 public void setDumpBeforeStop(boolean dumpBeforeStop) 254 {
255 { 255 _dumpBeforeStop = dumpBeforeStop;
256 _dumpBeforeStop = dumpBeforeStop; 256 }
257 } 257
258 258
259 259
260 260 /* ------------------------------------------------------------ */
261 /* ------------------------------------------------------------ */ 261 @Override
262 @Override 262 protected void doStart() throws Exception
263 protected void doStart() throws Exception 263 {
264 { 264 if (getStopAtShutdown())
265 if (getStopAtShutdown()) 265 {
266 { 266 ShutdownThread.register(this);
267 ShutdownThread.register(this); 267 }
268 } 268
269 269 ShutdownMonitor.getInstance().start(); // initialize
270 ShutdownMonitor.getInstance().start(); // initialize 270
271 271 LOG.info("jetty-"+__version);
272 LOG.info("jetty-"+__version); 272 HttpGenerator.setServerVersion(__version);
273 HttpGenerator.setServerVersion(__version); 273
274 274 MultiException mex=new MultiException();
275 MultiException mex=new MultiException(); 275
276 276 if (_threadPool==null)
277 if (_threadPool==null) 277 setThreadPool(new QueuedThreadPool());
278 setThreadPool(new QueuedThreadPool()); 278
279 279 try
280 try 280 {
281 { 281 super.doStart();
282 super.doStart(); 282 }
283 } 283 catch(Throwable e)
284 catch(Throwable e) 284 {
285 { 285 mex.add(e);
286 mex.add(e); 286 }
287 } 287
288 288 if (_connectors!=null && mex.size()==0)
289 if (_connectors!=null && mex.size()==0) 289 {
290 { 290 for (int i=0;i<_connectors.length;i++)
291 for (int i=0;i<_connectors.length;i++) 291 {
292 { 292 try{_connectors[i].start();}
293 try{_connectors[i].start();} 293 catch(Throwable e)
294 catch(Throwable e) 294 {
295 { 295 mex.add(e);
296 mex.add(e); 296 }
297 } 297 }
298 } 298 }
299 } 299
300 300 if (isDumpAfterStart())
301 if (isDumpAfterStart()) 301 dumpStdErr();
302 dumpStdErr(); 302
303 303 mex.ifExceptionThrow();
304 mex.ifExceptionThrow(); 304 }
305 } 305
306 306 /* ------------------------------------------------------------ */
307 /* ------------------------------------------------------------ */ 307 @Override
308 @Override 308 protected void doStop() throws Exception
309 protected void doStop() throws Exception 309 {
310 { 310 if (isDumpBeforeStop())
311 if (isDumpBeforeStop()) 311 dumpStdErr();
312 dumpStdErr(); 312
313 313 MultiException mex=new MultiException();
314 MultiException mex=new MultiException(); 314
315 315 if (_graceful>0)
316 if (_graceful>0) 316 {
317 { 317 if (_connectors!=null)
318 if (_connectors!=null) 318 {
319 { 319 for (int i=_connectors.length;i-->0;)
320 for (int i=_connectors.length;i-->0;) 320 {
321 { 321 LOG.info("Graceful shutdown {}",_connectors[i]);
322 LOG.info("Graceful shutdown {}",_connectors[i]); 322 try{_connectors[i].close();}catch(Throwable e){mex.add(e);}
323 try{_connectors[i].close();}catch(Throwable e){mex.add(e);} 323 }
324 } 324 }
325 } 325
326 326 Handler[] contexts = getChildHandlersByClass(Graceful.class);
327 Handler[] contexts = getChildHandlersByClass(Graceful.class); 327 for (int c=0;c<contexts.length;c++)
328 for (int c=0;c<contexts.length;c++) 328 {
329 { 329 Graceful context=(Graceful)contexts[c];
330 Graceful context=(Graceful)contexts[c]; 330 LOG.info("Graceful shutdown {}",context);
331 LOG.info("Graceful shutdown {}",context); 331 context.setShutdown(true);
332 context.setShutdown(true); 332 }
333 } 333 Thread.sleep(_graceful);
334 Thread.sleep(_graceful); 334 }
335 } 335
336 336 if (_connectors!=null)
337 if (_connectors!=null) 337 {
338 { 338 for (int i=_connectors.length;i-->0;)
339 for (int i=_connectors.length;i-->0;) 339 try{_connectors[i].stop();}catch(Throwable e){mex.add(e);}
340 try{_connectors[i].stop();}catch(Throwable e){mex.add(e);} 340 }
341 } 341
342 342 try {super.doStop(); } catch(Throwable e) { mex.add(e);}
343 try {super.doStop(); } catch(Throwable e) { mex.add(e);} 343
344 344 mex.ifExceptionThrow();
345 mex.ifExceptionThrow(); 345
346 346 if (getStopAtShutdown())
347 if (getStopAtShutdown()) 347 ShutdownThread.deregister(this);
348 ShutdownThread.deregister(this); 348 }
349 } 349
350 350 /* ------------------------------------------------------------ */
351 /* ------------------------------------------------------------ */ 351 /* Handle a request from a connection.
352 /* Handle a request from a connection. 352 * Called to handle a request on the connection when either the header has been received,
353 * Called to handle a request on the connection when either the header has been received, 353 * or after the entire request has been received (for short requests of known length), or
354 * or after the entire request has been received (for short requests of known length), or 354 * on the dispatch of an async request.
355 * on the dispatch of an async request. 355 */
356 */ 356 public void handle(AbstractHttpConnection connection) throws IOException, ServletException
357 public void handle(AbstractHttpConnection connection) throws IOException, ServletException 357 {
358 { 358 final String target=connection.getRequest().getPathInfo();
359 final String target=connection.getRequest().getPathInfo(); 359 final Request request=connection.getRequest();
360 final Request request=connection.getRequest(); 360 final Response response=connection.getResponse();
361 final Response response=connection.getResponse(); 361
362 362 if (LOG.isDebugEnabled())
363 if (LOG.isDebugEnabled()) 363 {
364 { 364 LOG.debug("REQUEST "+target+" on "+connection);
365 LOG.debug("REQUEST "+target+" on "+connection); 365 handle(target, request, request, response);
366 handle(target, request, request, response); 366 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()+" handled="+request.isHandled());
367 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()+" handled="+request.isHandled()); 367 }
368 } 368 else
369 else 369 handle(target, request, request, response);
370 handle(target, request, request, response); 370 }
371 } 371
372 372 /* ------------------------------------------------------------ */
373 /* ------------------------------------------------------------ */ 373 /* Handle a request from a connection.
374 /* Handle a request from a connection. 374 * Called to handle a request on the connection when either the header has been received,
375 * Called to handle a request on the connection when either the header has been received, 375 * or after the entire request has been received (for short requests of known length), or
376 * or after the entire request has been received (for short requests of known length), or 376 * on the dispatch of an async request.
377 * on the dispatch of an async request. 377 */
378 */ 378 public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException
379 public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException 379 {
380 { 380 final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
381 final AsyncContinuation async = connection.getRequest().getAsyncContinuation(); 381 final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();
382 final AsyncContinuation.AsyncEventState state = async.getAsyncEventState(); 382
383 383 final Request baseRequest=connection.getRequest();
384 final Request baseRequest=connection.getRequest(); 384 final String path=state.getPath();
385 final String path=state.getPath(); 385
386 386 if (path!=null)
387 if (path!=null) 387 {
388 { 388 // this is a dispatch with a path
389 // this is a dispatch with a path 389 final String contextPath=state.getServletContext().getContextPath();
390 final String contextPath=state.getServletContext().getContextPath(); 390 HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path));
391 HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path)); 391 baseRequest.setUri(uri);
392 baseRequest.setUri(uri); 392 baseRequest.setRequestURI(null);
393 baseRequest.setRequestURI(null); 393 baseRequest.setPathInfo(baseRequest.getRequestURI());
394 baseRequest.setPathInfo(baseRequest.getRequestURI()); 394 if (uri.getQuery()!=null)
395 if (uri.getQuery()!=null) 395 baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8
396 baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8 396 }
397 } 397
398 398 final String target=baseRequest.getPathInfo();
399 final String target=baseRequest.getPathInfo(); 399 final HttpServletRequest request=(HttpServletRequest)async.getRequest();
400 final HttpServletRequest request=(HttpServletRequest)async.getRequest(); 400 final HttpServletResponse response=(HttpServletResponse)async.getResponse();
401 final HttpServletResponse response=(HttpServletResponse)async.getResponse(); 401
402 402 if (LOG.isDebugEnabled())
403 if (LOG.isDebugEnabled()) 403 {
404 { 404 LOG.debug("REQUEST "+target+" on "+connection);
405 LOG.debug("REQUEST "+target+" on "+connection); 405 handle(target, baseRequest, request, response);
406 handle(target, baseRequest, request, response); 406 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
407 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()); 407 }
408 } 408 else
409 else 409 handle(target, baseRequest, request, response);
410 handle(target, baseRequest, request, response); 410
411 411 }
412 } 412
413 413
414 414 /* ------------------------------------------------------------ */
415 /* ------------------------------------------------------------ */ 415 public void join() throws InterruptedException
416 public void join() throws InterruptedException 416 {
417 { 417 getThreadPool().join();
418 getThreadPool().join(); 418 }
419 } 419
420 420 /* ------------------------------------------------------------ */
421 /* ------------------------------------------------------------ */ 421
422 /* ------------------------------------------------------------ */ 422 /* ------------------------------------------------------------ */
423 /** 423 public void setSendServerVersion (boolean sendServerVersion)
424 * @return Returns the sessionIdManager. 424 {
425 */ 425 _sendServerVersion = sendServerVersion;
426 public SessionIdManager getSessionIdManager() 426 }
427 { 427
428 return _sessionIdManager; 428 /* ------------------------------------------------------------ */
429 } 429 public boolean getSendServerVersion()
430 430 {
431 /* ------------------------------------------------------------ */ 431 return _sendServerVersion;
432 /* ------------------------------------------------------------ */ 432 }
433 /** 433
434 * @param sessionIdManager The sessionIdManager to set. 434 /* ------------------------------------------------------------ */
435 */ 435 /**
436 public void setSessionIdManager(SessionIdManager sessionIdManager) 436 * @param sendDateHeader
437 { 437 */
438 if (_sessionIdManager!=null) 438 public void setSendDateHeader(boolean sendDateHeader)
439 removeBean(_sessionIdManager); 439 {
440 _container.update(this, _sessionIdManager, sessionIdManager, "sessionIdManager",false); 440 _sendDateHeader = sendDateHeader;
441 _sessionIdManager = sessionIdManager; 441 }
442 if (_sessionIdManager!=null) 442
443 addBean(_sessionIdManager); 443 /* ------------------------------------------------------------ */
444 } 444 public boolean getSendDateHeader()
445 445 {
446 /* ------------------------------------------------------------ */ 446 return _sendDateHeader;
447 public void setSendServerVersion (boolean sendServerVersion) 447 }
448 { 448
449 _sendServerVersion = sendServerVersion; 449 /* ------------------------------------------------------------ */
450 } 450 /**
451 451 */
452 /* ------------------------------------------------------------ */ 452 @Deprecated
453 public boolean getSendServerVersion() 453 public int getMaxCookieVersion()
454 { 454 {
455 return _sendServerVersion; 455 return 1;
456 } 456 }
457 457
458 /* ------------------------------------------------------------ */ 458 /* ------------------------------------------------------------ */
459 /** 459 /**
460 * @param sendDateHeader 460 */
461 */ 461 @Deprecated
462 public void setSendDateHeader(boolean sendDateHeader) 462 public void setMaxCookieVersion(int maxCookieVersion)
463 { 463 {
464 _sendDateHeader = sendDateHeader; 464 }
465 } 465
466 466 /* ------------------------------------------------------------ */
467 /* ------------------------------------------------------------ */ 467 /**
468 public boolean getSendDateHeader() 468 * Add a LifeCycle object to be started/stopped
469 { 469 * along with the Server.
470 return _sendDateHeader; 470 * @deprecated Use {@link #addBean(Object)}
471 } 471 * @param c
472 472 */
473 /* ------------------------------------------------------------ */ 473 @Deprecated
474 /** 474 public void addLifeCycle (LifeCycle c)
475 */ 475 {
476 @Deprecated 476 addBean(c);
477 public int getMaxCookieVersion() 477 }
478 { 478
479 return 1; 479 /* ------------------------------------------------------------ */
480 } 480 /**
481 481 * Add an associated bean.
482 /* ------------------------------------------------------------ */ 482 * The bean will be added to the servers {@link Container}
483 /** 483 * and if it is a {@link LifeCycle} instance, it will be
484 */ 484 * started/stopped along with the Server. Any beans that are also
485 @Deprecated 485 * {@link Destroyable}, will be destroyed with the server.
486 public void setMaxCookieVersion(int maxCookieVersion) 486 * @param o the bean object to add
487 { 487 */
488 } 488 @Override
489 489 public boolean addBean(Object o)
490 /* ------------------------------------------------------------ */ 490 {
491 /** 491 if (super.addBean(o))
492 * Add a LifeCycle object to be started/stopped 492 {
493 * along with the Server. 493 _container.addBean(o);
494 * @deprecated Use {@link #addBean(Object)} 494 return true;
495 * @param c 495 }
496 */ 496 return false;
497 @Deprecated 497 }
498 public void addLifeCycle (LifeCycle c) 498
499 { 499 /**
500 addBean(c); 500 * Remove a LifeCycle object to be started/stopped
501 } 501 * along with the Server
502 502 * @deprecated Use {@link #removeBean(Object)}
503 /* ------------------------------------------------------------ */ 503 */
504 /** 504 @Deprecated
505 * Add an associated bean. 505 public void removeLifeCycle (LifeCycle c)
506 * The bean will be added to the servers {@link Container} 506 {
507 * and if it is a {@link LifeCycle} instance, it will be 507 removeBean(c);
508 * started/stopped along with the Server. Any beans that are also 508 }
509 * {@link Destroyable}, will be destroyed with the server. 509
510 * @param o the bean object to add 510 /* ------------------------------------------------------------ */
511 */ 511 /**
512 @Override 512 * Remove an associated bean.
513 public boolean addBean(Object o) 513 */
514 { 514 @Override
515 if (super.addBean(o)) 515 public boolean removeBean (Object o)
516 { 516 {
517 _container.addBean(o); 517 if (super.removeBean(o))
518 return true; 518 {
519 } 519 _container.removeBean(o);
520 return false; 520 return true;
521 } 521 }
522 522 return false;
523 /** 523 }
524 * Remove a LifeCycle object to be started/stopped 524
525 * along with the Server 525 /* ------------------------------------------------------------ */
526 * @deprecated Use {@link #removeBean(Object)} 526 /*
527 */ 527 * @see org.eclipse.util.AttributesMap#clearAttributes()
528 @Deprecated 528 */
529 public void removeLifeCycle (LifeCycle c) 529 public void clearAttributes()
530 { 530 {
531 removeBean(c); 531 _attributes.clearAttributes();
532 } 532 }
533 533
534 /* ------------------------------------------------------------ */ 534 /* ------------------------------------------------------------ */
535 /** 535 /*
536 * Remove an associated bean. 536 * @see org.eclipse.util.AttributesMap#getAttribute(java.lang.String)
537 */ 537 */
538 @Override 538 public Object getAttribute(String name)
539 public boolean removeBean (Object o) 539 {
540 { 540 return _attributes.getAttribute(name);
541 if (super.removeBean(o)) 541 }
542 { 542
543 _container.removeBean(o); 543 /* ------------------------------------------------------------ */
544 return true; 544 /*
545 } 545 * @see org.eclipse.util.AttributesMap#getAttributeNames()
546 return false; 546 */
547 } 547 public Enumeration getAttributeNames()
548 548 {
549 /* ------------------------------------------------------------ */ 549 return AttributesMap.getAttributeNamesCopy(_attributes);
550 /* 550 }
551 * @see org.eclipse.util.AttributesMap#clearAttributes() 551
552 */ 552 /* ------------------------------------------------------------ */
553 public void clearAttributes() 553 /*
554 { 554 * @see org.eclipse.util.AttributesMap#removeAttribute(java.lang.String)
555 _attributes.clearAttributes(); 555 */
556 } 556 public void removeAttribute(String name)
557 557 {
558 /* ------------------------------------------------------------ */ 558 _attributes.removeAttribute(name);
559 /* 559 }
560 * @see org.eclipse.util.AttributesMap#getAttribute(java.lang.String) 560
561 */ 561 /* ------------------------------------------------------------ */
562 public Object getAttribute(String name) 562 /*
563 { 563 * @see org.eclipse.util.AttributesMap#setAttribute(java.lang.String, java.lang.Object)
564 return _attributes.getAttribute(name); 564 */
565 } 565 public void setAttribute(String name, Object attribute)
566 566 {
567 /* ------------------------------------------------------------ */ 567 _attributes.setAttribute(name, attribute);
568 /* 568 }
569 * @see org.eclipse.util.AttributesMap#getAttributeNames() 569
570 */ 570 /* ------------------------------------------------------------ */
571 public Enumeration getAttributeNames() 571 /**
572 { 572 * @return the graceful
573 return AttributesMap.getAttributeNamesCopy(_attributes); 573 */
574 } 574 public int getGracefulShutdown()
575 575 {
576 /* ------------------------------------------------------------ */ 576 return _graceful;
577 /* 577 }
578 * @see org.eclipse.util.AttributesMap#removeAttribute(java.lang.String) 578
579 */ 579 /* ------------------------------------------------------------ */
580 public void removeAttribute(String name) 580 /**
581 { 581 * Set graceful shutdown timeout. If set, the internal <code>doStop()</code> method will not immediately stop the
582 _attributes.removeAttribute(name); 582 * server. Instead, all {@link Connector}s will be closed so that new connections will not be accepted
583 } 583 * and all handlers that implement {@link Graceful} will be put into the shutdown mode so that no new requests
584 584 * will be accepted, but existing requests can complete. The server will then wait the configured timeout
585 /* ------------------------------------------------------------ */ 585 * before stopping.
586 /* 586 * @param timeoutMS the milliseconds to wait for existing request to complete before stopping the server.
587 * @see org.eclipse.util.AttributesMap#setAttribute(java.lang.String, java.lang.Object) 587 *
588 */ 588 */
589 public void setAttribute(String name, Object attribute) 589 public void setGracefulShutdown(int timeoutMS)
590 { 590 {
591 _attributes.setAttribute(name, attribute); 591 _graceful=timeoutMS;
592 } 592 }
593 593
594 /* ------------------------------------------------------------ */ 594 /* ------------------------------------------------------------ */
595 /** 595 @Override
596 * @return the graceful 596 public String toString()
597 */ 597 {
598 public int getGracefulShutdown() 598 return this.getClass().getName()+"@"+Integer.toHexString(hashCode());
599 { 599 }
600 return _graceful; 600
601 } 601 /* ------------------------------------------------------------ */
602 602 @Override
603 /* ------------------------------------------------------------ */ 603 public void dump(Appendable out,String indent) throws IOException
604 /** 604 {
605 * Set graceful shutdown timeout. If set, the internal <code>doStop()</code> method will not immediately stop the 605 dumpThis(out);
606 * server. Instead, all {@link Connector}s will be closed so that new connections will not be accepted 606 dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),TypeUtil.asList(_connectors));
607 * and all handlers that implement {@link Graceful} will be put into the shutdown mode so that no new requests 607 }
608 * will be accepted, but existing requests can complete. The server will then wait the configured timeout 608
609 * before stopping. 609
610 * @param timeoutMS the milliseconds to wait for existing request to complete before stopping the server. 610 /* ------------------------------------------------------------ */
611 * 611 public boolean isUncheckedPrintWriter()
612 */ 612 {
613 public void setGracefulShutdown(int timeoutMS) 613 return _uncheckedPrintWriter;
614 { 614 }
615 _graceful=timeoutMS; 615
616 } 616 /* ------------------------------------------------------------ */
617 617 public void setUncheckedPrintWriter(boolean unchecked)
618 /* ------------------------------------------------------------ */ 618 {
619 @Override 619 _uncheckedPrintWriter=unchecked;
620 public String toString() 620 }
621 { 621
622 return this.getClass().getName()+"@"+Integer.toHexString(hashCode()); 622
623 } 623 /* ------------------------------------------------------------ */
624 624 /* A handler that can be gracefully shutdown.
625 /* ------------------------------------------------------------ */ 625 * Called by doStop if a {@link #setGracefulShutdown} period is set.
626 @Override 626 * TODO move this somewhere better
627 public void dump(Appendable out,String indent) throws IOException 627 */
628 { 628 public interface Graceful extends Handler
629 dumpThis(out); 629 {
630 dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),TypeUtil.asList(_connectors)); 630 public void setShutdown(boolean shutdown);
631 } 631 }
632 632
633 633 /* ------------------------------------------------------------ */
634 /* ------------------------------------------------------------ */ 634 public static void main(String...args) throws Exception
635 public boolean isUncheckedPrintWriter() 635 {
636 { 636 System.err.println(getVersion());
637 return _uncheckedPrintWriter; 637 }
638 }
639
640 /* ------------------------------------------------------------ */
641 public void setUncheckedPrintWriter(boolean unchecked)
642 {
643 _uncheckedPrintWriter=unchecked;
644 }
645
646
647 /* ------------------------------------------------------------ */
648 /* A handler that can be gracefully shutdown.
649 * Called by doStop if a {@link #setGracefulShutdown} period is set.
650 * TODO move this somewhere better
651 */
652 public interface Graceful extends Handler
653 {
654 public void setShutdown(boolean shutdown);
655 }
656
657 /* ------------------------------------------------------------ */
658 public static void main(String...args) throws Exception
659 {
660 System.err.println(getVersion());
661 }
662 } 638 }