|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.xenqtt.message.AbstractBlockingCommand<T>
public abstract class AbstractBlockingCommand<T>
Implementation of BlockingCommand
that provides a simple extension point for command implementations.
Constructor Summary | |
---|---|
AbstractBlockingCommand()
|
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 BlockingCommand.await() or BlockingCommand.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. |
protected abstract void |
doExecute(long now)
Extensions implement this method to execute the command. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractBlockingCommand()
Method Detail |
---|
public final T await() throws MqttInterruptedException
BlockingCommand
await
in interface BlockingCommand<T>
MqttInterruptedException
- Thrown when the SyncMqttClient
implementation is used and the calling thread is interrupted
.BlockingCommand.await()
public final T await(long timeout, TimeUnit unit) throws MqttInterruptedException, MqttTimeoutException
BlockingCommand
await
in interface BlockingCommand<T>
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
BlockingCommand.await()
.unit
- The time unit of the timeout argument
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.BlockingCommand.await(long, java.util.concurrent.TimeUnit)
public final void execute(long now)
BlockingCommand
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 BlockingCommand.setFailureCause(Throwable)
is called with the thrown exception and BlockingCommand.complete()
is invoked to complete the command. If
the command returns a result use BlockingCommand.setResult(Object)
to set it.
execute
in interface BlockingCommand<T>
now
- The time the command was executednet.sf.xenqtt.message.BlockingCommand#execute()
public void setResult(T result)
BlockingCommand
BlockingCommand.await()
and BlockingCommand.await(long, TimeUnit)
. This must be set before
BlockingCommand.complete()
is called. The last value set before BlockingCommand.complete()
is called is returned from BlockingCommand.await()
or
BlockingCommand.await(long, TimeUnit)
. This should only be called by the same thread that calls BlockingCommand.complete()
.
setResult
in interface BlockingCommand<T>
BlockingCommand.setResult(java.lang.Object)
public void setFailureCause(Throwable cause)
BlockingCommand
BlockingCommand.await()
or
BlockingCommand.await(long, TimeUnit)
after BlockingCommand.complete()
is called. This should only be called by the same thread that calls #execute()
.
setFailureCause
in interface BlockingCommand<T>
BlockingCommand.setFailureCause(java.lang.Throwable)
public void complete()
BlockingCommand
BlockingCommand.await()
or BlockingCommand.await(long, TimeUnit)
to return.This should only be called by the same thread
that calls #execute()
.
complete
in interface BlockingCommand<T>
BlockingCommand.complete()
public void cancel()
BlockingCommand
BlockingCommand.await()
or BlockingCommand.await(long, TimeUnit)
to throw an MqttCommandCancelledException
.This should only be
called by the same thread that calls #execute()
.
cancel
in interface BlockingCommand<T>
BlockingCommand.cancel()
protected abstract void doExecute(long now) throws Throwable
now
- The time the command is being executed
Exception
- Any exception thrown by the command. This will be set as the failure cause using setFailureCause(Throwable)
.
Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |