annotate src/org/eclipse/jetty/server/Server.java @ 872:1c0b6841cd32

remove SocketEndPoint
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 03 Oct 2016 19:55:41 -0600
parents 4f5547d29192
children b9aa175d9a29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.net.InetSocketAddress;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.util.Enumeration;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
24 import java.util.concurrent.LinkedBlockingQueue;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
25 import java.util.concurrent.ThreadPoolExecutor;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
26 import java.util.concurrent.TimeUnit;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.http.HttpGenerator;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.http.HttpURI;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import org.eclipse.jetty.server.handler.HandlerWrapper;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import org.eclipse.jetty.server.nio.SelectChannelConnector;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.util.Attributes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import org.eclipse.jetty.util.AttributesMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import org.eclipse.jetty.util.LazyList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import org.eclipse.jetty.util.MultiException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import org.eclipse.jetty.util.TypeUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.util.URIUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.util.component.Destroyable;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.util.component.LifeCycle;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 812
diff changeset
44 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 812
diff changeset
45 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import org.eclipse.jetty.util.thread.ShutdownThread;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 /** Jetty HTTP Servlet Server.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 * This class is the main class for the Jetty HTTP Servlet server.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 * It aggregates Connectors (HTTP request receivers) and request Handlers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 * The server is itself a handler and a ThreadPool. Connectors use the ThreadPool methods
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 * to run jobs that will eventually call the handle method.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 * @org.apache.xbean.XBean description="Creates an embedded Jetty web server"
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 public class Server extends HandlerWrapper implements Attributes
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 812
diff changeset
59 private static final Logger LOG = LoggerFactory.getLogger(Server.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
61 private static final String __version = "8";
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 private final AttributesMap _attributes = new AttributesMap();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
64 private final ThreadPoolExecutor _threadPool;
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 private Connector[] _connectors;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 private boolean _sendServerVersion = true; //send Server: header
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 private boolean _sendDateHeader = false; //send Date: header
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 private int _graceful=0;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 private boolean _stopAtShutdown;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 private boolean _dumpAfterStart=false;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 private boolean _dumpBeforeStop=false;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 private boolean _uncheckedPrintWriter=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 /** Convenience constructor
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 * Creates server and a {@link SelectChannelConnector} at the passed port.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 public Server(int port)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 setServer(this);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 Connector connector=new SelectChannelConnector();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 connector.setPort(port);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 setConnectors(new Connector[]{connector});
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
87 _threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 public static String getVersion()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 return __version;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 public boolean getStopAtShutdown()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 return _stopAtShutdown;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 public void setStopAtShutdown(boolean stop)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 //if we now want to stop
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 if (stop)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 //and we weren't stopping before
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 if (!_stopAtShutdown)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 //only register to stop if we're already started (otherwise we'll do it in doStart())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 if (isStarted())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 ShutdownThread.register(this);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 else
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 ShutdownThread.deregister(this);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 _stopAtShutdown=stop;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 * @return Returns the connectors.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 public Connector[] getConnectors()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 return _connectors;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 public void addConnector(Connector connector)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 setConnectors((Connector[])LazyList.addToArray(getConnectors(), connector, Connector.class));
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 * Conveniance method which calls {@link #getConnectors()} and {@link #setConnectors(Connector[])} to
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 * remove a connector.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 * @param connector The connector to remove.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 public void removeConnector(Connector connector) {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 setConnectors((Connector[])LazyList.removeFromArray (getConnectors(), connector));
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149 /** Set the connectors for this server.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 * Each connector has this server set as it's ThreadPool and its Handler.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 * @param connectors The connectors to set.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 public void setConnectors(Connector[] connectors)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 if (connectors!=null)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 for (int i=0;i<connectors.length;i++)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 connectors[i].setServer(this);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 _connectors = connectors;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 * @return Returns the threadPool.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 */
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
168 public ThreadPoolExecutor getThreadPool()
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 return _threadPool;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 * @return true if {@link #dumpStdErr()} is called after starting
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 public boolean isDumpAfterStart()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 return _dumpAfterStart;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 * @param dumpAfterStart true if {@link #dumpStdErr()} is called after starting
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 public void setDumpAfterStart(boolean dumpAfterStart)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 _dumpAfterStart = dumpAfterStart;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 * @return true if {@link #dumpStdErr()} is called before stopping
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 public boolean isDumpBeforeStop()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 return _dumpBeforeStop;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 * @param dumpBeforeStop true if {@link #dumpStdErr()} is called before stopping
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 public void setDumpBeforeStop(boolean dumpBeforeStop)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 _dumpBeforeStop = dumpBeforeStop;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 @Override
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 protected void doStart() throws Exception
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
210 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 if (getStopAtShutdown())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 ShutdownThread.register(this);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
216 ShutdownMonitor.getInstance().start(); // initialize
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 LOG.info("jetty-"+__version);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 HttpGenerator.setServerVersion(__version);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 MultiException mex=new MultiException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
222
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 try
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225 super.doStart();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
226 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 catch(Throwable e)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 mex.add(e);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232 if (_connectors!=null && mex.size()==0)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 for (int i=0;i<_connectors.length;i++)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 try{_connectors[i].start();}
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 catch(Throwable e)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 mex.add(e);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
243
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 if (isDumpAfterStart())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 dumpStdErr();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 mex.ifExceptionThrow();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
249
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 @Override
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 protected void doStop() throws Exception
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 if (isDumpBeforeStop())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 dumpStdErr();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
257 MultiException mex=new MultiException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
259 if (_graceful>0)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 if (_connectors!=null)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
262 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 for (int i=_connectors.length;i-->0;)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 LOG.info("Graceful shutdown {}",_connectors[i]);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 try{_connectors[i].close();}catch(Throwable e){mex.add(e);}
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
268 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
269
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 Handler[] contexts = getChildHandlersByClass(Graceful.class);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 for (int c=0;c<contexts.length;c++)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 Graceful context=(Graceful)contexts[c];
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 LOG.info("Graceful shutdown {}",context);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 context.setShutdown(true);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 Thread.sleep(_graceful);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
279
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 if (_connectors!=null)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 for (int i=_connectors.length;i-->0;)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 try{_connectors[i].stop();}catch(Throwable e){mex.add(e);}
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
285
867
Franklin Schmidt <fschmidt@gmail.com>
parents: 865
diff changeset
286 _threadPool.shutdownNow();
Franklin Schmidt <fschmidt@gmail.com>
parents: 865
diff changeset
287
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 try {super.doStop(); } catch(Throwable e) { mex.add(e);}
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
289
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 mex.ifExceptionThrow();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
291
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 if (getStopAtShutdown())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 ShutdownThread.deregister(this);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
294 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
295
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 /* Handle a request from a connection.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 * Called to handle a request on the connection when either the header has been received,
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 * or after the entire request has been received (for short requests of known length), or
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 * on the dispatch of an async request.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 public void handle(AbstractHttpConnection connection) throws IOException, ServletException
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 final String target=connection.getRequest().getPathInfo();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 final Request request=connection.getRequest();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 final Response response=connection.getResponse();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
307
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
308 if (LOG.isDebugEnabled())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
310 LOG.debug("REQUEST "+target+" on "+connection);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
311 handle(target, request, request, response);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()+" handled="+request.isHandled());
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
313 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
314 else
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 handle(target, request, request, response);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
317
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 /* Handle a request from a connection.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
320 * Called to handle a request on the connection when either the header has been received,
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 * or after the entire request has been received (for short requests of known length), or
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322 * on the dispatch of an async request.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
324 public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
325 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
326 final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
327 final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
328
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
329 final Request baseRequest=connection.getRequest();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 final String path=state.getPath();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
331
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
332 if (path!=null)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 // this is a dispatch with a path
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 final String contextPath=state.getServletContext().getContextPath();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path));
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
337 baseRequest.setUri(uri);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
338 baseRequest.setRequestURI(null);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
339 baseRequest.setPathInfo(baseRequest.getRequestURI());
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
340 if (uri.getQuery()!=null)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
342 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
344 final String target=baseRequest.getPathInfo();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 final HttpServletRequest request=(HttpServletRequest)async.getRequest();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 final HttpServletResponse response=(HttpServletResponse)async.getResponse();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348 if (LOG.isDebugEnabled())
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
349 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
350 LOG.debug("REQUEST "+target+" on "+connection);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
351 handle(target, baseRequest, request, response);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
352 LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
353 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
354 else
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 handle(target, baseRequest, request, response);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
358
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
361 public void join() throws InterruptedException
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 {
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
363 // getThreadPool().join();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
364 _threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
366
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 /* ------------------------------------------------------------ */
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
368
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 public void setSendServerVersion (boolean sendServerVersion)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
372 _sendServerVersion = sendServerVersion;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
373 }
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
374
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
375 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 public boolean getSendServerVersion()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
378 return _sendServerVersion;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
381 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 * @param sendDateHeader
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
384 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
385 public void setSendDateHeader(boolean sendDateHeader)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
387 _sendDateHeader = sendDateHeader;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
388 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
389
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
390 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
391 public boolean getSendDateHeader()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
392 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
393 return _sendDateHeader;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
394 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
395
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
396 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
397 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
398 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 @Deprecated
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
400 public int getMaxCookieVersion()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
402 return 1;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
403 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
404
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
405 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
407 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
408 @Deprecated
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
409 public void setMaxCookieVersion(int maxCookieVersion)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
410 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
411 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
412
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
413 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
414 /*
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
415 * @see org.eclipse.util.AttributesMap#clearAttributes()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
416 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
417 public void clearAttributes()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
418 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
419 _attributes.clearAttributes();
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
420 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
421
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
422 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
423 /*
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
424 * @see org.eclipse.util.AttributesMap#getAttribute(java.lang.String)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
425 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
426 public Object getAttribute(String name)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
427 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
428 return _attributes.getAttribute(name);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
429 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
430
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
431 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
432 /*
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
433 * @see org.eclipse.util.AttributesMap#getAttributeNames()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
434 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
435 public Enumeration getAttributeNames()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
436 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
437 return AttributesMap.getAttributeNamesCopy(_attributes);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
438 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
439
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
440 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
441 /*
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
442 * @see org.eclipse.util.AttributesMap#removeAttribute(java.lang.String)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
443 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
444 public void removeAttribute(String name)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
445 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
446 _attributes.removeAttribute(name);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
447 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
448
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
449 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
450 /*
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
451 * @see org.eclipse.util.AttributesMap#setAttribute(java.lang.String, java.lang.Object)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
452 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
453 public void setAttribute(String name, Object attribute)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
454 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
455 _attributes.setAttribute(name, attribute);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
456 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
457
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
458 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
459 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
460 * @return the graceful
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
461 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
462 public int getGracefulShutdown()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
463 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
464 return _graceful;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
465 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
466
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
467 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
468 /**
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
469 * Set graceful shutdown timeout. If set, the internal <code>doStop()</code> method will not immediately stop the
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
470 * server. Instead, all {@link Connector}s will be closed so that new connections will not be accepted
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
471 * and all handlers that implement {@link Graceful} will be put into the shutdown mode so that no new requests
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
472 * will be accepted, but existing requests can complete. The server will then wait the configured timeout
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
473 * before stopping.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
474 * @param timeoutMS the milliseconds to wait for existing request to complete before stopping the server.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
475 *
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
476 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
477 public void setGracefulShutdown(int timeoutMS)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
478 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
479 _graceful=timeoutMS;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
480 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
481
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
482 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
483 @Override
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
484 public String toString()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
485 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
486 return this.getClass().getName()+"@"+Integer.toHexString(hashCode());
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
487 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
488
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
489 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
490 @Override
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
491 public void dump(Appendable out,String indent) throws IOException
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
492 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
493 dumpThis(out);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
494 dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),TypeUtil.asList(_connectors));
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
495 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
496
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
497
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
498 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
499 public boolean isUncheckedPrintWriter()
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
500 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
501 return _uncheckedPrintWriter;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
502 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
504 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
505 public void setUncheckedPrintWriter(boolean unchecked)
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
506 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
507 _uncheckedPrintWriter=unchecked;
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
508 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
509
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
510
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
511 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
512 /* A handler that can be gracefully shutdown.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
513 * Called by doStop if a {@link #setGracefulShutdown} period is set.
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
514 * TODO move this somewhere better
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
515 */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
516 public interface Graceful extends Handler
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
517 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
518 public void setShutdown(boolean shutdown);
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
519 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
520
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
521
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
522 public final boolean isLowOnThreads()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
523 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
524 ThreadPoolExecutor tpe = getThreadPool();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
525 // getActiveCount() locks the thread pool, so execute it last
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
526 return tpe.getPoolSize() == tpe.getMaximumPoolSize() &&
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
527 tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
528 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
529
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
530
812
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
531 /* ------------------------------------------------------------ */
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
532 public static void main(String...args) throws Exception
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
533 {
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
534 System.err.println(getVersion());
700317ba03ad remove SessionIdManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
535 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
536 }