Asynchronous version of
Provider .
Applications that use the JAX-WS RI can implement this interface instead of
Provider to implement asynchronous web services (AWS.) AWS enables
applications to perform operations with long latency without blocking a thread,
and thus particularly suitable for highly scalable service implementation,
at the expesnce of implementation complexity.
Programming Model
Whenever a new reuqest arrives, the JAX-WS RI invokes the
AsyncProvider.invoke method
to notify the application. Normally, the application then schedules an execution
of this request, and exit from this method immediately (the point of AWS is not
to use this calling thread for request processing.)
Unlike the synchronous version, which requires the response to be given as the return value,
with AWS the JAX-WS RI will keep the connection with client open, until the application
eventually notifies the JAX-WS RI via
AsyncProviderCallback . When that
happens that causes the JAX-WS RI to send back a response to the client.
The following code shows a very simple AWS example:
@WebService
class MyAsyncEchoService implements AsyncProvider<Source> {
private static final
Executor exec = ...;
public void invoke( final Source request, final AsyncProviderCallback<Source> callback, final WebServiceContext context) {
exec.execute(new
Runnable () {
public void run() {
Thread.sleep(1000); // kill time.
callback.send(request); // just echo back
}
});
}
}
Please also check the
Provider and its programming model for general
provider programming model.
WebServiceContext
In synchronous web services, the injected
WebServiceContext instance uses
the calling
Thread to determine which request it should return information about.
This no longer works with AWS, as you may need to call
WebServiceContext much later, possibly from entirely different thread.
For this reason,
AsyncProvider passes in
WebServiceContext as
a parameter. This object remains usable until you invoke
AsyncProviderCallback ,
and it can be invoked from any thread, even concurrently. AWS must not use the injected
WebServiceContext , as its behavior is undefined.
See Also: Provider author: Jitendra Kotamraju author: Kohsuke Kawaguchi since: 2.1 |