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