annotate src/org/eclipse/jetty/server/handler/HandlerCollection.java @ 963:4b6216fa9cec

replace SelectChannelEndPoint._state with isDispatched
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 14 Oct 2016 00:15:28 -0600
parents b9aa175d9a29
children 32d4b569567c
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.handler;
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.util.concurrent.CountDownLatch;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import javax.servlet.http.HttpServletResponse;
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 org.eclipse.jetty.server.Handler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.server.Server;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.util.LazyList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.util.MultiException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 /** A collection of handlers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 * The default implementations calls all handlers in list order,
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 * regardless of the response status or exceptions. Derived implementation
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 * may alter the order or the conditions of calling the contained
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 * handlers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 * @org.apache.xbean.XBean
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 public class HandlerCollection extends AbstractHandlerContainer
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 {
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47 private final boolean _mutableWhenRunning;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 private volatile Handler[] _handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 private boolean _parallelStart=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 public HandlerCollection()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 _mutableWhenRunning=false;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
57 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 public HandlerCollection(boolean mutableWhenRunning)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 _mutableWhenRunning=mutableWhenRunning;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 /**
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 * @return Returns the handlers.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 public Handler[] getHandlers()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 return _handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 /**
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 *
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 * @param handlers The handlers to set.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 public void setHandlers(Handler[] handlers)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 if (!_mutableWhenRunning && isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 throw new IllegalStateException(STARTED);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 Handler [] old_handlers = _handlers==null?null:_handlers.clone();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 _handlers = handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 Server server = getServer();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 MultiException mex = new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 for (int i=0;handlers!=null && i<handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 if (handlers[i].getServer()!=server)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 handlers[i].setServer(server);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 // stop old handlers
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 for (int i=0;old_handlers!=null && i<old_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 if (old_handlers[i]!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 try
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 if (old_handlers[i].isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 old_handlers[i].stop();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 catch (Throwable e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 mex.ifExceptionThrowRuntime();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 /** Get the parrallelStart.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 * @return true if the contained handlers are started in parallel.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 public boolean isParallelStart()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 return _parallelStart;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 /** Set the parallelStart.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 * @param parallelStart If true, contained handlers are started in parallel.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 public void setParallelStart(boolean parallelStart)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 this._parallelStart = parallelStart;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 /**
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 * @see Handler#handle(String, Request, HttpServletRequest, HttpServletResponse)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 throws IOException, ServletException
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 if (_handlers!=null && isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 MultiException mex=null;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149 try
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 _handlers[i].handle(target,baseRequest, request, response);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 catch(IOException e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 throw e;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 catch(RuntimeException e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 throw e;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 catch(Exception e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 if (mex==null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 if (mex!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 if (mex.size()==1)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 throw new ServletException(mex.getThrowable(0));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 else
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 throw new ServletException(mex);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
180 /*
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStart()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 protected void doStart() throws Exception
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 final MultiException mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 if (_handlers!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 if (_parallelStart)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 final CountDownLatch latch = new CountDownLatch(_handlers.length);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 final ClassLoader loader = Thread.currentThread().getContextClassLoader();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 final int h=i;
875
b9aa175d9a29 remove Server.getThreadPool()
Franklin Schmidt <fschmidt@gmail.com>
parents: 865
diff changeset
196 getServer().threadPool.execute(
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 new Runnable()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 public void run()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 ClassLoader orig = Thread.currentThread().getContextClassLoader();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 try
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 Thread.currentThread().setContextClassLoader(loader);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 _handlers[h].start();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 catch(Throwable e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
210 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 finally
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 Thread.currentThread().setContextClassLoader(orig);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 latch.countDown();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
216 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
217 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 );
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 latch.await();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 else
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
226 try{_handlers[i].start();}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 catch(Throwable e){mex.add(e);}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 super.doStart();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232 mex.ifExceptionThrow();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 /*
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStop()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 protected void doStop() throws Exception
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 MultiException mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 try { super.doStop(); } catch(Throwable e){mex.add(e);}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 if (_handlers!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 for (int i=_handlers.length;i-->0;)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 try{_handlers[i].stop();}catch(Throwable e){mex.add(e);}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 mex.ifExceptionThrow();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 public void setServer(Server server)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
256 if (isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
257 throw new IllegalStateException(STARTED);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
259 Server old_server=getServer();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 super.setServer(server);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 Handler[] h=getHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 for (int i=0;h!=null && i<h.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 h[i].setServer(server);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 /* Add a handler.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 * This implementation adds the passed handler to the end of the existing collection of handlers.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 * @see org.eclipse.jetty.server.server.HandlerContainer#addHandler(org.eclipse.jetty.server.server.Handler)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 public void addHandler(Handler handler)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 setHandlers((Handler[])LazyList.addToArray(getHandlers(), handler, Handler.class));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
279 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 public void removeHandler(Handler handler)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 Handler[] handlers = getHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 if (handlers!=null && handlers.length>0 )
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
285 setHandlers((Handler[])LazyList.removeFromArray(handlers, handler));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
286 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
287
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 protected Object expandChildren(Object list, Class byClass)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 Handler[] handlers = getHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 for (int i=0;handlers!=null && i<handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
294 list=expandHandler(handlers[i], list, byClass);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 return list;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 public void destroy()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 if (!isStopped())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 throw new IllegalStateException("!STOPPED");
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 Handler[] children=getChildHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 setHandlers(null);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 for (Handler child: children)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
307 child.destroy();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
308 super.destroy();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
310 }