Mercurial Hosting > luan
comparison src/org/eclipse/jetty/continuation/Continuation.java @ 917:1fc8ee20cb18
remove doSuspend
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 09 Oct 2016 03:23:55 -0600 |
| parents | 3428c60d7cfc |
| children | a5af9ee7cf91 |
comparison
equal
deleted
inserted
replaced
| 916:4de7f6e9c453 | 917:1fc8ee20cb18 |
|---|---|
| 142 * @see ContinuationListener | 142 * @see ContinuationListener |
| 143 * | 143 * |
| 144 */ | 144 */ |
| 145 public interface Continuation | 145 public interface Continuation |
| 146 { | 146 { |
| 147 public final static String ATTRIBUTE = "org.eclipse.jetty.continuation"; | 147 public final static String ATTRIBUTE = "org.eclipse.jetty.continuation"; |
| 148 | 148 |
| 149 /* ------------------------------------------------------------ */ | 149 /* ------------------------------------------------------------ */ |
| 150 /** | 150 /** |
| 151 * Set the continuation timeout. | 151 * Set the continuation timeout. |
| 152 * | 152 * |
| 153 * @param timeoutMs | 153 * @param timeoutMs |
| 154 * The time in milliseconds to wait before expiring this | 154 * The time in milliseconds to wait before expiring this |
| 155 * continuation after a call to {@link #suspend()} or {@link #suspend(ServletResponse)}. | 155 * continuation after a call to {@link #suspend()} or {@link #suspend(ServletResponse)}. |
| 156 * A timeout of <=0 means the continuation will never expire. | 156 * A timeout of <=0 means the continuation will never expire. |
| 157 */ | 157 */ |
| 158 void setTimeout(long timeoutMs); | 158 void setTimeout(long timeoutMs); |
| 159 | 159 |
| 160 /* ------------------------------------------------------------ */ | 160 /* ------------------------------------------------------------ */ |
| 161 /** | 161 /** |
| 162 * Suspend the processing of the request and associated | 162 * Suspend the processing of the request and associated |
| 163 * {@link ServletResponse}. | 163 * {@link ServletResponse}. |
| 164 * | 164 * |
| 165 * <p> | 165 * <p> |
| 166 * After this method has been called, the lifecycle of the request will be | 166 * After this method has been called, the lifecycle of the request will be |
| 167 * extended beyond the return to the container from the | 167 * extended beyond the return to the container from the |
| 168 * {@link Servlet#service(ServletRequest, ServletResponse)} method and | 168 * {@link Servlet#service(ServletRequest, ServletResponse)} method and |
| 169 * {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)} | 169 * {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)} |
| 170 * calls. When a suspended request is returned to the container after | 170 * calls. When a suspended request is returned to the container after |
| 171 * a dispatch, then the container will not commit the associated response | 171 * a dispatch, then the container will not commit the associated response |
| 172 * (unless an exception other than {@link ContinuationThrowable} is thrown). | 172 * (unless an exception other than {@link ContinuationThrowable} is thrown). |
| 173 * </p> | 173 * </p> |
| 174 * | 174 * |
| 175 * <p> | 175 * <p> |
| 176 * When the thread calling the filter chain and/or servlet has returned to | 176 * When the thread calling the filter chain and/or servlet has returned to |
| 177 * the container with a suspended request, the thread is freed for other | 177 * the container with a suspended request, the thread is freed for other |
| 178 * tasks and the request is held until either: | 178 * tasks and the request is held until either: |
| 179 * <ul> | 179 * <ul> |
| 180 * <li>a call to {@link #resume()}.</li> | 180 * <li>a call to {@link #resume()}.</li> |
| 181 * <li>a call to {@link #complete()}.</li> | 181 * <li>a call to {@link #complete()}.</li> |
| 182 * <li>the timeout expires.</li> | 182 * <li>the timeout expires.</li> |
| 183 * </ul> | 183 * </ul> |
| 184 * <p> | 184 * <p> |
| 185 * Typically suspend with no arguments is uses when a call to {@link #resume()} | 185 * Typically suspend with no arguments is uses when a call to {@link #resume()} |
| 186 * is expected. If a call to {@link #complete()} is expected, then the | 186 * is expected. If a call to {@link #complete()} is expected, then the |
| 187 * {@link #suspend(ServletResponse)} method should be used instead of this method. | 187 * {@link #suspend(ServletResponse)} method should be used instead of this method. |
| 188 * </p> | 188 * </p> |
| 189 * | 189 * |
| 190 * @exception IllegalStateException | 190 * @exception IllegalStateException |
| 191 * If the request cannot be suspended | 191 * If the request cannot be suspended |
| 192 */ | 192 */ |
| 193 void suspend(); | 193 // void suspend(); |
| 194 | 194 |
| 195 | 195 |
| 196 /* ------------------------------------------------------------ */ | 196 /* ------------------------------------------------------------ */ |
| 197 /** | 197 /** |
| 198 * Suspend the processing of the request and associated | 198 * Suspend the processing of the request and associated |
| 199 * {@link ServletResponse}. | 199 * {@link ServletResponse}. |
| 200 * | 200 * |
| 201 * <p> | 201 * <p> |
| 202 * After this method has been called, the lifecycle of the request will be | 202 * After this method has been called, the lifecycle of the request will be |
| 203 * extended beyond the return to the container from the | 203 * extended beyond the return to the container from the |
| 204 * {@link Servlet#service(ServletRequest, ServletResponse)} method and | 204 * {@link Servlet#service(ServletRequest, ServletResponse)} method and |
| 205 * {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)} | 205 * {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)} |
| 206 * calls. When a suspended request is returned to the container after | 206 * calls. When a suspended request is returned to the container after |
| 207 * a dispatch, then the container will not commit the associated response | 207 * a dispatch, then the container will not commit the associated response |
| 208 * (unless an exception other than {@link ContinuationThrowable} is thrown). | 208 * (unless an exception other than {@link ContinuationThrowable} is thrown). |
| 209 * </p> | 209 * </p> |
| 210 * <p> | 210 * <p> |
| 211 * When the thread calling the filter chain and/or servlet has returned to | 211 * When the thread calling the filter chain and/or servlet has returned to |
| 212 * the container with a suspended request, the thread is freed for other | 212 * the container with a suspended request, the thread is freed for other |
| 213 * tasks and the request is held until either: | 213 * tasks and the request is held until either: |
| 214 * <ul> | 214 * <ul> |
| 215 * <li>a call to {@link #resume()}.</li> | 215 * <li>a call to {@link #resume()}.</li> |
| 216 * <li>a call to {@link #complete()}.</li> | 216 * <li>a call to {@link #complete()}.</li> |
| 217 * <li>the timeout expires.</li> | 217 * <li>the timeout expires.</li> |
| 218 * </ul> | 218 * </ul> |
| 219 * <p> | 219 * <p> |
| 220 * Typically suspend with a response argument is uses when a call to {@link #complete()} | 220 * Typically suspend with a response argument is uses when a call to {@link #complete()} |
| 221 * is expected. If a call to {@link #resume()} is expected, then the | 221 * is expected. If a call to {@link #resume()} is expected, then the |
| 222 * {@link #suspend()} method should be used instead of this method. | 222 * {@link #suspend()} method should be used instead of this method. |
| 223 * </p> | 223 * </p> |
| 224 * <p> | 224 * <p> |
| 225 * Filters that may wrap the response object should check {@link #isResponseWrapped()} | 225 * Filters that may wrap the response object should check {@link #isResponseWrapped()} |
| 226 * to decide if they should destroy/finish the wrapper. If {@link #isResponseWrapped()} | 226 * to decide if they should destroy/finish the wrapper. If {@link #isResponseWrapped()} |
| 227 * returns true, then the wrapped request has been passed to the asynchronous | 227 * returns true, then the wrapped request has been passed to the asynchronous |
| 228 * handler and the wrapper should not be destroyed/finished until after a call to | 228 * handler and the wrapper should not be destroyed/finished until after a call to |
| 229 * {@link #complete()} (potentially using a {@link ContinuationListener#onComplete(Continuation)} | 229 * {@link #complete()} (potentially using a {@link ContinuationListener#onComplete(Continuation)} |
| 230 * listener). | 230 * listener). |
| 231 * | 231 * |
| 232 * @param response The response to return via a call to {@link #getServletResponse()} | 232 * @param response The response to return via a call to {@link #getServletResponse()} |
| 233 * @exception IllegalStateException | 233 * @exception IllegalStateException |
| 234 * If the request cannot be suspended | 234 * If the request cannot be suspended |
| 235 */ | 235 */ |
| 236 void suspend(ServletResponse response); | 236 // void suspend(ServletResponse response); |
| 237 | 237 |
| 238 /* ------------------------------------------------------------ */ | 238 /* ------------------------------------------------------------ */ |
| 239 /** | 239 /** |
| 240 * Resume a suspended request. | 240 * Resume a suspended request. |
| 241 * | 241 * |
| 242 * <p> | 242 * <p> |
| 243 * This method can be called by any thread that has been passed a reference | 243 * This method can be called by any thread that has been passed a reference |
| 244 * to a continuation. When called the request is redispatched to the | 244 * to a continuation. When called the request is redispatched to the |
| 245 * normal filter chain and servlet processing with {@link #isInitial()} false. | 245 * normal filter chain and servlet processing with {@link #isInitial()} false. |
| 246 * </p> | 246 * </p> |
| 247 * <p> | 247 * <p> |
| 248 * If resume is called before a suspended request is returned to the | 248 * If resume is called before a suspended request is returned to the |
| 249 * container (ie the thread that called {@link #suspend()} is still | 249 * container (ie the thread that called {@link #suspend()} is still |
| 250 * within the filter chain and/or servlet service method), then the resume | 250 * within the filter chain and/or servlet service method), then the resume |
| 251 * does not take effect until the call to the filter chain and/or servlet | 251 * does not take effect until the call to the filter chain and/or servlet |
| 252 * returns to the container. In this case both {@link #isSuspended()} and | 252 * returns to the container. In this case both {@link #isSuspended()} and |
| 253 * {@link #isResumed()} return true. Multiple calls to resume are ignored. | 253 * {@link #isResumed()} return true. Multiple calls to resume are ignored. |
| 254 * </p> | 254 * </p> |
| 255 * <p> | 255 * <p> |
| 256 * Typically resume() is used after a call to {@link #suspend()} with | 256 * Typically resume() is used after a call to {@link #suspend()} with |
| 257 * no arguments. The dispatch after a resume call will use the original | 257 * no arguments. The dispatch after a resume call will use the original |
| 258 * request and response objects, even if {@link #suspend(ServletResponse)} | 258 * request and response objects, even if {@link #suspend(ServletResponse)} |
| 259 * had been passed a wrapped response. | 259 * had been passed a wrapped response. |
| 260 * </p> | 260 * </p> |
| 261 * | 261 * |
| 262 * @see #suspend() | 262 * @see #suspend() |
| 263 * @exception IllegalStateException if the request is not suspended. | 263 * @exception IllegalStateException if the request is not suspended. |
| 264 * | 264 * |
| 265 */ | 265 */ |
| 266 void resume(); | 266 void resume(); |
| 267 | 267 |
| 268 /* ------------------------------------------------------------ */ | 268 /* ------------------------------------------------------------ */ |
| 269 /** | 269 /** |
| 270 * Complete a suspended request. | 270 * Complete a suspended request. |
| 271 * | 271 * |
| 272 * <p> | 272 * <p> |
| 273 * This method can be called by any thread that has been passed a reference | 273 * This method can be called by any thread that has been passed a reference |
| 274 * to a suspended request. When a request is completed, the associated | 274 * to a suspended request. When a request is completed, the associated |
| 275 * response object committed and flushed. The request is not redispatched. | 275 * response object committed and flushed. The request is not redispatched. |
| 276 * </p> | 276 * </p> |
| 277 * | 277 * |
| 278 * <p> | 278 * <p> |
| 279 * If complete is called before a suspended request is returned to the | 279 * If complete is called before a suspended request is returned to the |
| 280 * container (ie the thread that called {@link #suspend()} is still | 280 * container (ie the thread that called {@link #suspend()} is still |
| 281 * within the filter chain and/or servlet service method), then the complete | 281 * within the filter chain and/or servlet service method), then the complete |
| 282 * does not take effect until the call to the filter chain and/or servlet | 282 * does not take effect until the call to the filter chain and/or servlet |
| 283 * returns to the container. In this case both {@link #isSuspended()} and | 283 * returns to the container. In this case both {@link #isSuspended()} and |
| 284 * {@link #isResumed()} return true. | 284 * {@link #isResumed()} return true. |
| 285 * </p> | 285 * </p> |
| 286 * | 286 * |
| 287 * <p> | 287 * <p> |
| 288 * Typically resume() is used after a call to {@link #suspend(ServletResponse)} with | 288 * Typically resume() is used after a call to {@link #suspend(ServletResponse)} with |
| 289 * a possibly wrapped response. The async handler should use the response | 289 * a possibly wrapped response. The async handler should use the response |
| 290 * provided by {@link #getServletResponse()} to write the response before | 290 * provided by {@link #getServletResponse()} to write the response before |
| 291 * calling {@link #complete()}. If the request was suspended with a | 291 * calling {@link #complete()}. If the request was suspended with a |
| 292 * call to {@link #suspend()} then no response object will be available via | 292 * call to {@link #suspend()} then no response object will be available via |
| 293 * {@link #getServletResponse()}. | 293 * {@link #getServletResponse()}. |
| 294 * </p> | 294 * </p> |
| 295 * | 295 * |
| 296 * <p> | 296 * <p> |
| 297 * Once complete has been called and any thread calling the filter chain | 297 * Once complete has been called and any thread calling the filter chain |
| 298 * and/or servlet chain has returned to the container, the request lifecycle | 298 * and/or servlet chain has returned to the container, the request lifecycle |
| 299 * is complete. The container is able to recycle request objects, so it is | 299 * is complete. The container is able to recycle request objects, so it is |
| 300 * not valid hold a request or continuation reference after the end of the | 300 * not valid hold a request or continuation reference after the end of the |
| 301 * life cycle. | 301 * life cycle. |
| 302 * | 302 * |
| 303 * @see #suspend() | 303 * @see #suspend() |
| 304 * @exception IllegalStateException | 304 * @exception IllegalStateException |
| 305 * if the request is not suspended. | 305 * if the request is not suspended. |
| 306 * | 306 * |
| 307 */ | 307 */ |
| 308 void complete(); | 308 void complete(); |
| 309 | 309 |
| 310 /* ------------------------------------------------------------ */ | 310 /* ------------------------------------------------------------ */ |
| 311 /** | 311 /** |
| 312 * @return true after {@link #suspend()} has been called and before the | 312 * @return true after {@link #suspend()} has been called and before the |
| 313 * request has been redispatched due to being resumed, completed or | 313 * request has been redispatched due to being resumed, completed or |
| 314 * timed out. | 314 * timed out. |
| 315 */ | 315 */ |
| 316 boolean isSuspended(); | 316 boolean isSuspended(); |
| 317 | 317 |
| 318 /* ------------------------------------------------------------ */ | 318 /* ------------------------------------------------------------ */ |
| 319 /** | 319 /** |
| 320 * @return true if the request has been redispatched by a call to | 320 * @return true if the request has been redispatched by a call to |
| 321 * {@link #resume()}. Returns false after any subsequent call to | 321 * {@link #resume()}. Returns false after any subsequent call to |
| 322 * suspend | 322 * suspend |
| 323 */ | 323 */ |
| 324 boolean isResumed(); | 324 boolean isResumed(); |
| 325 | 325 |
| 326 /* ------------------------------------------------------------ */ | 326 /* ------------------------------------------------------------ */ |
| 327 /** | 327 /** |
| 328 * @return true after a request has been redispatched as the result of a | 328 * @return true after a request has been redispatched as the result of a |
| 329 * timeout. Returns false after any subsequent call to suspend. | 329 * timeout. Returns false after any subsequent call to suspend. |
| 330 */ | 330 */ |
| 331 boolean isExpired(); | 331 boolean isExpired(); |
| 332 | 332 |
| 333 /* ------------------------------------------------------------ */ | 333 /* ------------------------------------------------------------ */ |
| 334 /** | 334 /** |
| 335 * @return true while the request is within the initial dispatch to the | 335 * @return true while the request is within the initial dispatch to the |
| 336 * filter chain and/or servlet. Will return false once the calling | 336 * filter chain and/or servlet. Will return false once the calling |
| 337 * thread has returned to the container after suspend has been | 337 * thread has returned to the container after suspend has been |
| 338 * called and during any subsequent redispatch. | 338 * called and during any subsequent redispatch. |
| 339 */ | 339 */ |
| 340 boolean isInitial(); | 340 boolean isInitial(); |
| 341 | 341 |
| 342 /* ------------------------------------------------------------ */ | 342 /* ------------------------------------------------------------ */ |
| 343 /** | 343 /** |
| 344 * Is the suspended response wrapped. | 344 * Is the suspended response wrapped. |
| 345 * <p> | 345 * <p> |
| 346 * Filters that wrap the response object should check this method to | 346 * Filters that wrap the response object should check this method to |
| 347 * determine if they should destroy/finish the wrapped response. If | 347 * determine if they should destroy/finish the wrapped response. If |
| 348 * the request was suspended with a call to {@link #suspend(ServletResponse)} | 348 * the request was suspended with a call to {@link #suspend(ServletResponse)} |
| 349 * that passed the wrapped response, then the filter should register | 349 * that passed the wrapped response, then the filter should register |
| 350 * a {@link ContinuationListener} to destroy/finish the wrapped response | 350 * a {@link ContinuationListener} to destroy/finish the wrapped response |
| 351 * during a call to {@link ContinuationListener#onComplete(Continuation)}. | 351 * during a call to {@link ContinuationListener#onComplete(Continuation)}. |
| 352 * @return True if {@link #suspend(ServletResponse)} has been passed a | 352 * @return True if {@link #suspend(ServletResponse)} has been passed a |
| 353 * {@link ServletResponseWrapper} instance. | 353 * {@link ServletResponseWrapper} instance. |
| 354 */ | 354 */ |
| 355 boolean isResponseWrapped(); | 355 boolean isResponseWrapped(); |
| 356 | 356 |
| 357 | 357 |
| 358 /* ------------------------------------------------------------ */ | 358 /* ------------------------------------------------------------ */ |
| 359 /** | 359 /** |
| 360 * Get the suspended response. | 360 * Get the suspended response. |
| 361 * @return the {@link ServletResponse} passed to {@link #suspend(ServletResponse)}. | 361 * @return the {@link ServletResponse} passed to {@link #suspend(ServletResponse)}. |
| 362 */ | 362 */ |
| 363 ServletResponse getServletResponse(); | 363 ServletResponse getServletResponse(); |
| 364 | 364 |
| 365 /* ------------------------------------------------------------ */ | 365 /* ------------------------------------------------------------ */ |
| 366 /** | 366 /** |
| 367 * Add a ContinuationListener. | 367 * Add a ContinuationListener. |
| 368 * | 368 * |
| 369 * @param listener | 369 * @param listener |
| 370 */ | 370 */ |
| 371 void addContinuationListener(ContinuationListener listener); | 371 void addContinuationListener(ContinuationListener listener); |
| 372 | 372 |
| 373 /* ------------------------------------------------------------ */ | 373 /* ------------------------------------------------------------ */ |
| 374 /** Set a request attribute. | 374 /** Set a request attribute. |
| 375 * This method is a convenience method to call the {@link ServletRequest#setAttribute(String, Object)} | 375 * This method is a convenience method to call the {@link ServletRequest#setAttribute(String, Object)} |
| 376 * method on the associated request object. | 376 * method on the associated request object. |
| 377 * This is a thread safe call and may be called by any thread. | 377 * This is a thread safe call and may be called by any thread. |
| 378 * @param name the attribute name | 378 * @param name the attribute name |
| 379 * @param attribute the attribute value | 379 * @param attribute the attribute value |
| 380 */ | 380 */ |
| 381 public void setAttribute(String name, Object attribute); | 381 public void setAttribute(String name, Object attribute); |
| 382 | 382 |
| 383 /* ------------------------------------------------------------ */ | 383 /* ------------------------------------------------------------ */ |
| 384 /** Get a request attribute. | 384 /** Get a request attribute. |
| 385 * This method is a convenience method to call the {@link ServletRequest#getAttribute(String)} | 385 * This method is a convenience method to call the {@link ServletRequest#getAttribute(String)} |
| 386 * method on the associated request object. | 386 * method on the associated request object. |
| 387 * This is a thread safe call and may be called by any thread. | 387 * This is a thread safe call and may be called by any thread. |
| 388 * @param name the attribute name | 388 * @param name the attribute name |
| 389 * @return the attribute value | 389 * @return the attribute value |
| 390 */ | 390 */ |
| 391 public Object getAttribute(String name); | 391 public Object getAttribute(String name); |
| 392 | 392 |
| 393 /* ------------------------------------------------------------ */ | 393 /* ------------------------------------------------------------ */ |
| 394 /** Remove a request attribute. | 394 /** Remove a request attribute. |
| 395 * This method is a convenience method to call the {@link ServletRequest#removeAttribute(String)} | 395 * This method is a convenience method to call the {@link ServletRequest#removeAttribute(String)} |
| 396 * method on the associated request object. | 396 * method on the associated request object. |
| 397 * This is a thread safe call and may be called by any thread. | 397 * This is a thread safe call and may be called by any thread. |
| 398 * @param name the attribute name | 398 * @param name the attribute name |
| 399 */ | 399 */ |
| 400 public void removeAttribute(String name); | 400 public void removeAttribute(String name); |
| 401 | 401 |
| 402 /* ------------------------------------------------------------ */ | 402 /* ------------------------------------------------------------ */ |
| 403 /** | 403 /** |
| 404 * Undispatch the request. | 404 * Undispatch the request. |
| 405 * <p> | 405 * <p> |
| 406 * This method can be called on a suspended continuation in order | 406 * This method can be called on a suspended continuation in order |
| 407 * to exit the dispatch to the filter/servlet by throwing a {@link ContinuationThrowable} | 407 * to exit the dispatch to the filter/servlet by throwing a {@link ContinuationThrowable} |
| 408 * which is caught either by the container or the {@link ContinuationFilter}. | 408 * which is caught either by the container or the {@link ContinuationFilter}. |
| 409 * This is an alternative to simply returning from the dispatch in the case | 409 * This is an alternative to simply returning from the dispatch in the case |
| 410 * where filters in the filter chain may not be prepared to handle a suspended | 410 * where filters in the filter chain may not be prepared to handle a suspended |
| 411 * request. | 411 * request. |
| 412 * </p> | 412 * </p> |
| 413 * This method should only be used as a last resort and a normal return is a prefereable | 413 * This method should only be used as a last resort and a normal return is a prefereable |
| 414 * solution if filters can be updated to handle that case. | 414 * solution if filters can be updated to handle that case. |
| 415 * | 415 * |
| 416 * @throws ContinuationThrowable thrown if the request is suspended. The instance of the | 416 * @throws ContinuationThrowable thrown if the request is suspended. The instance of the |
| 417 * exception may be reused on subsequent calls, so the stack frame may not be accurate. | 417 * exception may be reused on subsequent calls, so the stack frame may not be accurate. |
| 418 */ | 418 */ |
| 419 public void undispatch() throws ContinuationThrowable; | 419 public void undispatch() throws ContinuationThrowable; |
| 420 } | 420 } |
