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