|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.paho.client.mqttv3.MqttToken
public class MqttToken
Provides a mechanism for tracking the completion of an asynchronous action.
A token that implements the ImqttToken interface is returned from all non-blocking method with the exception of publish.
IMqttToken| Field Summary | |
|---|---|
Token |
internalTok
A reference to the the class that provides most of the implementation of the MqttToken. |
| Constructor Summary | |
|---|---|
MqttToken()
|
|
MqttToken(String logContext)
|
|
| Method Summary | |
|---|---|
IMqttActionListener |
getActionCallback()
Return the async listener for this token. |
IMqttAsyncClient |
getClient()
Returns the MQTT client that is responsible for processing the asynchronous action |
MqttException |
getException()
Returns an exception providing more detail if an operation failed. |
int |
getMessageId()
Returns the message ID of the message that is associated with the token. |
String[] |
getTopics()
Returns the topic string(s) for the action being tracked by this token. |
Object |
getUserContext()
Retrieve the context associated with an action. |
boolean |
isComplete()
Returns whether or not the action has finished. |
void |
setActionCallback(IMqttActionListener listener)
Register a listener to be notified when an action completes. |
void |
setUserContext(Object userContext)
Store some context associated with an action. |
void |
waitForCompletion()
Blocks the current thread until the action this token is associated with has completed. |
void |
waitForCompletion(long timeout)
Blocks the current thread until the action this token is associated with has completed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public Token internalTok
| Constructor Detail |
|---|
public MqttToken()
public MqttToken(String logContext)
| Method Detail |
|---|
public MqttException getException()
IMqttTokenWhile an action in in progress and when an action completes successfully null will be returned. Certain errors like timeout or shutting down will not set the exception as the action has not failed or completed at that time
getException in interface IMqttTokenpublic boolean isComplete()
IMqttTokenTrue will be returned both in the case where the action finished successfully
and in the case where it failed. If the action failed IMqttToken.getException() will
be non null.
isComplete in interface IMqttTokenpublic void setActionCallback(IMqttActionListener listener)
IMqttTokenOnce a listener is registered it will be invoked when the action the token is associated with either succeeds or fails.
setActionCallback in interface IMqttTokenlistener - to be invoked once the action completespublic IMqttActionListener getActionCallback()
IMqttToken
getActionCallback in interface IMqttToken
public void waitForCompletion()
throws MqttException
IMqttToken
waitForCompletion in interface IMqttTokenMqttException - if there was a problem with the action associated with the token.IMqttToken.waitForCompletion(long)
public void waitForCompletion(long timeout)
throws MqttException
IMqttTokenThe timeout specifies the maximum time it will block for. If the action completes before the timeout then control returns immediately, if not it will block until the timeout expires.
If the action being tracked fails or the timeout expires an exception will be thrown. In the event of a timeout the action may complete after timeout.
waitForCompletion in interface IMqttTokentimeout - the maximum amount of time to wait for, in milliseconds.
MqttException - if there was a problem with the action associated with the token.public IMqttAsyncClient getClient()
IMqttToken
getClient in interface IMqttTokenpublic String[] getTopics()
IMqttToken
getTopics in interface IMqttTokenpublic Object getUserContext()
IMqttTokenAllows the ActionListener associated with an action to retrieve any context that was associated with the action when the action was invoked. If not context was provided null is returned.
getUserContext in interface IMqttTokenpublic void setUserContext(Object userContext)
IMqttTokenAllows the caller of an action to store some context that can be accessed from within the ActionListener associated with the action. This can be useful when the same ActionListener is associated with multiple actions
setUserContext in interface IMqttTokenuserContext - to associate with an actionpublic int getMessageId()
IMqttToken
getMessageId in interface IMqttToken
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||