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()
           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,
               MqttException,
               RuntimeException
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 SynchronousMqttClient implementation is used and the calling thread is interrupted.
MqttException - Any checked exception thrown by the command will be wrapped in an MqttException
RuntimeException - Of course, any RuntimeException may be thrown

await

T await(long timeout,
        TimeUnit unit)
        throws MqttCommandCancelledException,
               MqttInterruptedException,
               MqttTimeoutException,
               MqttException,
               RuntimeException
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 SynchronousMqttClient implementation is used and the calling thread is interrupted.
MqttTimeoutException - Thrown when the SynchronousMqttClient implementation is used and this method has blocked for approximately the configured timeout.
MqttException - Any checked exception thrown by the command will be wrapped in an MqttException
RuntimeException - Of course, any RuntimeException may be thrown

execute

void execute()

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.


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 thrown by await() or await(long, TimeUnit) after complete() is called. If cause is a checked exception it will be wrapped in MqttException before being thrown by await() or await(long, TimeUnit).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.