Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AsyncContinuation.java @ 935:aa7dc1802d29
remove ContinuationListener
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 09 Oct 2016 21:15:24 -0600 |
parents | fe461f7cfc8e |
children | 237ace6e8bc2 |
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.RequestDispatcher; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import javax.servlet.ServletException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.util.ArrayList; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.util.List; |
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 javax.servlet.ServletContext; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import javax.servlet.ServletRequest; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import javax.servlet.ServletResponse; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import javax.servlet.http.HttpServletRequest; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.continuation.Continuation; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.io.AsyncEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.server.handler.ContextHandler; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.server.handler.ContextHandler.Context; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 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
|
38 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
39 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 /* ------------------------------------------------------------ */ |
933
c9513d80f305
remove AsyncContext support
Franklin Schmidt <fschmidt@gmail.com>
parents:
932
diff
changeset
|
42 /** Implementation of Continuation interfaces |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 */ |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
45 public final class AsyncContinuation implements Continuation |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 { |
865 | 47 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 |
865 | 49 private final static long DEFAULT_TIMEOUT=30000L; |
931
6f7e2ff51879
remove ContinuationThrowable
Franklin Schmidt <fschmidt@gmail.com>
parents:
930
diff
changeset
|
50 |
865 | 51 // STATES: |
52 // handling() suspend() unhandle() resume() complete() doComplete() | |
53 // startAsync() dispatch() | |
54 // IDLE DISPATCHED | |
55 // DISPATCHED ASYNCSTARTED UNCOMPLETED | |
56 // ASYNCSTARTED ASYNCWAIT REDISPATCHING COMPLETING | |
57 // REDISPATCHING REDISPATCHED | |
58 // ASYNCWAIT REDISPATCH COMPLETING | |
59 // REDISPATCH REDISPATCHED | |
60 // REDISPATCHED ASYNCSTARTED UNCOMPLETED | |
61 // COMPLETING UNCOMPLETED UNCOMPLETED | |
62 // UNCOMPLETED COMPLETED | |
63 // COMPLETED | |
64 private static final int __IDLE=0; // Idle request | |
65 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet | |
66 private static final int __UNCOMPLETED=8; // Request is completable | |
67 private static final int __COMPLETED=9; // Request is complete | |
68 | |
69 /* ------------------------------------------------------------ */ | |
70 protected AbstractHttpConnection _connection; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 |
865 | 72 /* ------------------------------------------------------------ */ |
73 private int _state; | |
74 private volatile long _expireAt; | |
75 | |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
76 AsyncContinuation() |
865 | 77 { |
78 _state=__IDLE; | |
79 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
81 protected synchronized void setConnection(final AbstractHttpConnection connection) |
865 | 82 { |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
83 _connection=connection; |
865 | 84 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
85 |
865 | 86 |
87 @Override | |
88 public String toString() | |
89 { | |
90 synchronized (this) | |
91 { | |
92 return super.toString()+"@"+getStatusString(); | |
93 } | |
94 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
95 |
865 | 96 public String getStatusString() |
97 { | |
98 synchronized (this) | |
99 { | |
100 return | |
101 ((_state==__IDLE)?"IDLE": | |
102 (_state==__DISPATCHED)?"DISPATCHED": | |
103 (_state==__UNCOMPLETED)?"UNCOMPLETED": | |
104 (_state==__COMPLETED)?"COMPLETE": | |
929 | 105 ("UNKNOWN?"+_state)); |
865 | 106 } |
107 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 |
929 | 109 protected synchronized void handling() |
865 | 110 { |
929 | 111 switch(_state) |
865 | 112 { |
929 | 113 case __IDLE: |
114 _state=__DISPATCHED; | |
115 return; | |
116 | |
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 |
865 | 122 /* ------------------------------------------------------------ */ |
123 /** | |
124 * Signal that the HttpConnection has finished handling the request. | |
125 * For blocking connectors, this call may block if the request has | |
126 * been suspended (startAsync called). | |
127 * @return true if handling is complete, false if the request should | |
128 * be handled again (eg because of a resume that happened before unhandle was called) | |
129 */ | |
928 | 130 protected synchronized void unhandle() |
865 | 131 { |
928 | 132 switch(_state) |
865 | 133 { |
928 | 134 case __DISPATCHED: |
135 _state = __UNCOMPLETED; | |
136 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
137 |
928 | 138 default: |
139 throw new IllegalStateException(this.getStatusString()); | |
865 | 140 } |
141 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
142 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
143 |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
144 protected synchronized void doComplete(Throwable ex) |
865 | 145 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
146 switch(_state) |
865 | 147 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
148 case __UNCOMPLETED: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
149 _state = __COMPLETED; |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
150 break; |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
151 |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
152 default: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
153 throw new IllegalStateException(this.getStatusString()); |
865 | 154 } |
155 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
156 |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
157 protected synchronized void recycle() |
865 | 158 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
159 switch(_state) |
865 | 160 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
161 case __DISPATCHED: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
162 throw new IllegalStateException(getStatusString()); |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
163 default: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
164 _state=__IDLE; |
865 | 165 } |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
166 cancelTimeout(); |
865 | 167 } |
168 | |
169 /* ------------------------------------------------------------ */ | |
170 protected void cancelTimeout() | |
171 { | |
172 EndPoint endp=_connection.getEndPoint(); | |
173 if (endp.isBlocking()) | |
174 { | |
175 synchronized(this) | |
176 { | |
177 _expireAt=0; | |
178 this.notifyAll(); | |
179 } | |
180 } | |
181 else | |
182 { | |
183 } | |
184 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
186 synchronized boolean isUncompleted() |
865 | 187 { |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
188 return _state==__UNCOMPLETED; |
865 | 189 } |
190 | |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
191 public synchronized boolean isComplete() |
865 | 192 { |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
193 return _state==__COMPLETED; |
865 | 194 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 |
865 | 196 /* ------------------------------------------------------------ */ |
197 public Request getBaseRequest() | |
198 { | |
199 return _connection.getRequest(); | |
200 } | |
201 | |
202 /* ------------------------------------------------------------ */ | |
203 public ServletRequest getRequest() | |
204 { | |
205 return _connection.getRequest(); | |
206 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 |
865 | 208 /* ------------------------------------------------------------ */ |
209 public ServletResponse getResponse() | |
210 { | |
211 return _connection.getResponse(); | |
212 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
213 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
214 |
865 | 215 /* ------------------------------------------------------------ */ |
216 /** | |
217 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse() | |
218 */ | |
219 public ServletResponse getServletResponse() | |
220 { | |
221 return _connection.getResponse(); | |
222 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
223 |
865 | 224 /* ------------------------------------------------------------ */ |
225 /** | |
226 * @see org.eclipse.jetty.continuation.Continuation#getAttribute(java.lang.String) | |
227 */ | |
228 public Object getAttribute(String name) | |
229 { | |
230 return _connection.getRequest().getAttribute(name); | |
231 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
232 |
865 | 233 /* ------------------------------------------------------------ */ |
234 /** | |
235 * @see org.eclipse.jetty.continuation.Continuation#removeAttribute(java.lang.String) | |
236 */ | |
237 public void removeAttribute(String name) | |
238 { | |
239 _connection.getRequest().removeAttribute(name); | |
240 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 |
865 | 242 /* ------------------------------------------------------------ */ |
243 /** | |
244 * @see org.eclipse.jetty.continuation.Continuation#setAttribute(java.lang.String, java.lang.Object) | |
245 */ | |
246 public void setAttribute(String name, Object attribute) | |
247 { | |
248 _connection.getRequest().setAttribute(name,attribute); | |
249 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
250 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
251 } |