comparison src/org/eclipse/jetty/server/AsyncContinuation.java @ 934:fe461f7cfc8e

simplify AsyncContinuation
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 09 Oct 2016 21:03:00 -0600
parents c9513d80f305
children aa7dc1802d29
comparison
equal deleted inserted replaced
933:c9513d80f305 934:fe461f7cfc8e
37 import org.eclipse.jetty.server.handler.ContextHandler; 37 import org.eclipse.jetty.server.handler.ContextHandler;
38 import org.eclipse.jetty.server.handler.ContextHandler.Context; 38 import org.eclipse.jetty.server.handler.ContextHandler.Context;
39 import org.eclipse.jetty.util.URIUtil; 39 import org.eclipse.jetty.util.URIUtil;
40 import org.slf4j.Logger; 40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory; 41 import org.slf4j.LoggerFactory;
42 import org.eclipse.jetty.util.thread.Timeout;
43 42
44 /* ------------------------------------------------------------ */ 43 /* ------------------------------------------------------------ */
45 /** Implementation of Continuation interfaces 44 /** Implementation of Continuation interfaces
46 * 45 *
47 */ 46 */
74 private List<AsyncListener> _asyncListeners; 73 private List<AsyncListener> _asyncListeners;
75 private List<ContinuationListener> _continuationListeners; 74 private List<ContinuationListener> _continuationListeners;
76 75
77 /* ------------------------------------------------------------ */ 76 /* ------------------------------------------------------------ */
78 private int _state; 77 private int _state;
79 private volatile boolean _responseWrapped;
80 private long _timeoutMs=DEFAULT_TIMEOUT;
81 private volatile long _expireAt; 78 private volatile long _expireAt;
82 79
83 /* ------------------------------------------------------------ */
84 protected AsyncContinuation() 80 protected AsyncContinuation()
85 { 81 {
86 _state=__IDLE; 82 _state=__IDLE;
87 } 83 }
88 84
89 /* ------------------------------------------------------------ */ 85 protected synchronized void setConnection(final AbstractHttpConnection connection)
90 protected void setConnection(final AbstractHttpConnection connection) 86 {
91 { 87 _connection=connection;
92 synchronized(this)
93 {
94 _connection=connection;
95 }
96 } 88 }
97 89
98 /* ------------------------------------------------------------ */ 90 /* ------------------------------------------------------------ */
99 public void addListener(AsyncListener listener) 91 public void addListener(AsyncListener listener)
100 { 92 {
127 _continuationListeners=new ArrayList<ContinuationListener>(); 119 _continuationListeners=new ArrayList<ContinuationListener>();
128 _continuationListeners.add(listener); 120 _continuationListeners.add(listener);
129 } 121 }
130 } 122 }
131 123
132 /* ------------------------------------------------------------ */ 124
133 public void setTimeout(long ms) 125
134 {
135 synchronized(this)
136 {
137 _timeoutMs=ms;
138 }
139 }
140
141 /* ------------------------------------------------------------ */
142 public long getTimeout()
143 {
144 synchronized(this)
145 {
146 return _timeoutMs;
147 }
148 }
149
150 /* ------------------------------------------------------------ */
151 /**
152 * @see org.eclipse.jetty.continuation.Continuation#keepWrappers()
153 */
154
155 /* ------------------------------------------------------------ */
156 /**
157 * @see org.eclipse.jetty.continuation.Continuation#isResponseWrapped()
158 */
159 public boolean isResponseWrapped()
160 {
161 return _responseWrapped;
162 }
163
164 /* ------------------------------------------------------------ */
165 /* (non-Javadoc)
166 * @see javax.servlet.ServletRequest#isSuspended()
167 */
168 public boolean isSuspended()
169 {
170 synchronized(this)
171 {
172 switch(_state)
173 {
174 default:
175 return false;
176 }
177 }
178 }
179
180 /* ------------------------------------------------------------ */
181 public boolean isSuspending()
182 {
183 synchronized(this)
184 {
185 switch(_state)
186 {
187 default:
188 return false;
189 }
190 }
191 }
192
193 /* ------------------------------------------------------------ */
194 public boolean isDispatchable()
195 {
196 synchronized(this)
197 {
198 switch(_state)
199 {
200 default:
201 return false;
202 }
203 }
204 }
205
206 /* ------------------------------------------------------------ */
207 @Override 126 @Override
208 public String toString() 127 public String toString()
209 { 128 {
210 synchronized (this) 129 synchronized (this)
211 { 130 {
212 return super.toString()+"@"+getStatusString(); 131 return super.toString()+"@"+getStatusString();
213 } 132 }
214 } 133 }
215 134
216 /* ------------------------------------------------------------ */
217 public String getStatusString() 135 public String getStatusString()
218 { 136 {
219 synchronized (this) 137 synchronized (this)
220 { 138 {
221 return 139 return
261 default: 179 default:
262 throw new IllegalStateException(this.getStatusString()); 180 throw new IllegalStateException(this.getStatusString());
263 } 181 }
264 } 182 }
265 183
266 public void dispatch() 184
267 {
268 throw new UnsupportedOperationException();
269 }
270
271 /* ------------------------------------------------------------ */
272 protected void expired()
273 {
274 }
275
276 /* ------------------------------------------------------------ */
277 /* (non-Javadoc)
278 * @see javax.servlet.ServletRequest#complete()
279 */
280 public void complete()
281 {
282 // just like resume, except don't set _resumed=true;
283 boolean dispatch=false;
284 synchronized (this)
285 {
286 switch(_state)
287 {
288 case __DISPATCHED:
289 throw new IllegalStateException(this.getStatusString());
290
291 default:
292 throw new IllegalStateException(this.getStatusString());
293 }
294 }
295 }
296
297 /* ------------------------------------------------------------ */
298 /* (non-Javadoc)
299 * @see javax.servlet.ServletRequest#complete()
300 */
301 public void errorComplete()
302 {
303 // just like complete except can overrule a prior dispatch call;
304 synchronized (this)
305 {
306 switch(_state)
307 {
308 default:
309 throw new IllegalStateException(this.getStatusString());
310 }
311 }
312 }
313
314 /* ------------------------------------------------------------ */ 185 /* ------------------------------------------------------------ */
315 /* (non-Javadoc) 186 /* (non-Javadoc)
316 * @see javax.servlet.ServletRequest#complete() 187 * @see javax.servlet.ServletRequest#complete()
317 */ 188 */
318 protected void doComplete(Throwable ex) 189 protected void doComplete(Throwable ex)
381 case __DISPATCHED: 252 case __DISPATCHED:
382 throw new IllegalStateException(getStatusString()); 253 throw new IllegalStateException(getStatusString());
383 default: 254 default:
384 _state=__IDLE; 255 _state=__IDLE;
385 } 256 }
386 _responseWrapped=false;
387 cancelTimeout(); 257 cancelTimeout();
388 _timeoutMs=DEFAULT_TIMEOUT;
389 _continuationListeners=null; 258 _continuationListeners=null;
390 } 259 }
391 } 260 }
392 261
393 /* ------------------------------------------------------------ */ 262 /* ------------------------------------------------------------ */
405 else 274 else
406 { 275 {
407 } 276 }
408 } 277 }
409 278
410 boolean isUncompleted() 279 synchronized boolean isUncompleted()
411 { 280 {
412 synchronized (this) 281 return _state==__UNCOMPLETED;
413 {
414 return _state==__UNCOMPLETED;
415 }
416 } 282 }
417 283
418 public boolean isComplete() 284 public synchronized boolean isComplete()
419 { 285 {
420 synchronized (this) 286 return _state==__COMPLETED;
421 {
422 return _state==__COMPLETED;
423 }
424 }
425
426 public void dispatch(ServletContext context, String path)
427 {
428 throw new UnsupportedOperationException();
429 }
430
431 public void dispatch(String path)
432 {
433 throw new UnsupportedOperationException();
434 } 287 }
435 288
436 /* ------------------------------------------------------------ */ 289 /* ------------------------------------------------------------ */
437 public Request getBaseRequest() 290 public Request getBaseRequest()
438 { 291 {
449 public ServletResponse getResponse() 302 public ServletResponse getResponse()
450 { 303 {
451 return _connection.getResponse(); 304 return _connection.getResponse();
452 } 305 }
453 306
454 /* ------------------------------------------------------------ */
455 public void start(final Runnable run)
456 {
457 }
458
459 /* ------------------------------------------------------------ */
460 public boolean hasOriginalRequestAndResponse()
461 {
462 synchronized (this)
463 {
464 return false;
465 }
466 }
467
468 /* ------------------------------------------------------------ */
469 public ContextHandler getContextHandler()
470 {
471 return null;
472 }
473
474 307
475 /* ------------------------------------------------------------ */ 308 /* ------------------------------------------------------------ */
476 /** 309 /**
477 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse() 310 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse()
478 */ 311 */