Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AsyncContinuation.java @ 938:a088981f9cd4
remove more async code
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 09 Oct 2016 23:48:32 -0600 |
| parents | 0541b6034003 |
| children |
| 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 |
|
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
21 import org.slf4j.Logger; |
|
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
22 import org.slf4j.LoggerFactory; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 |
|
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
24 |
| 937 | 25 public final class AsyncContinuation |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 { |
| 865 | 27 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); |
|
931
6f7e2ff51879
remove ContinuationThrowable
Franklin Schmidt <fschmidt@gmail.com>
parents:
930
diff
changeset
|
28 |
| 865 | 29 // STATES: |
| 30 // handling() suspend() unhandle() resume() complete() doComplete() | |
| 31 // startAsync() dispatch() | |
| 32 // IDLE DISPATCHED | |
| 33 // DISPATCHED ASYNCSTARTED UNCOMPLETED | |
| 34 // ASYNCSTARTED ASYNCWAIT REDISPATCHING COMPLETING | |
| 35 // REDISPATCHING REDISPATCHED | |
| 36 // ASYNCWAIT REDISPATCH COMPLETING | |
| 37 // REDISPATCH REDISPATCHED | |
| 38 // REDISPATCHED ASYNCSTARTED UNCOMPLETED | |
| 39 // COMPLETING UNCOMPLETED UNCOMPLETED | |
| 40 // UNCOMPLETED COMPLETED | |
| 41 // COMPLETED | |
| 42 private static final int __IDLE=0; // Idle request | |
| 43 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet | |
| 44 private static final int __UNCOMPLETED=8; // Request is completable | |
| 45 private static final int __COMPLETED=9; // Request is complete | |
| 46 | |
| 47 private int _state; | |
| 48 | |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
49 AsyncContinuation() |
| 865 | 50 { |
| 51 _state=__IDLE; | |
| 52 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 |
| 865 | 54 @Override |
|
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
55 public synchronized String toString() |
| 865 | 56 { |
|
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
57 return super.toString()+"@"+getStatusString(); |
| 865 | 58 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 |
|
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
60 private synchronized String getStatusString() |
| 865 | 61 { |
|
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
62 return |
|
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
63 ((_state==__IDLE)?"IDLE": |
|
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
64 (_state==__DISPATCHED)?"DISPATCHED": |
|
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
65 (_state==__UNCOMPLETED)?"UNCOMPLETED": |
|
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
66 (_state==__COMPLETED)?"COMPLETE": |
|
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
67 ("UNKNOWN?"+_state)); |
| 865 | 68 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
69 |
| 929 | 70 protected synchronized void handling() |
| 865 | 71 { |
| 929 | 72 switch(_state) |
| 865 | 73 { |
| 929 | 74 case __IDLE: |
| 75 _state=__DISPATCHED; | |
| 76 return; | |
| 77 | |
| 78 default: | |
| 79 throw new IllegalStateException(this.getStatusString()); | |
| 865 | 80 } |
| 81 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 |
| 865 | 83 /* ------------------------------------------------------------ */ |
| 84 /** | |
| 85 * Signal that the HttpConnection has finished handling the request. | |
| 86 * For blocking connectors, this call may block if the request has | |
| 87 * been suspended (startAsync called). | |
| 88 * @return true if handling is complete, false if the request should | |
| 89 * be handled again (eg because of a resume that happened before unhandle was called) | |
| 90 */ | |
| 928 | 91 protected synchronized void unhandle() |
| 865 | 92 { |
| 928 | 93 switch(_state) |
| 865 | 94 { |
| 928 | 95 case __DISPATCHED: |
| 96 _state = __UNCOMPLETED; | |
| 97 return; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
98 |
| 928 | 99 default: |
| 100 throw new IllegalStateException(this.getStatusString()); | |
| 865 | 101 } |
| 102 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
103 |
|
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
104 |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
105 protected synchronized void doComplete(Throwable ex) |
| 865 | 106 { |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
107 switch(_state) |
| 865 | 108 { |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
109 case __UNCOMPLETED: |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
110 _state = __COMPLETED; |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
111 break; |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
112 |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
113 default: |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
114 throw new IllegalStateException(this.getStatusString()); |
| 865 | 115 } |
| 116 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
117 |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
118 protected synchronized void recycle() |
| 865 | 119 { |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
120 switch(_state) |
| 865 | 121 { |
|
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
122 case __DISPATCHED: |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
123 throw new IllegalStateException(getStatusString()); |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
124 default: |
|
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
125 _state=__IDLE; |
| 865 | 126 } |
| 127 } | |
| 128 | |
|
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
129 synchronized boolean isUncompleted() |
| 865 | 130 { |
|
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
131 return _state==__UNCOMPLETED; |
| 865 | 132 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 } |
