net.sf.xenqtt.message
Interface BlockingCommand<T>

Type Parameters:
T - The type returned by await() and await(long, TimeUnit). Use Void if there is no return value.
All Known Implementing Classes:
AbstractBlockingCommand

public interface BlockingCommand<T>

Command that allows the calling thread to block until the command is completed.


Method Summary
 T await()
          Waits indefinitely for the command to complete.
 T await(long timeout, TimeUnit unit)
          Waits for the specified amount of time for the command to complete
 void cancel()
          Cancels the command causes await() or await(long, TimeUnit) to throw an MqttCommandCancelledException.This should only be called by the same thread that calls #execute().
 void complete()
          Called when the command is complete.
 void execute(long now)
           Executes the command.
 void setFailureCause(Throwable cause)
          Sets the cause if the command fails.
 void setResult(T result)
          Sets the result of this command.
 

Method Detail

await

T await()
        throws MqttCommandCancelledException,
               MqttInterruptedException,
               MqttInvocationException,
               MqttInvocationError
Waits indefinitely for the command to complete.

Returns:
The result of the command, if any.
Throws:
MqttCommandCancelledException - Thrown if the command was cancelled
MqttInterruptedException - Thrown when the SyncMqttClient implementation is used and the calling thread is interrupted.
MqttInvocationException - Any Exception thrown by a command will be wrapped in an MqttInvocationException
MqttInvocationError - Any Error thrown by a command will be wrapped in an MqttInvocationError

await

T await(long timeout,
        TimeUnit unit)
        throws MqttCommandCancelledException,
               MqttInterruptedException,
               MqttTimeoutException,
               MqttInvocationException,
               MqttInvocationError
Waits for the specified amount of time for the command to complete

Parameters:
timeout - The maximum time to wait. If this is Long.MAX_VALUE is used then the unit arg is ignored and this is the same as invoking await().
unit - The time unit of the timeout argument
Returns:
The result of the command, if any.
Throws:
MqttCommandCancelledException - Thrown if the command was cancelled
MqttInterruptedException - Thrown when the SyncMqttClient implementation is used and the calling thread is interrupted.
MqttTimeoutException - Thrown when the SyncMqttClient implementation is used and this method has blocked for approximately the configured timeout.
MqttInvocationException - Any Exception thrown by a command will be wrapped in an MqttInvocationException
MqttInvocationError - Any Error thrown by a command will be wrapped in an MqttInvocationError

execute

void execute(long now)

Executes the command. This is called by the thread responsible for processing the command, not the thread creating or waiting on the command. If an exception occurs setFailureCause(Throwable) is called with the thrown exception and complete() is invoked to complete the command. If the command returns a result use setResult(Object) to set it.

Parameters:
now - The time the command was executed

setResult

void setResult(T result)
Sets the result of this command. This is the value returned by await() and await(long, TimeUnit). This must be set before complete() is called. The last value set before complete() is called is returned from await() or await(long, TimeUnit). This should only be called by the same thread that calls complete().


setFailureCause

void setFailureCause(Throwable cause)
Sets the cause if the command fails. Null to clear any existing cause. If this is non-null then it is wrapped and re-thrown by await() or await(long, TimeUnit) after complete() is called. This should only be called by the same thread that calls #execute().


complete

void complete()
Called when the command is complete. Causes await() or await(long, TimeUnit) to return.This should only be called by the same thread that calls #execute().


cancel

void cancel()
Cancels the command causes await() or await(long, TimeUnit) to throw an MqttCommandCancelledException.This should only be called by the same thread that calls #execute().



Copyright © 2013. All Rights Reserved.