Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
934:fe461f7cfc8e | 935:aa7dc1802d29 |
---|---|
16 // ======================================================================== | 16 // ======================================================================== |
17 // | 17 // |
18 | 18 |
19 package org.eclipse.jetty.server; | 19 package org.eclipse.jetty.server; |
20 | 20 |
21 import javax.servlet.AsyncListener; | |
22 import javax.servlet.RequestDispatcher; | 21 import javax.servlet.RequestDispatcher; |
23 import javax.servlet.ServletException; | 22 import javax.servlet.ServletException; |
24 | 23 |
25 import java.util.ArrayList; | 24 import java.util.ArrayList; |
26 import java.util.List; | 25 import java.util.List; |
29 import javax.servlet.ServletRequest; | 28 import javax.servlet.ServletRequest; |
30 import javax.servlet.ServletResponse; | 29 import javax.servlet.ServletResponse; |
31 import javax.servlet.http.HttpServletRequest; | 30 import javax.servlet.http.HttpServletRequest; |
32 | 31 |
33 import org.eclipse.jetty.continuation.Continuation; | 32 import org.eclipse.jetty.continuation.Continuation; |
34 import org.eclipse.jetty.continuation.ContinuationListener; | |
35 import org.eclipse.jetty.io.AsyncEndPoint; | 33 import org.eclipse.jetty.io.AsyncEndPoint; |
36 import org.eclipse.jetty.io.EndPoint; | 34 import org.eclipse.jetty.io.EndPoint; |
37 import org.eclipse.jetty.server.handler.ContextHandler; | 35 import org.eclipse.jetty.server.handler.ContextHandler; |
38 import org.eclipse.jetty.server.handler.ContextHandler.Context; | 36 import org.eclipse.jetty.server.handler.ContextHandler.Context; |
39 import org.eclipse.jetty.util.URIUtil; | 37 import org.eclipse.jetty.util.URIUtil; |
42 | 40 |
43 /* ------------------------------------------------------------ */ | 41 /* ------------------------------------------------------------ */ |
44 /** Implementation of Continuation interfaces | 42 /** Implementation of Continuation interfaces |
45 * | 43 * |
46 */ | 44 */ |
47 public class AsyncContinuation implements Continuation | 45 public final class AsyncContinuation implements Continuation |
48 { | 46 { |
49 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); | 47 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); |
50 | 48 |
51 private final static long DEFAULT_TIMEOUT=30000L; | 49 private final static long DEFAULT_TIMEOUT=30000L; |
52 | 50 |
68 private static final int __UNCOMPLETED=8; // Request is completable | 66 private static final int __UNCOMPLETED=8; // Request is completable |
69 private static final int __COMPLETED=9; // Request is complete | 67 private static final int __COMPLETED=9; // Request is complete |
70 | 68 |
71 /* ------------------------------------------------------------ */ | 69 /* ------------------------------------------------------------ */ |
72 protected AbstractHttpConnection _connection; | 70 protected AbstractHttpConnection _connection; |
73 private List<AsyncListener> _asyncListeners; | |
74 private List<ContinuationListener> _continuationListeners; | |
75 | 71 |
76 /* ------------------------------------------------------------ */ | 72 /* ------------------------------------------------------------ */ |
77 private int _state; | 73 private int _state; |
78 private volatile long _expireAt; | 74 private volatile long _expireAt; |
79 | 75 |
80 protected AsyncContinuation() | 76 AsyncContinuation() |
81 { | 77 { |
82 _state=__IDLE; | 78 _state=__IDLE; |
83 } | 79 } |
84 | 80 |
85 protected synchronized void setConnection(final AbstractHttpConnection connection) | 81 protected synchronized void setConnection(final AbstractHttpConnection connection) |
86 { | 82 { |
87 _connection=connection; | 83 _connection=connection; |
88 } | 84 } |
89 | |
90 /* ------------------------------------------------------------ */ | |
91 public void addListener(AsyncListener listener) | |
92 { | |
93 synchronized(this) | |
94 { | |
95 if (_asyncListeners==null) | |
96 _asyncListeners=new ArrayList<AsyncListener>(); | |
97 _asyncListeners.add(listener); | |
98 } | |
99 } | |
100 | |
101 /* ------------------------------------------------------------ */ | |
102 public void addListener(AsyncListener listener,ServletRequest request, ServletResponse response) | |
103 { | |
104 synchronized(this) | |
105 { | |
106 // TODO handle the request/response ??? | |
107 if (_asyncListeners==null) | |
108 _asyncListeners=new ArrayList<AsyncListener>(); | |
109 _asyncListeners.add(listener); | |
110 } | |
111 } | |
112 | |
113 /* ------------------------------------------------------------ */ | |
114 public void addContinuationListener(ContinuationListener listener) | |
115 { | |
116 synchronized(this) | |
117 { | |
118 if (_continuationListeners==null) | |
119 _continuationListeners=new ArrayList<ContinuationListener>(); | |
120 _continuationListeners.add(listener); | |
121 } | |
122 } | |
123 | |
124 | 85 |
125 | 86 |
126 @Override | 87 @Override |
127 public String toString() | 88 public String toString() |
128 { | 89 { |
149 { | 110 { |
150 switch(_state) | 111 switch(_state) |
151 { | 112 { |
152 case __IDLE: | 113 case __IDLE: |
153 _state=__DISPATCHED; | 114 _state=__DISPATCHED; |
154 if (_asyncListeners!=null) | |
155 _asyncListeners.clear(); | |
156 return; | 115 return; |
157 | 116 |
158 default: | 117 default: |
159 throw new IllegalStateException(this.getStatusString()); | 118 throw new IllegalStateException(this.getStatusString()); |
160 } | 119 } |
180 throw new IllegalStateException(this.getStatusString()); | 139 throw new IllegalStateException(this.getStatusString()); |
181 } | 140 } |
182 } | 141 } |
183 | 142 |
184 | 143 |
185 /* ------------------------------------------------------------ */ | 144 protected synchronized void doComplete(Throwable ex) |
186 /* (non-Javadoc) | 145 { |
187 * @see javax.servlet.ServletRequest#complete() | 146 switch(_state) |
188 */ | 147 { |
189 protected void doComplete(Throwable ex) | 148 case __UNCOMPLETED: |
190 { | 149 _state = __COMPLETED; |
191 final List<ContinuationListener> cListeners; | 150 break; |
192 final List<AsyncListener> aListeners; | 151 |
193 synchronized (this) | 152 default: |
194 { | 153 throw new IllegalStateException(this.getStatusString()); |
195 switch(_state) | 154 } |
196 { | 155 } |
197 case __UNCOMPLETED: | 156 |
198 _state = __COMPLETED; | 157 protected synchronized void recycle() |
199 cListeners=_continuationListeners; | 158 { |
200 aListeners=_asyncListeners; | 159 switch(_state) |
201 break; | 160 { |
202 | 161 case __DISPATCHED: |
203 default: | 162 throw new IllegalStateException(getStatusString()); |
204 cListeners=null; | 163 default: |
205 aListeners=null; | 164 _state=__IDLE; |
206 throw new IllegalStateException(this.getStatusString()); | 165 } |
207 } | 166 cancelTimeout(); |
208 } | |
209 | |
210 if (aListeners!=null) | |
211 { | |
212 for (AsyncListener listener : aListeners) | |
213 { | |
214 try | |
215 { | |
216 if (ex!=null) | |
217 { | |
218 throw new UnsupportedOperationException(); | |
219 } | |
220 else | |
221 listener.onComplete(null); | |
222 } | |
223 catch(Exception e) | |
224 { | |
225 LOG.warn("",e); | |
226 } | |
227 } | |
228 } | |
229 if (cListeners!=null) | |
230 { | |
231 for (ContinuationListener listener : cListeners) | |
232 { | |
233 try | |
234 { | |
235 listener.onComplete(this); | |
236 } | |
237 catch(Exception e) | |
238 { | |
239 LOG.warn("",e); | |
240 } | |
241 } | |
242 } | |
243 } | |
244 | |
245 /* ------------------------------------------------------------ */ | |
246 protected void recycle() | |
247 { | |
248 synchronized (this) | |
249 { | |
250 switch(_state) | |
251 { | |
252 case __DISPATCHED: | |
253 throw new IllegalStateException(getStatusString()); | |
254 default: | |
255 _state=__IDLE; | |
256 } | |
257 cancelTimeout(); | |
258 _continuationListeners=null; | |
259 } | |
260 } | 167 } |
261 | 168 |
262 /* ------------------------------------------------------------ */ | 169 /* ------------------------------------------------------------ */ |
263 protected void cancelTimeout() | 170 protected void cancelTimeout() |
264 { | 171 { |