Annotation Type Suspended
-
@Target(PARAMETER) @Retention(RUNTIME) @Documented public @interface Suspended
Inject a suspendedAsyncResponseinto a parameter of an invoked JAX-RSresource or sub-resource method. The injectedAsyncResponseinstance is bound to the processing of the active request and can be used to resume the request processing when a response is available.By default there is
no suspend timeout setand the asynchronous response is suspended indefinitely. The suspend timeout as well as a customtimeout handlercan be specified programmatically using theAsyncResponse.setTimeout(long, TimeUnit)andAsyncResponse.setTimeoutHandler(TimeoutHandler)methods. For example:@Stateless @Path("/") public class MyEjbResource { … @GET @Asynchronous public void longRunningOperation(@Suspended AsyncResponse ar) { ar.setTimeoutHandler(customHandler); ar.setTimeout(10, TimeUnit.SECONDS); final String result = executeLongRunningOperation(); ar.resume(result); } private String executeLongRunningOperation() { … } }A resource or sub-resource method that injects a suspended instance of an
AsyncResponseusing the@Suspendedannotation is expected be declared to returnvoidtype. Methods that inject asynchronous response instance using the@Suspendedannotation and declare a return type other thanvoidMUST be detected by the JAX-RS runtime and a warning message MUST be logged. Any response value returned from such resource or sub-resource method MUST be ignored by the framework:@Path("/messages/next") public class MessagingResource { … @GET public String readMessage(@Suspended AsyncResponse ar) { suspended.put(ar); return "This response will be ignored."; } … }- Since:
- 2.0
- Author:
- Marek Potociar