comparison src/org/eclipse/jetty/server/AsyncContinuation.java @ 918:7b62446899c6

remove unused states in AsyncContinuation
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 09 Oct 2016 03:37:53 -0600
parents 1fc8ee20cb18
children dd6b1f079634
comparison
equal deleted inserted replaced
917:1fc8ee20cb18 918:7b62446899c6
69 // COMPLETING UNCOMPLETED UNCOMPLETED 69 // COMPLETING UNCOMPLETED UNCOMPLETED
70 // UNCOMPLETED COMPLETED 70 // UNCOMPLETED COMPLETED
71 // COMPLETED 71 // COMPLETED
72 private static final int __IDLE=0; // Idle request 72 private static final int __IDLE=0; // Idle request
73 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet 73 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet
74 private static final int __ASYNCSTARTED=2; // Suspend called, but not yet returned to container
75 private static final int __REDISPATCHING=3;// resumed while dispatched
76 private static final int __ASYNCWAIT=4; // Suspended and parked
77 private static final int __REDISPATCH=5; // Has been scheduled
78 private static final int __REDISPATCHED=6; // Request redispatched to filter/servlet
79 private static final int __COMPLETING=7; // complete while dispatched
80 private static final int __UNCOMPLETED=8; // Request is completable 74 private static final int __UNCOMPLETED=8; // Request is completable
81 private static final int __COMPLETED=9; // Request is complete 75 private static final int __COMPLETED=9; // Request is complete
82 76
83 /* ------------------------------------------------------------ */ 77 /* ------------------------------------------------------------ */
84 protected AbstractHttpConnection _connection; 78 protected AbstractHttpConnection _connection;
213 { 207 {
214 synchronized(this) 208 synchronized(this)
215 { 209 {
216 switch(_state) 210 switch(_state)
217 { 211 {
218 case __ASYNCSTARTED:
219 case __REDISPATCHING:
220 case __COMPLETING:
221 case __ASYNCWAIT:
222 return true;
223
224 default: 212 default:
225 return false; 213 return false;
226 } 214 }
227 } 215 }
228 } 216 }
232 { 220 {
233 synchronized(this) 221 synchronized(this)
234 { 222 {
235 switch(_state) 223 switch(_state)
236 { 224 {
237 case __ASYNCSTARTED:
238 case __ASYNCWAIT:
239 return true;
240
241 default: 225 default:
242 return false; 226 return false;
243 } 227 }
244 } 228 }
245 } 229 }
249 { 233 {
250 synchronized(this) 234 synchronized(this)
251 { 235 {
252 switch(_state) 236 switch(_state)
253 { 237 {
254 case __REDISPATCH:
255 case __REDISPATCHED:
256 case __REDISPATCHING:
257 case __COMPLETING:
258 return true;
259
260 default: 238 default:
261 return false; 239 return false;
262 } 240 }
263 } 241 }
264 } 242 }
279 synchronized (this) 257 synchronized (this)
280 { 258 {
281 return 259 return
282 ((_state==__IDLE)?"IDLE": 260 ((_state==__IDLE)?"IDLE":
283 (_state==__DISPATCHED)?"DISPATCHED": 261 (_state==__DISPATCHED)?"DISPATCHED":
284 (_state==__ASYNCSTARTED)?"ASYNCSTARTED":
285 (_state==__ASYNCWAIT)?"ASYNCWAIT":
286 (_state==__REDISPATCHING)?"REDISPATCHING":
287 (_state==__REDISPATCH)?"REDISPATCH":
288 (_state==__REDISPATCHED)?"REDISPATCHED":
289 (_state==__COMPLETING)?"COMPLETING":
290 (_state==__UNCOMPLETED)?"UNCOMPLETED": 262 (_state==__UNCOMPLETED)?"UNCOMPLETED":
291 (_state==__COMPLETED)?"COMPLETE": 263 (_state==__COMPLETED)?"COMPLETE":
292 ("UNKNOWN?"+_state))+ 264 ("UNKNOWN?"+_state))+
293 (_initial?",initial":"")+ 265 (_initial?",initial":"")+
294 (_resumed?",resumed":"")+ 266 (_resumed?",resumed":"")+
320 _asyncListeners=_lastAsyncListeners; 292 _asyncListeners=_lastAsyncListeners;
321 _lastAsyncListeners=null; 293 _lastAsyncListeners=null;
322 } 294 }
323 return true; 295 return true;
324 296
325 case __COMPLETING:
326 _state=__UNCOMPLETED;
327 return false;
328
329 case __ASYNCWAIT:
330 return false;
331
332 case __REDISPATCH:
333 _state=__REDISPATCHED;
334 return true;
335
336 default: 297 default:
337 throw new IllegalStateException(this.getStatusString()); 298 throw new IllegalStateException(this.getStatusString());
338 } 299 }
339 } 300 }
340 } 301 }
351 { 312 {
352 synchronized (this) 313 synchronized (this)
353 { 314 {
354 switch(_state) 315 switch(_state)
355 { 316 {
356 case __REDISPATCHED:
357 case __DISPATCHED: 317 case __DISPATCHED:
358 _state=__UNCOMPLETED; 318 _state = __UNCOMPLETED;
359 return true; 319 return true;
360 320
361 case __IDLE: 321 case __IDLE:
362 throw new IllegalStateException(this.getStatusString()); 322 throw new IllegalStateException(this.getStatusString());
363 323
364 case __ASYNCSTARTED:
365 _initial=false;
366 _state=__ASYNCWAIT;
367 scheduleTimeout(); // could block and change state.
368 if (_state==__ASYNCWAIT)
369 return true;
370 else if (_state==__COMPLETING)
371 {
372 _state=__UNCOMPLETED;
373 return true;
374 }
375 _initial=false;
376 _state=__REDISPATCHED;
377 return false;
378
379 case __REDISPATCHING:
380 _initial=false;
381 _state=__REDISPATCHED;
382 return false;
383
384 case __COMPLETING:
385 _initial=false;
386 _state=__UNCOMPLETED;
387 return true;
388
389 default: 324 default:
390 throw new IllegalStateException(this.getStatusString()); 325 throw new IllegalStateException(this.getStatusString());
391 } 326 }
392 } 327 }
393 } 328 }
398 boolean dispatch=false; 333 boolean dispatch=false;
399 synchronized (this) 334 synchronized (this)
400 { 335 {
401 switch(_state) 336 switch(_state)
402 { 337 {
403 case __ASYNCSTARTED:
404 _state=__REDISPATCHING;
405 _resumed=true;
406 return;
407
408 case __ASYNCWAIT:
409 dispatch=!_expired;
410 _state=__REDISPATCH;
411 _resumed=true;
412 break;
413
414 case __REDISPATCH:
415 return;
416
417 default: 338 default:
418 throw new IllegalStateException(this.getStatusString()); 339 throw new IllegalStateException(this.getStatusString());
419 } 340 }
420 } 341 }
421
422 if (dispatch)
423 {
424 cancelTimeout();
425 scheduleDispatch();
426 }
427 } 342 }
428 343
429 /* ------------------------------------------------------------ */ 344 /* ------------------------------------------------------------ */
430 protected void expired() 345 protected void expired()
346 {
347 }
348
349 /* ------------------------------------------------------------ */
350 /* (non-Javadoc)
351 * @see javax.servlet.ServletRequest#complete()
352 */
353 public void complete()
354 {
355 // just like resume, except don't set _resumed=true;
356 boolean dispatch=false;
357 synchronized (this)
358 {
359 switch(_state)
360 {
361 case __DISPATCHED:
362 throw new IllegalStateException(this.getStatusString());
363
364 default:
365 throw new IllegalStateException(this.getStatusString());
366 }
367 }
368 }
369
370 /* ------------------------------------------------------------ */
371 /* (non-Javadoc)
372 * @see javax.servlet.ServletRequest#complete()
373 */
374 public void errorComplete()
375 {
376 // just like complete except can overrule a prior dispatch call;
377 synchronized (this)
378 {
379 switch(_state)
380 {
381 default:
382 throw new IllegalStateException(this.getStatusString());
383 }
384 }
385 }
386
387 /* ------------------------------------------------------------ */
388 @Override
389 public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException
390 {
391 try
392 {
393 // TODO inject
394 return clazz.newInstance();
395 }
396 catch(Exception e)
397 {
398 throw new ServletException(e);
399 }
400 }
401
402
403 /* ------------------------------------------------------------ */
404 /* (non-Javadoc)
405 * @see javax.servlet.ServletRequest#complete()
406 */
407 protected void doComplete(Throwable ex)
431 { 408 {
432 final List<ContinuationListener> cListeners; 409 final List<ContinuationListener> cListeners;
433 final List<AsyncListener> aListeners; 410 final List<AsyncListener> aListeners;
434 synchronized (this) 411 synchronized (this)
435 { 412 {
436 switch(_state) 413 switch(_state)
437 { 414 {
438 case __ASYNCSTARTED:
439 case __ASYNCWAIT:
440 cListeners=_continuationListeners;
441 aListeners=_asyncListeners;
442 break;
443 default:
444 cListeners=null;
445 aListeners=null;
446 return;
447 }
448 _expired=true;
449 }
450
451 if (aListeners!=null)
452 {
453 for (AsyncListener listener : aListeners)
454 {
455 try
456 {
457 listener.onTimeout(_event);
458 }
459 catch(Exception e)
460 {
461 LOG.debug("",e);
462 _connection.getRequest().setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
463 break;
464 }
465 }
466 }
467 if (cListeners!=null)
468 {
469 for (ContinuationListener listener : cListeners)
470 {
471 try
472 {
473 listener.onTimeout(this);
474 }
475 catch(Exception e)
476 {
477 LOG.warn("",e);
478 }
479 }
480 }
481
482 synchronized (this)
483 {
484 switch(_state)
485 {
486 case __ASYNCSTARTED:
487 case __ASYNCWAIT:
488 dispatch();
489 break;
490
491 default:
492 if (!_continuation)
493 _expired=false;
494 }
495 }
496
497 scheduleDispatch();
498 }
499
500 /* ------------------------------------------------------------ */
501 /* (non-Javadoc)
502 * @see javax.servlet.ServletRequest#complete()
503 */
504 public void complete()
505 {
506 // just like resume, except don't set _resumed=true;
507 boolean dispatch=false;
508 synchronized (this)
509 {
510 switch(_state)
511 {
512 case __DISPATCHED:
513 case __REDISPATCHED:
514 throw new IllegalStateException(this.getStatusString());
515
516 case __ASYNCSTARTED:
517 _state=__COMPLETING;
518 return;
519
520 case __ASYNCWAIT:
521 _state=__COMPLETING;
522 dispatch=!_expired;
523 break;
524
525 default:
526 throw new IllegalStateException(this.getStatusString());
527 }
528 }
529
530 if (dispatch)
531 {
532 cancelTimeout();
533 scheduleDispatch();
534 }
535 }
536
537 /* ------------------------------------------------------------ */
538 /* (non-Javadoc)
539 * @see javax.servlet.ServletRequest#complete()
540 */
541 public void errorComplete()
542 {
543 // just like complete except can overrule a prior dispatch call;
544 synchronized (this)
545 {
546 switch(_state)
547 {
548 case __REDISPATCHING:
549 case __ASYNCSTARTED:
550 _state=__COMPLETING;
551 _resumed=false;
552 return;
553
554 case __COMPLETING:
555 return;
556
557 default:
558 throw new IllegalStateException(this.getStatusString());
559 }
560 }
561 }
562
563 /* ------------------------------------------------------------ */
564 @Override
565 public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException
566 {
567 try
568 {
569 // TODO inject
570 return clazz.newInstance();
571 }
572 catch(Exception e)
573 {
574 throw new ServletException(e);
575 }
576 }
577
578
579 /* ------------------------------------------------------------ */
580 /* (non-Javadoc)
581 * @see javax.servlet.ServletRequest#complete()
582 */
583 protected void doComplete(Throwable ex)
584 {
585 final List<ContinuationListener> cListeners;
586 final List<AsyncListener> aListeners;
587 synchronized (this)
588 {
589 switch(_state)
590 {
591 case __UNCOMPLETED: 415 case __UNCOMPLETED:
592 _state=__COMPLETED; 416 _state = __COMPLETED;
593 cListeners=_continuationListeners; 417 cListeners=_continuationListeners;
594 aListeners=_asyncListeners; 418 aListeners=_asyncListeners;
595 break; 419 break;
596 420
597 default: 421 default:
644 synchronized (this) 468 synchronized (this)
645 { 469 {
646 switch(_state) 470 switch(_state)
647 { 471 {
648 case __DISPATCHED: 472 case __DISPATCHED:
649 case __REDISPATCHED:
650 throw new IllegalStateException(getStatusString()); 473 throw new IllegalStateException(getStatusString());
651 default: 474 default:
652 _state=__IDLE; 475 _state=__IDLE;
653 } 476 }
654 _initial = true; 477 _initial = true;
744 /* ------------------------------------------------------------ */ 567 /* ------------------------------------------------------------ */
745 public boolean isCompleting() 568 public boolean isCompleting()
746 { 569 {
747 synchronized (this) 570 synchronized (this)
748 { 571 {
749 return _state==__COMPLETING; 572 return false;
750 } 573 }
751 } 574 }
752 575
753 /* ------------------------------------------------------------ */ 576 /* ------------------------------------------------------------ */
754 boolean isUncompleted() 577 boolean isUncompleted()
774 { 597 {
775 synchronized (this) 598 synchronized (this)
776 { 599 {
777 switch(_state) 600 switch(_state)
778 { 601 {
779 case __ASYNCSTARTED:
780 case __REDISPATCHING:
781 case __REDISPATCH:
782 case __ASYNCWAIT:
783 return true;
784
785 default: 602 default:
786 return false; 603 return false;
787 } 604 }
788 } 605 }
789 } 606 }