JBoss Remoting 3.0.0.Beta2

org.jboss.remoting
Interface RequestContext<O>

Type Parameters:
O - the reply type
All Superinterfaces:
Executor

public interface RequestContext<O>
extends Executor

The context of a single request. A request listener is obligated to call exactly one of the three send methods specified in this interface.


Method Summary
 void addCancelHandler(RequestCancelHandler<O> handler)
          Add a notifier to be called if a cancel request is received.
 void execute(Runnable command)
          Execute a task in the context of this request.
 ClientContext getContext()
          Get the context that the request came in on.
 boolean isCancelled()
          Determine whether the current request was cancelled.
 void sendCancelled()
          Send a cancellation message back to the client.
 void sendFailure(String msg, Throwable cause)
          Send a failure message back to the caller.
 void sendReply(O reply)
          Send a reply back to the caller.
 

Method Detail

getContext

ClientContext getContext()
Get the context that the request came in on.

Returns:
the context

isCancelled

boolean isCancelled()
Determine whether the current request was cancelled.

Returns:
true if the request was cancelled

sendReply

void sendReply(O reply)
               throws IOException,
                      IllegalStateException
Send a reply back to the caller. If transmission fails, an IOException is thrown from this method and a reply is sent back to the client which will trigger a RemoteReplyException to be thrown. If the client connection is interrupted in such a way that the reply cannot reach the client, the client will (eventually) receive an IndeterminateOutcomeException.

Parameters:
reply - the reply to send
Throws:
IOException - if the transmission failed
IllegalStateException - if this or another of the sendXXX() methods was already invoked for this request

sendFailure

void sendFailure(String msg,
                 Throwable cause)
                 throws IOException,
                        IllegalStateException
Send a failure message back to the caller. If the transmission succeeds, the client will receive a RemoteExecutionException with the message initialized to msg and the cause initialized to cause. If the transmission fails, an IOException is thrown from this method and the client will (eventually) receive an IndeterminateOutcomeException.

Parameters:
msg - a message describing the failure, if any (can be null)
cause - the failure cause, if any (can be null)
Throws:
IOException - if the transmission failed
IllegalStateException - if this or another of the sendXXX() methods was already invoked for this request

sendCancelled

void sendCancelled()
                   throws IOException,
                          IllegalStateException
Send a cancellation message back to the client. If the transmission succeeds, the client result will be an acknowledgement of cancellation. If the transmission fails, an IOException is thrown from this method and the client will (eventually) receive an IndeterminateOutcomeException.

Throws:
IOException - if the message could not be sent (the client could not be notified about the cancellation)
IllegalStateException - if this or another of the sendXXX() methods was already invoked for this request

addCancelHandler

void addCancelHandler(RequestCancelHandler<O> handler)
Add a notifier to be called if a cancel request is received. The notifier may be called from the current thread or a different thread. If the request has already been cancelled, the notifier will be called immediately.

Parameters:
handler - the cancel handler

execute

void execute(Runnable command)
             throws RejectedExecutionException
Execute a task in the context of this request. This method can be used to continue execution of a request. Any tasks submitted to this executor will be interruptible in the event of cancellation.

Specified by:
execute in interface Executor
Parameters:
command - the task to execute
Throws:
RejectedExecutionException

JBoss Remoting 3.0.0.Beta2

Copyright © 2008 JBoss, a division of Red Hat, Inc.