Class AwsIotCompletion
- java.lang.Object
-
- com.amazonaws.services.iot.client.AWSIotMessage
-
- com.amazonaws.services.iot.client.core.AwsIotCompletion
-
- All Implemented Interfaces:
AwsIotMessageCallback
- Direct Known Subclasses:
AwsIotDeviceCommand
public class AwsIotCompletion extends AWSIotMessage
This is a helper class that can be used to manage the request execution and return either synchronously or asynchronously the result, e.g. success, failure, or timeout. It's used by most of the APIs to implement blocking and non-blocking calls with timeout support.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanhasFailureIndicates whether the request has completed with failure.protected booleanhasSuccessIndicates whether the request has completed successfully.protected booleanhasTimeoutIndicates whether the request has timed out.protected booleanisAsyncwhether the request is asynchronous or not.protected AWSIotMessagerequestThe request containing the callback functions.protected longtimeoutThe timeout associated with the request.protected Future<?>timeoutTaskThe future object of the timeout task.-
Fields inherited from class com.amazonaws.services.iot.client.AWSIotMessage
errorCode, errorMessage, payload, qos, topic
-
-
Constructor Summary
Constructors Constructor Description AwsIotCompletion(long timeout, boolean isAsync)Instantiates a new completion object either synchronous or asynchronous request based on theisAsyncargument.AwsIotCompletion(AWSIotMessage req, long timeout, boolean isAsync)Instantiates a new completion object either synchronous or asynchronous request based on theisAsyncargument.AwsIotCompletion(String topic, AWSIotQos qos, byte[] payload, long timeout)Instantiates a new completion object with a synchronous request.AwsIotCompletion(String topic, AWSIotQos qos, long timeout)Instantiates a new completion object with a synchronous request.AwsIotCompletion(String topic, AWSIotQos qos, String payload, long timeout)Instantiates a new completion object with a synchronous request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidget(AbstractAwsIotClient client)The user of the completion object is expected to call this function to either block until the request is completed or timed out in the case of synchronous calls, or to schedule a timeout handler in the case of asynchronous calls.voidonFailure()Callback function to be invoked a non-block API has completed unsuccessfully.voidonSuccess()Callback function to be invoked a non-block API has completed successfully.voidonTimeout()Callback function to be invoked a non-block API has timed out.-
Methods inherited from class com.amazonaws.services.iot.client.AWSIotMessage
getErrorCode, getErrorMessage, getPayload, getQos, getStringPayload, getTopic, setErrorCode, setErrorMessage, setPayload, setQos, setStringPayload, setTopic
-
-
-
-
Field Detail
-
request
protected final AWSIotMessage request
The request containing the callback functions.
-
timeout
protected final long timeout
The timeout associated with the request.
-
isAsync
protected final boolean isAsync
whether the request is asynchronous or not.
-
timeoutTask
protected Future<?> timeoutTask
The future object of the timeout task.
-
hasSuccess
protected boolean hasSuccess
Indicates whether the request has completed successfully.
-
hasFailure
protected boolean hasFailure
Indicates whether the request has completed with failure.
-
hasTimeout
protected boolean hasTimeout
Indicates whether the request has timed out.
-
-
Constructor Detail
-
AwsIotCompletion
public AwsIotCompletion(String topic, AWSIotQos qos, long timeout)
Instantiates a new completion object with a synchronous request.- Parameters:
topic- the topic of the requestqos- the QoS of the requesttimeout- the timeout in milliseconds for the request. If timeout is 0 or less, the request will never be timed out.
-
AwsIotCompletion
public AwsIotCompletion(String topic, AWSIotQos qos, String payload, long timeout)
Instantiates a new completion object with a synchronous request.- Parameters:
topic- the topic of the requestqos- the QoS of the requestpayload- the string payload of the requesttimeout- the timeout in milliseconds for the request. If timeout is 0 or less, the request will never be timed out.
-
AwsIotCompletion
public AwsIotCompletion(String topic, AWSIotQos qos, byte[] payload, long timeout)
Instantiates a new completion object with a synchronous request.- Parameters:
topic- the topic of the requestqos- the QoS of the requestpayload- the byte array payload of the requesttimeout- the timeout in milliseconds for the request. If timeout is 0 or less, the request will never be timed out.
-
AwsIotCompletion
public AwsIotCompletion(long timeout, boolean isAsync)Instantiates a new completion object either synchronous or asynchronous request based on theisAsyncargument.- Parameters:
timeout- the timeout in milliseconds for the request. If timeout is 0 or less, the request will never be timed out.isAsync- whether or not the request is asynchronous
-
AwsIotCompletion
public AwsIotCompletion(AWSIotMessage req, long timeout, boolean isAsync)
Instantiates a new completion object either synchronous or asynchronous request based on theisAsyncargument. Callback functions are provided through thereqargument.- Parameters:
req- the request containing request topic, QoS, payload, and callback functions for asynchronous requests.timeout- the timeout in milliseconds for the request. If timeout is 0 or less, the request will never be timed out.isAsync- whether or not the request is asynchronous
-
-
Method Detail
-
get
public void get(AbstractAwsIotClient client) throws AWSIotException, AWSIotTimeoutException
The user of the completion object is expected to call this function to either block until the request is completed or timed out in the case of synchronous calls, or to schedule a timeout handler in the case of asynchronous calls.- Parameters:
client- the client object that provides the execution thread pool for the timeout handler.- Throws:
AWSIotException- For synchronous calls, this exception may be thrown if the request has failed.AWSIotTimeoutException- For synchronous calls, this exception may be thrown if the request has timed out.
-
onSuccess
public void onSuccess()
Description copied from class:AWSIotMessageCallback function to be invoked a non-block API has completed successfully.- Specified by:
onSuccessin interfaceAwsIotMessageCallback- Overrides:
onSuccessin classAWSIotMessage
-
onFailure
public void onFailure()
Description copied from class:AWSIotMessageCallback function to be invoked a non-block API has completed unsuccessfully.- Specified by:
onFailurein interfaceAwsIotMessageCallback- Overrides:
onFailurein classAWSIotMessage
-
onTimeout
public void onTimeout()
Description copied from class:AWSIotMessageCallback function to be invoked a non-block API has timed out.- Specified by:
onTimeoutin interfaceAwsIotMessageCallback- Overrides:
onTimeoutin classAWSIotMessage
-
-