Class RequestDispatch

java.lang.Object
com.yahoo.jdisc.handler.RequestDispatch
All Implemented Interfaces:
ResponseHandler, Future<Response>
Direct Known Subclasses:
CallableRequestDispatch

public abstract class RequestDispatch extends Object implements Future<Response>, ResponseHandler

This class provides a convenient way of safely dispatching a Request. Using this class you do not have to worry about the exception safety surrounding the SharedResource logic. The internal mechanics of this class will ensure that anything that goes wrong during dispatch is safely handled according to jDISC contracts.

It also provides a default implementation of the ResponseHandler interface that returns a NullContent. If you want to return a different ContentChannel, you need to override handleResponse(Response).

The following is a simple example on how to use this class:

 public void handleRequest(final Request parent, final ResponseHandler handler) {
     new RequestDispatch() {
         @Override
         protected Request newRequest() {
             return new Request(parent, URI.create("http://remotehost/"));
         }
         @Override
         protected Iterable<ByteBuffer> requestContent() {
             return Collections.singleton(ByteBuffer.wrap(new byte[] { 6, 9 }));
         }
         @Override
         public ContentChannel handleResponse(Response response) {
             return handler.handleResponse(response);
         }
     }.dispatch();
 }
 
Author:
Simon Thoresen Hult