Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AsyncContinuation.java @ 931:6f7e2ff51879
remove ContinuationThrowable
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 09 Oct 2016 19:24:55 -0600 |
| parents | cd080b7bcf49 |
| children | 947df3056ddb |
| 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 javax.servlet.AsyncContext; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import javax.servlet.AsyncEvent; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import javax.servlet.AsyncListener; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import javax.servlet.RequestDispatcher; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import javax.servlet.ServletException; |
|
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 java.util.ArrayList; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.util.List; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import javax.servlet.ServletContext; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import javax.servlet.ServletRequest; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import javax.servlet.ServletResponse; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import javax.servlet.http.HttpServletRequest; |
|
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 import org.eclipse.jetty.continuation.Continuation; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.continuation.ContinuationListener; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.io.AsyncEndPoint; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.io.EndPoint; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.server.handler.ContextHandler; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.server.handler.ContextHandler.Context; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 import org.eclipse.jetty.util.URIUtil; |
|
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
42 import org.slf4j.Logger; |
|
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
43 import org.slf4j.LoggerFactory; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 import org.eclipse.jetty.util.thread.Timeout; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 /* ------------------------------------------------------------ */ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 /** Implementation of Continuation and AsyncContext interfaces |
|
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 */ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 public class AsyncContinuation implements AsyncContext, Continuation |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 { |
| 865 | 52 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 |
| 865 | 54 private final static long DEFAULT_TIMEOUT=30000L; |
|
931
6f7e2ff51879
remove ContinuationThrowable
Franklin Schmidt <fschmidt@gmail.com>
parents:
930
diff
changeset
|
55 |
| 865 | 56 // STATES: |
| 57 // handling() suspend() unhandle() resume() complete() doComplete() | |
| 58 // startAsync() dispatch() | |
| 59 // IDLE DISPATCHED | |
| 60 // DISPATCHED ASYNCSTARTED UNCOMPLETED | |
| 61 // ASYNCSTARTED ASYNCWAIT REDISPATCHING COMPLETING | |
| 62 // REDISPATCHING REDISPATCHED | |
| 63 // ASYNCWAIT REDISPATCH COMPLETING | |
| 64 // REDISPATCH REDISPATCHED | |
| 65 // REDISPATCHED ASYNCSTARTED UNCOMPLETED | |
| 66 // COMPLETING UNCOMPLETED UNCOMPLETED | |
| 67 // UNCOMPLETED COMPLETED | |
| 68 // COMPLETED | |
| 69 private static final int __IDLE=0; // Idle request | |
| 70 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet | |
| 71 private static final int __UNCOMPLETED=8; // Request is completable | |
| 72 private static final int __COMPLETED=9; // Request is complete | |
| 73 | |
| 74 /* ------------------------------------------------------------ */ | |
| 75 protected AbstractHttpConnection _connection; | |
| 76 private List<AsyncListener> _asyncListeners; | |
| 77 private List<ContinuationListener> _continuationListeners; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
78 |
| 865 | 79 /* ------------------------------------------------------------ */ |
| 80 private int _state; | |
| 81 private volatile boolean _responseWrapped; | |
| 82 private long _timeoutMs=DEFAULT_TIMEOUT; | |
| 83 private AsyncEventState _event; | |
| 84 private volatile long _expireAt; | |
| 85 | |
| 86 /* ------------------------------------------------------------ */ | |
| 87 protected AsyncContinuation() | |
| 88 { | |
| 89 _state=__IDLE; | |
| 90 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 |
| 865 | 92 /* ------------------------------------------------------------ */ |
| 93 protected void setConnection(final AbstractHttpConnection connection) | |
| 94 { | |
| 95 synchronized(this) | |
| 96 { | |
| 97 _connection=connection; | |
| 98 } | |
| 99 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
100 |
| 865 | 101 /* ------------------------------------------------------------ */ |
| 102 public void addListener(AsyncListener listener) | |
| 103 { | |
| 104 synchronized(this) | |
| 105 { | |
| 106 if (_asyncListeners==null) | |
| 107 _asyncListeners=new ArrayList<AsyncListener>(); | |
| 108 _asyncListeners.add(listener); | |
| 109 } | |
| 110 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
111 |
| 865 | 112 /* ------------------------------------------------------------ */ |
| 113 public void addListener(AsyncListener listener,ServletRequest request, ServletResponse response) | |
| 114 { | |
| 115 synchronized(this) | |
| 116 { | |
| 117 // TODO handle the request/response ??? | |
| 118 if (_asyncListeners==null) | |
| 119 _asyncListeners=new ArrayList<AsyncListener>(); | |
| 120 _asyncListeners.add(listener); | |
| 121 } | |
| 122 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 |
| 865 | 124 /* ------------------------------------------------------------ */ |
| 125 public void addContinuationListener(ContinuationListener listener) | |
| 126 { | |
| 127 synchronized(this) | |
| 128 { | |
| 129 if (_continuationListeners==null) | |
| 130 _continuationListeners=new ArrayList<ContinuationListener>(); | |
| 131 _continuationListeners.add(listener); | |
| 132 } | |
| 133 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
134 |
| 865 | 135 /* ------------------------------------------------------------ */ |
| 136 public void setTimeout(long ms) | |
| 137 { | |
| 138 synchronized(this) | |
| 139 { | |
| 140 _timeoutMs=ms; | |
| 141 } | |
| 142 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
143 |
| 865 | 144 /* ------------------------------------------------------------ */ |
| 145 public long getTimeout() | |
| 146 { | |
| 147 synchronized(this) | |
| 148 { | |
| 149 return _timeoutMs; | |
| 150 } | |
| 151 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
152 |
| 865 | 153 /* ------------------------------------------------------------ */ |
| 154 public AsyncEventState getAsyncEventState() | |
| 155 { | |
| 156 synchronized(this) | |
| 157 { | |
| 158 return _event; | |
| 159 } | |
| 160 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
161 |
| 865 | 162 /* ------------------------------------------------------------ */ |
| 163 /** | |
| 164 * @see org.eclipse.jetty.continuation.Continuation#keepWrappers() | |
| 165 */ | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
166 |
| 865 | 167 /* ------------------------------------------------------------ */ |
| 168 /** | |
| 169 * @see org.eclipse.jetty.continuation.Continuation#isResponseWrapped() | |
| 170 */ | |
| 171 public boolean isResponseWrapped() | |
| 172 { | |
| 173 return _responseWrapped; | |
| 174 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 |
| 865 | 176 /* ------------------------------------------------------------ */ |
| 177 /* (non-Javadoc) | |
| 178 * @see javax.servlet.ServletRequest#isSuspended() | |
| 179 */ | |
| 180 public boolean isSuspended() | |
| 181 { | |
| 182 synchronized(this) | |
| 183 { | |
| 184 switch(_state) | |
| 185 { | |
| 186 default: | |
| 187 return false; | |
| 188 } | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 /* ------------------------------------------------------------ */ | |
| 193 public boolean isSuspending() | |
| 194 { | |
| 195 synchronized(this) | |
| 196 { | |
| 197 switch(_state) | |
| 198 { | |
| 199 default: | |
| 200 return false; | |
| 201 } | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 /* ------------------------------------------------------------ */ | |
| 206 public boolean isDispatchable() | |
| 207 { | |
| 208 synchronized(this) | |
| 209 { | |
| 210 switch(_state) | |
| 211 { | |
| 212 default: | |
| 213 return false; | |
| 214 } | |
| 215 } | |
| 216 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
217 |
| 865 | 218 /* ------------------------------------------------------------ */ |
| 219 @Override | |
| 220 public String toString() | |
| 221 { | |
| 222 synchronized (this) | |
| 223 { | |
| 224 return super.toString()+"@"+getStatusString(); | |
| 225 } | |
| 226 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
227 |
| 865 | 228 /* ------------------------------------------------------------ */ |
| 229 public String getStatusString() | |
| 230 { | |
| 231 synchronized (this) | |
| 232 { | |
| 233 return | |
| 234 ((_state==__IDLE)?"IDLE": | |
| 235 (_state==__DISPATCHED)?"DISPATCHED": | |
| 236 (_state==__UNCOMPLETED)?"UNCOMPLETED": | |
| 237 (_state==__COMPLETED)?"COMPLETE": | |
| 929 | 238 ("UNKNOWN?"+_state)); |
| 865 | 239 } |
| 240 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 |
| 929 | 242 protected synchronized void handling() |
| 865 | 243 { |
| 929 | 244 switch(_state) |
| 865 | 245 { |
| 929 | 246 case __IDLE: |
| 247 _state=__DISPATCHED; | |
| 248 if (_asyncListeners!=null) | |
| 249 _asyncListeners.clear(); | |
| 250 return; | |
| 251 | |
| 252 default: | |
| 253 throw new IllegalStateException(this.getStatusString()); | |
| 865 | 254 } |
| 255 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
256 |
| 865 | 257 /* ------------------------------------------------------------ */ |
| 258 /** | |
| 259 * Signal that the HttpConnection has finished handling the request. | |
| 260 * For blocking connectors, this call may block if the request has | |
| 261 * been suspended (startAsync called). | |
| 262 * @return true if handling is complete, false if the request should | |
| 263 * be handled again (eg because of a resume that happened before unhandle was called) | |
| 264 */ | |
| 928 | 265 protected synchronized void unhandle() |
| 865 | 266 { |
| 928 | 267 switch(_state) |
| 865 | 268 { |
| 928 | 269 case __DISPATCHED: |
| 270 _state = __UNCOMPLETED; | |
| 271 return; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
272 |
| 928 | 273 default: |
| 274 throw new IllegalStateException(this.getStatusString()); | |
| 865 | 275 } |
| 276 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 |
| 865 | 278 public void dispatch() |
| 279 { | |
| 929 | 280 throw new UnsupportedOperationException(); |
| 865 | 281 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 |
| 865 | 283 /* ------------------------------------------------------------ */ |
| 284 protected void expired() | |
| 285 { | |
| 286 } | |
| 287 | |
| 288 /* ------------------------------------------------------------ */ | |
| 289 /* (non-Javadoc) | |
| 290 * @see javax.servlet.ServletRequest#complete() | |
| 291 */ | |
| 292 public void complete() | |
| 293 { | |
| 294 // just like resume, except don't set _resumed=true; | |
| 295 boolean dispatch=false; | |
| 296 synchronized (this) | |
| 297 { | |
| 298 switch(_state) | |
| 299 { | |
| 300 case __DISPATCHED: | |
| 301 throw new IllegalStateException(this.getStatusString()); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
| 865 | 303 default: |
| 304 throw new IllegalStateException(this.getStatusString()); | |
| 305 } | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 /* ------------------------------------------------------------ */ | |
| 310 /* (non-Javadoc) | |
| 311 * @see javax.servlet.ServletRequest#complete() | |
| 312 */ | |
| 313 public void errorComplete() | |
| 314 { | |
| 315 // just like complete except can overrule a prior dispatch call; | |
| 316 synchronized (this) | |
| 317 { | |
| 318 switch(_state) | |
| 319 { | |
| 320 default: | |
| 321 throw new IllegalStateException(this.getStatusString()); | |
| 322 } | |
| 323 } | |
| 324 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
325 |
| 865 | 326 /* ------------------------------------------------------------ */ |
| 327 @Override | |
| 328 public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException | |
| 329 { | |
| 330 try | |
| 331 { | |
| 332 // TODO inject | |
| 333 return clazz.newInstance(); | |
| 334 } | |
| 335 catch(Exception e) | |
| 336 { | |
| 337 throw new ServletException(e); | |
| 338 } | |
| 339 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
341 |
| 865 | 342 /* ------------------------------------------------------------ */ |
| 343 /* (non-Javadoc) | |
| 344 * @see javax.servlet.ServletRequest#complete() | |
| 345 */ | |
| 346 protected void doComplete(Throwable ex) | |
| 347 { | |
| 348 final List<ContinuationListener> cListeners; | |
| 349 final List<AsyncListener> aListeners; | |
| 350 synchronized (this) | |
| 351 { | |
| 352 switch(_state) | |
| 353 { | |
| 354 case __UNCOMPLETED: | |
|
918
7b62446899c6
remove unused states in AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
917
diff
changeset
|
355 _state = __COMPLETED; |
| 865 | 356 cListeners=_continuationListeners; |
| 357 aListeners=_asyncListeners; | |
| 358 break; | |
| 359 | |
| 360 default: | |
| 361 cListeners=null; | |
| 362 aListeners=null; | |
| 363 throw new IllegalStateException(this.getStatusString()); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 if (aListeners!=null) | |
| 368 { | |
| 369 for (AsyncListener listener : aListeners) | |
| 370 { | |
| 371 try | |
| 372 { | |
| 373 if (ex!=null) | |
| 374 { | |
| 375 _event.getSuppliedRequest().setAttribute(RequestDispatcher.ERROR_EXCEPTION,ex); | |
| 376 _event.getSuppliedRequest().setAttribute(RequestDispatcher.ERROR_MESSAGE,ex.getMessage()); | |
| 377 listener.onError(_event); | |
| 378 } | |
| 379 else | |
| 380 listener.onComplete(_event); | |
| 381 } | |
| 382 catch(Exception e) | |
| 383 { | |
| 384 LOG.warn("",e); | |
| 385 } | |
| 386 } | |
| 387 } | |
| 388 if (cListeners!=null) | |
| 389 { | |
| 390 for (ContinuationListener listener : cListeners) | |
| 391 { | |
| 392 try | |
| 393 { | |
| 394 listener.onComplete(this); | |
| 395 } | |
| 396 catch(Exception e) | |
| 397 { | |
| 398 LOG.warn("",e); | |
| 399 } | |
| 400 } | |
| 401 } | |
| 402 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
403 |
| 865 | 404 /* ------------------------------------------------------------ */ |
| 405 protected void recycle() | |
| 406 { | |
| 407 synchronized (this) | |
| 408 { | |
| 409 switch(_state) | |
| 410 { | |
| 411 case __DISPATCHED: | |
| 412 throw new IllegalStateException(getStatusString()); | |
| 413 default: | |
| 414 _state=__IDLE; | |
| 415 } | |
| 416 _responseWrapped=false; | |
| 417 cancelTimeout(); | |
| 418 _timeoutMs=DEFAULT_TIMEOUT; | |
| 419 _continuationListeners=null; | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 /* ------------------------------------------------------------ */ | |
| 424 protected void cancelTimeout() | |
| 425 { | |
| 426 EndPoint endp=_connection.getEndPoint(); | |
| 427 if (endp.isBlocking()) | |
| 428 { | |
| 429 synchronized(this) | |
| 430 { | |
| 431 _expireAt=0; | |
| 432 this.notifyAll(); | |
| 433 } | |
| 434 } | |
| 435 else | |
| 436 { | |
| 437 final AsyncEventState event=_event; | |
| 438 if (event!=null) | |
| 439 { | |
| 440 ((AsyncEndPoint)endp).cancelTimeout(event._timeout); | |
| 441 } | |
| 442 } | |
| 443 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
444 |
| 865 | 445 boolean isUncompleted() |
| 446 { | |
| 447 synchronized (this) | |
| 448 { | |
| 449 return _state==__UNCOMPLETED; | |
| 450 } | |
| 451 } | |
| 452 | |
| 453 public boolean isComplete() | |
| 454 { | |
| 455 synchronized (this) | |
| 456 { | |
| 457 return _state==__COMPLETED; | |
| 458 } | |
| 459 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
460 |
| 865 | 461 public void dispatch(ServletContext context, String path) |
| 462 { | |
| 929 | 463 throw new UnsupportedOperationException(); |
| 865 | 464 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
465 |
| 865 | 466 public void dispatch(String path) |
| 467 { | |
| 929 | 468 throw new UnsupportedOperationException(); |
| 865 | 469 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
470 |
| 865 | 471 /* ------------------------------------------------------------ */ |
| 472 public Request getBaseRequest() | |
| 473 { | |
| 474 return _connection.getRequest(); | |
| 475 } | |
| 476 | |
| 477 /* ------------------------------------------------------------ */ | |
| 478 public ServletRequest getRequest() | |
| 479 { | |
| 480 if (_event!=null) | |
| 481 return _event.getSuppliedRequest(); | |
| 482 return _connection.getRequest(); | |
| 483 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
484 |
| 865 | 485 /* ------------------------------------------------------------ */ |
| 486 public ServletResponse getResponse() | |
| 487 { | |
| 488 if (_responseWrapped && _event!=null && _event.getSuppliedResponse()!=null) | |
| 489 return _event.getSuppliedResponse(); | |
| 490 return _connection.getResponse(); | |
| 491 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
492 |
| 865 | 493 /* ------------------------------------------------------------ */ |
| 494 public void start(final Runnable run) | |
| 495 { | |
| 496 final AsyncEventState event=_event; | |
| 497 if (event!=null) | |
| 498 { | |
|
875
b9aa175d9a29
remove Server.getThreadPool()
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
499 _connection.getServer().threadPool.execute(new Runnable() |
| 865 | 500 { |
| 501 public void run() | |
| 502 { | |
| 503 ((Context)event.getServletContext()).getContextHandler().handle(run); | |
| 504 } | |
| 505 }); | |
| 506 } | |
| 507 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
508 |
| 865 | 509 /* ------------------------------------------------------------ */ |
| 510 public boolean hasOriginalRequestAndResponse() | |
| 511 { | |
| 512 synchronized (this) | |
| 513 { | |
| 514 return (_event!=null && _event.getSuppliedRequest()==_connection._request && _event.getSuppliedResponse()==_connection._response); | |
| 515 } | |
| 516 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
517 |
| 865 | 518 /* ------------------------------------------------------------ */ |
| 519 public ContextHandler getContextHandler() | |
| 520 { | |
| 521 final AsyncEventState event=_event; | |
| 522 if (event!=null) | |
| 523 return ((Context)event.getServletContext()).getContextHandler(); | |
| 524 return null; | |
| 525 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
526 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
527 |
| 865 | 528 /* ------------------------------------------------------------ */ |
| 529 /** | |
| 530 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse() | |
| 531 */ | |
| 532 public ServletResponse getServletResponse() | |
| 533 { | |
| 534 if (_responseWrapped && _event!=null && _event.getSuppliedResponse()!=null) | |
| 535 return _event.getSuppliedResponse(); | |
| 536 return _connection.getResponse(); | |
| 537 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
538 |
| 865 | 539 /* ------------------------------------------------------------ */ |
| 540 /** | |
| 541 * @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String) | |
| 542 */ | |
| 543 public Object getAttribute(String name) | |
| 544 { | |
| 545 return _connection.getRequest().getAttribute(name); | |
| 546 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
547 |
| 865 | 548 /* ------------------------------------------------------------ */ |
| 549 /** | |
| 550 * @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String) | |
| 551 */ | |
| 552 public void removeAttribute(String name) | |
| 553 { | |
| 554 _connection.getRequest().removeAttribute(name); | |
| 555 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
556 |
| 865 | 557 /* ------------------------------------------------------------ */ |
| 558 /** | |
| 559 * @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object) | |
| 560 */ | |
| 561 public void setAttribute(String name, Object attribute) | |
| 562 { | |
| 563 _connection.getRequest().setAttribute(name,attribute); | |
| 564 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
565 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
566 |
| 865 | 567 /* ------------------------------------------------------------ */ |
| 568 /* ------------------------------------------------------------ */ | |
| 569 public class AsyncTimeout extends Timeout.Task implements Runnable | |
| 570 { | |
| 571 @Override | |
| 572 public void expired() | |
| 573 { | |
| 574 AsyncContinuation.this.expired(); | |
| 575 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
576 |
| 865 | 577 @Override |
| 578 public void run() | |
| 579 { | |
| 580 AsyncContinuation.this.expired(); | |
| 581 } | |
| 582 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
583 |
| 865 | 584 /* ------------------------------------------------------------ */ |
| 585 /* ------------------------------------------------------------ */ | |
| 586 public class AsyncEventState extends AsyncEvent | |
| 587 { | |
| 588 private final ServletContext _suspendedContext; | |
| 589 private ServletContext _dispatchContext; | |
| 590 private String _pathInContext; | |
| 591 private Timeout.Task _timeout= new AsyncTimeout(); | |
| 592 | |
| 593 public AsyncEventState(ServletContext context, ServletRequest request, ServletResponse response) | |
| 594 { | |
| 595 super(AsyncContinuation.this, request,response); | |
| 596 _suspendedContext=context; | |
| 597 // Get the base request So we can remember the initial paths | |
| 598 Request r=_connection.getRequest(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
599 |
| 865 | 600 // If we haven't been async dispatched before |
| 601 if (r.getAttribute(AsyncContext.ASYNC_REQUEST_URI)==null) | |
| 602 { | |
| 603 // We are setting these attributes during startAsync, when the spec implies that | |
| 604 // they are only available after a call to AsyncContext.dispatch(...); | |
| 605 | |
| 606 // have we been forwarded before? | |
| 607 String uri=(String)r.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI); | |
| 608 if (uri!=null) | |
| 609 { | |
| 610 r.setAttribute(AsyncContext.ASYNC_REQUEST_URI,uri); | |
| 611 r.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,r.getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH)); | |
| 612 r.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,r.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH)); | |
| 613 r.setAttribute(AsyncContext.ASYNC_PATH_INFO,r.getAttribute(RequestDispatcher.FORWARD_PATH_INFO)); | |
| 614 r.setAttribute(AsyncContext.ASYNC_QUERY_STRING,r.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING)); | |
| 615 } | |
| 616 else | |
| 617 { | |
| 618 r.setAttribute(AsyncContext.ASYNC_REQUEST_URI,r.getRequestURI()); | |
| 619 r.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,r.getContextPath()); | |
| 620 r.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,r.getServletPath()); | |
| 621 r.setAttribute(AsyncContext.ASYNC_PATH_INFO,r.getPathInfo()); | |
| 622 r.setAttribute(AsyncContext.ASYNC_QUERY_STRING,r.getQueryString()); | |
| 623 } | |
| 624 } | |
| 625 } | |
| 626 | |
| 627 public ServletContext getSuspendedContext() | |
| 628 { | |
| 629 return _suspendedContext; | |
| 630 } | |
| 631 | |
| 632 public ServletContext getDispatchContext() | |
| 633 { | |
| 634 return _dispatchContext; | |
| 635 } | |
| 636 | |
| 637 public ServletContext getServletContext() | |
| 638 { | |
| 639 return _dispatchContext==null?_suspendedContext:_dispatchContext; | |
| 640 } | |
| 641 | |
| 642 public void setPath(String path) | |
| 643 { | |
| 644 _pathInContext=path; | |
| 645 } | |
| 646 | |
| 647 /* ------------------------------------------------------------ */ | |
| 648 /** | |
| 649 * @return The path in the context | |
| 650 */ | |
| 651 public String getPath() | |
| 652 { | |
| 653 return _pathInContext; | |
| 654 } | |
| 655 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
656 } |
