annotate src/org/eclipse/jetty/server/handler/HandlerCollection.java @ 1042:a62193321d6a

remove Buffer.reset()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 01:03:25 -0600
parents 32d4b569567c
children
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.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import org.eclipse.jetty.server.Handler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.server.Server;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.util.LazyList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.util.MultiException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32
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 /** A collection of handlers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 * The default implementations calls all handlers in list order,
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 * regardless of the response status or exceptions. Derived implementation
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 * 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
39 * handlers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * @org.apache.xbean.XBean
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 public class HandlerCollection extends AbstractHandlerContainer
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 {
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 private final boolean _mutableWhenRunning;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47 private volatile Handler[] _handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 private boolean _parallelStart=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 public HandlerCollection()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 _mutableWhenRunning=false;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 }
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 public HandlerCollection(boolean mutableWhenRunning)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 _mutableWhenRunning=mutableWhenRunning;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 /* ------------------------------------------------------------ */
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 * @return Returns the handlers.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 public Handler[] getHandlers()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 return _handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 }
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 * @param handlers The handlers to set.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 public void setHandlers(Handler[] handlers)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 if (!_mutableWhenRunning && isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 throw new IllegalStateException(STARTED);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 Handler [] old_handlers = _handlers==null?null:_handlers.clone();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 _handlers = handlers;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 Server server = getServer();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 MultiException mex = new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 for (int i=0;handlers!=null && i<handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 if (handlers[i].getServer()!=server)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 handlers[i].setServer(server);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 // stop old handlers
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 for (int i=0;old_handlers!=null && i<old_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 if (old_handlers[i]!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 try
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 if (old_handlers[i].isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 old_handlers[i].stop();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 catch (Throwable e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 }
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 mex.ifExceptionThrowRuntime();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113
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 /** Get the parrallelStart.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 * @return true if the contained handlers are started in parallel.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 public boolean isParallelStart()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 return _parallelStart;
22a4e93ed20e remove Container
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
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
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 /** Set the parallelStart.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 * @param parallelStart If true, contained handlers are started in parallel.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 public void setParallelStart(boolean parallelStart)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 this._parallelStart = parallelStart;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 875
diff changeset
134 @Override
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 875
diff changeset
135 public void handle(String target, Request request, HttpServletResponse response)
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 throws IOException, ServletException
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 if (_handlers!=null && isStarted())
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 MultiException mex=null;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 try
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 {
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 875
diff changeset
146 _handlers[i].handle(target, request, response);
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 catch(IOException e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 throw e;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 catch(RuntimeException e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 throw e;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 catch(Exception e)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 if (mex==null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 }
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 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 if (mex.size()==1)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 throw new ServletException(mex.getThrowable(0));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 else
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 throw new ServletException(mex);
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
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173
848
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 * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStart()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 protected void doStart() throws Exception
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 final MultiException mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 if (_handlers!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 if (_parallelStart)
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 CountDownLatch latch = new CountDownLatch(_handlers.length);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 final ClassLoader loader = Thread.currentThread().getContextClassLoader();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 final int h=i;
875
b9aa175d9a29 remove Server.getThreadPool()
Franklin Schmidt <fschmidt@gmail.com>
parents: 865
diff changeset
191 getServer().threadPool.execute(
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 new Runnable()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 public void run()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
196 ClassLoader orig = Thread.currentThread().getContextClassLoader();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 try
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 Thread.currentThread().setContextClassLoader(loader);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 _handlers[h].start();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 catch(Throwable e)
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 mex.add(e);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 finally
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 Thread.currentThread().setContextClassLoader(orig);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 latch.countDown();
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 }
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 );
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215 latch.await();
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 else
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 for (int i=0;i<_handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 try{_handlers[i].start();}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 catch(Throwable e){mex.add(e);}
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 }
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 super.doStart();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 mex.ifExceptionThrow();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
848
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 /*
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232 * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStop()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 protected void doStop() throws Exception
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 MultiException mex=new MultiException();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 try { super.doStop(); } catch(Throwable e){mex.add(e);}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 if (_handlers!=null)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 for (int i=_handlers.length;i-->0;)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 try{_handlers[i].stop();}catch(Throwable e){mex.add(e);}
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 }
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 mex.ifExceptionThrow();
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
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 public void setServer(Server server)
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 if (isStarted())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 throw new IllegalStateException(STARTED);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 Server old_server=getServer();
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 super.setServer(server);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258 Handler[] h=getHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
259 for (int i=0;h!=null && i<h.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260 h[i].setServer(server);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
262 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 /* Add a handler.
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 * 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
267 * @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
268 */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 public void addHandler(Handler handler)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 setHandlers((Handler[])LazyList.addToArray(getHandlers(), handler, Handler.class));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 }
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 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 public void removeHandler(Handler handler)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 Handler[] handlers = getHandlers();
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 if (handlers!=null && handlers.length>0 )
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 setHandlers((Handler[])LazyList.removeFromArray(handlers, handler));
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
848
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 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
285 protected Object expandChildren(Object list, Class byClass)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
286 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 Handler[] handlers = getHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 for (int i=0;handlers!=null && i<handlers.length;i++)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 list=expandHandler(handlers[i], list, byClass);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 return list;
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
848
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 /* ------------------------------------------------------------ */
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
294 @Override
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 public void destroy()
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 {
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 if (!isStopped())
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 throw new IllegalStateException("!STOPPED");
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 Handler[] children=getChildHandlers();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 setHandlers(null);
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 for (Handler child: children)
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 child.destroy();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 super.destroy();
22a4e93ed20e remove Container
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
305 }