comparison 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
comparison
equal deleted inserted replaced
935:aa7dc1802d29 936:237ace6e8bc2
16 // ======================================================================== 16 // ========================================================================
17 // 17 //
18 18
19 package org.eclipse.jetty.server; 19 package org.eclipse.jetty.server;
20 20
21 import javax.servlet.RequestDispatcher;
22 import javax.servlet.ServletException;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.servlet.ServletContext;
28 import javax.servlet.ServletRequest;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
31
32 import org.eclipse.jetty.continuation.Continuation; 21 import org.eclipse.jetty.continuation.Continuation;
33 import org.eclipse.jetty.io.AsyncEndPoint;
34 import org.eclipse.jetty.io.EndPoint; 22 import org.eclipse.jetty.io.EndPoint;
35 import org.eclipse.jetty.server.handler.ContextHandler;
36 import org.eclipse.jetty.server.handler.ContextHandler.Context;
37 import org.eclipse.jetty.util.URIUtil;
38 import org.slf4j.Logger; 23 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
25
40 26
41 /* ------------------------------------------------------------ */ 27 /* ------------------------------------------------------------ */
42 /** Implementation of Continuation interfaces 28 /** Implementation of Continuation interfaces
43 * 29 *
44 */ 30 */
69 /* ------------------------------------------------------------ */ 55 /* ------------------------------------------------------------ */
70 protected AbstractHttpConnection _connection; 56 protected AbstractHttpConnection _connection;
71 57
72 /* ------------------------------------------------------------ */ 58 /* ------------------------------------------------------------ */
73 private int _state; 59 private int _state;
74 private volatile long _expireAt;
75 60
76 AsyncContinuation() 61 AsyncContinuation()
77 { 62 {
78 _state=__IDLE; 63 _state=__IDLE;
79 } 64 }
83 _connection=connection; 68 _connection=connection;
84 } 69 }
85 70
86 71
87 @Override 72 @Override
88 public String toString() 73 public synchronized String toString()
89 { 74 {
90 synchronized (this) 75 return super.toString()+"@"+getStatusString();
91 {
92 return super.toString()+"@"+getStatusString();
93 }
94 } 76 }
95 77
96 public String getStatusString() 78 private synchronized String getStatusString()
97 { 79 {
98 synchronized (this) 80 return
99 { 81 ((_state==__IDLE)?"IDLE":
100 return 82 (_state==__DISPATCHED)?"DISPATCHED":
101 ((_state==__IDLE)?"IDLE": 83 (_state==__UNCOMPLETED)?"UNCOMPLETED":
102 (_state==__DISPATCHED)?"DISPATCHED": 84 (_state==__COMPLETED)?"COMPLETE":
103 (_state==__UNCOMPLETED)?"UNCOMPLETED": 85 ("UNKNOWN?"+_state));
104 (_state==__COMPLETED)?"COMPLETE":
105 ("UNKNOWN?"+_state));
106 }
107 } 86 }
108 87
109 protected synchronized void handling() 88 protected synchronized void handling()
110 { 89 {
111 switch(_state) 90 switch(_state)
164 _state=__IDLE; 143 _state=__IDLE;
165 } 144 }
166 cancelTimeout(); 145 cancelTimeout();
167 } 146 }
168 147
169 /* ------------------------------------------------------------ */ 148 private void cancelTimeout()
170 protected void cancelTimeout()
171 { 149 {
172 EndPoint endp=_connection.getEndPoint(); 150 EndPoint endp=_connection.getEndPoint();
173 if (endp.isBlocking()) 151 if (endp.isBlocking())
174 { 152 {
175 synchronized(this) 153 synchronized(this)
176 { 154 {
177 _expireAt=0;
178 this.notifyAll(); 155 this.notifyAll();
179 } 156 }
180 }
181 else
182 {
183 } 157 }
184 } 158 }
185 159
186 synchronized boolean isUncompleted() 160 synchronized boolean isUncompleted()
187 { 161 {
188 return _state==__UNCOMPLETED; 162 return _state==__UNCOMPLETED;
189 } 163 }
190
191 public synchronized boolean isComplete()
192 {
193 return _state==__COMPLETED;
194 }
195
196 /* ------------------------------------------------------------ */
197 public Request getBaseRequest()
198 {
199 return _connection.getRequest();
200 }
201
202 /* ------------------------------------------------------------ */
203 public ServletRequest getRequest()
204 {
205 return _connection.getRequest();
206 }
207
208 /* ------------------------------------------------------------ */
209 public ServletResponse getResponse()
210 {
211 return _connection.getResponse();
212 }
213
214
215 /* ------------------------------------------------------------ */
216 /**
217 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse()
218 */
219 public ServletResponse getServletResponse()
220 {
221 return _connection.getResponse();
222 }
223
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 }
232
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 }
241
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 }
250
251 } 164 }