public class AwsIotClient
extends java.lang.Object
| Constructor and Description |
|---|
AwsIotClient(AwsIotClientOptions options)
Constructor client.
|
AwsIotClient(AwsIotClientOptions options,
AwsIotConnectionListener connectionCallback)
Constructor client.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this client.
|
void |
connect()
Connect to AWS IoT service using the client options.
|
protected void |
connectionLost(java.lang.Throwable cause)
Dispatch connection lost event if an
AwsIotConnectionListener was registered. |
void |
deleteShadow()
Delete the classic shadow of thing with QOS 0.
|
void |
deleteShadow(int qos)
Delete the classic shadow of thing.
|
void |
deleteShadow(java.lang.String shadowName)
Delete the named shadow of thing with QOS 0.
|
void |
deleteShadow(java.lang.String shadowName,
int qos)
Delete the named shadow of thing.
|
void |
disconnect()
Disconnect this client from the underlying communication layer.
|
protected void |
dispatch(AwsIotMessage message)
dispatch message to corresponding subscriber if any otherwise log a warning if warning logs are activated
|
AwsIotClientOptions |
getClientOptions()
Gets the client options.
|
void |
getShadow()
Gets shadow with default QOS 0.
|
void |
getShadow(int qos)
Gets shadow.
|
void |
getShadow(java.lang.String shadowName)
Gets the named shadow with default QOS 0.
|
void |
getShadow(java.lang.String shadowName,
int qos)
Gets the named shadow.
|
boolean |
isConnected()
Returns the state of the connection.
|
void |
publish(AwsIotMessage message)
Publish a message to AWS IoT MQTT broker.
|
void |
publish(java.lang.String topic,
byte[] data)
Publishes a message on a topic with default QOS 0
|
void |
publish(java.lang.String topic,
byte[] data,
int qos)
Publishes a message on a topic.
|
void |
publish(java.lang.String topic,
byte[] data,
int qos,
boolean retained)
Publishes a message on a topic.
|
void |
subscribe(java.lang.String topic,
AwsIotMessageCallback subscriber)
Adds a topic listener on a topic.
|
void |
subscribe(java.lang.String topic,
AwsIotMessageCallback subscriber,
int qos)
Adds a topic listener on a topic.
|
void |
subscribeToShadow(ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback)
Subscribe to a shadow action (GET, UPDATE, DELETE) result ACCEPTED, REJECTED and (DELTA, DOCUMENT for update
only).
|
void |
subscribeToShadow(ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback,
int qos)
Subscribe to a shadow action (GET, UPDATE, DELETE) result ACCEPTED, REJECTED and (DELTA, DOCUMENT for update
only).
|
void |
subscribeToShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback)
Subscribe to a shadow action (GET, UPDATE, DELETE) result ACCEPTED, REJECTED and (DELTA, DOCUMENT for update
only).
|
void |
subscribeToShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback,
int qos)
Subscribe to a shadow action (GET, UPDATE, DELETE) result ACCEPTED, REJECTED and (DELTA, DOCUMENT for update
only).
|
void |
unsubscribe(java.lang.String topic)
Unsubscribe from a topic.
|
void |
unsubscribeFromShadow(ShadowAction action,
ShadowResult result)
Unsubscribe from a shadow action.
|
void |
unsubscribeFromShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result)
Unsubscribe from a shadow action.
|
void |
updateShadow(byte[] message)
Creates a no-named shadow if it doesn't exist, or updates the contents of an existing shadow with the state
information provided in the message body.
|
void |
updateShadow(byte[] message,
int qos)
Creates a no-named shadow if it doesn't exist, or updates the contents of an existing shadow with the state
information provided in the message body.
|
void |
updateShadow(java.lang.String shadowName,
byte[] message)
Creates a shadow if it doesn't exist, or updates the contents of an existing shadow with the state information
provided in the message body.
|
void |
updateShadow(java.lang.String shadowName,
byte[] message,
int qos)
updateShadow : Creates a shadow if it doesn't exist, or updates the contents of an existing shadow with the state
information provided in the message body.
|
public AwsIotClient(AwsIotClientOptions options)
options - the connection option. use AwsIotClientOptions.Builder to create an instance of
AwsIotClientOptionspublic AwsIotClient(AwsIotClientOptions options, AwsIotConnectionListener connectionCallback)
options - the connection optionconnectionCallback - connection callback to monitor connection lost eventspublic void connect()
throws AwsIotException
AwsIotException - if an error occurred during connection.public boolean isConnected()
public void disconnect()
throws AwsIotException
AwsIotException - when not connectedpublic void close()
throws AwsIotException
AwsIotException - if the client is not disconnected.public void subscribe(java.lang.String topic,
AwsIotMessageCallback subscriber)
throws AwsIotException
topic - the topic to add the listener on, one listener is allowed per topicsubscriber - the subscriber that will process the received dataAwsIotException - when not connected or on communication errorpublic void subscribe(java.lang.String topic,
AwsIotMessageCallback subscriber,
int qos)
throws AwsIotException
topic - the topic to add the listener on, one listener is allowed per topicsubscriber - the subscriber that will process the received dataqos - MQTT quality of serviceAwsIotException - when not connected or on communication errorpublic void unsubscribe(java.lang.String topic)
throws AwsIotException
topic - the topic you want to stop listening toAwsIotException - when not connected or on communication errorpublic void publish(AwsIotMessage message) throws AwsIotException
message - AwsIotMessageAwsIotException - on errorpublic void publish(java.lang.String topic,
byte[] data)
throws AwsIotException
topic - the topic you want to publish ondata - the data you want to publishAwsIotException - when not connected or on communication errorpublic void publish(java.lang.String topic,
byte[] data,
int qos)
throws AwsIotException
topic - the topic you want to publish ondata - the data you want to publishqos - MQTT quality of serviceAwsIotException - when not connected or on communication errorpublic void publish(java.lang.String topic,
byte[] data,
int qos,
boolean retained)
throws AwsIotException
topic - the topic you want to publish ondata - the data you want to publishqos - MQTT quality of serviceretained - set retained flag on the message.AwsIotException - when not connected or on communication errorpublic void getShadow()
throws AwsIotException
AwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void getShadow(int qos)
throws AwsIotException
qos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void getShadow(java.lang.String shadowName)
throws AwsIotException
shadowName - the shadow nameAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void getShadow(java.lang.String shadowName,
int qos)
throws AwsIotException
shadowName - the shadow nameqos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void updateShadow(byte[] message)
throws AwsIotException
message - the message (body of request)AwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void updateShadow(byte[] message,
int qos)
throws AwsIotException
message - the message (body of request)qos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void updateShadow(java.lang.String shadowName,
byte[] message)
throws AwsIotException
shadowName - the shadow namemessage - the messageAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void updateShadow(java.lang.String shadowName,
byte[] message,
int qos)
throws AwsIotException
shadowName - the shadow namemessage - the messageqos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void deleteShadow()
throws AwsIotException
AwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void deleteShadow(int qos)
throws AwsIotException
qos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void deleteShadow(java.lang.String shadowName)
throws AwsIotException
shadowName - the shadow clientAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void deleteShadow(java.lang.String shadowName,
int qos)
throws AwsIotException
shadowName - the shadow clientqos - MQTT quality of serviceAwsIotException - when not connected or on communication errorsubscribeToShadow(ShadowAction, ShadowResult, AwsIotMessageCallback)public void subscribeToShadow(ShadowAction action, ShadowResult result, AwsIotMessageCallback callback) throws AwsIotException
subscribeToShadow(String, ShadowAction, ShadowResult, AwsIotMessageCallback, int)action - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuescallback - the action callback will be executed when a message is received.AwsIotException - on error.public void subscribeToShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback)
throws AwsIotException
subscribeToShadow(String, ShadowAction, ShadowResult, AwsIotMessageCallback, int)shadowName - the name of shadowaction - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuescallback - the action callback will be executed when a message is received.AwsIotException - on error.public void subscribeToShadow(ShadowAction action, ShadowResult result, AwsIotMessageCallback callback, int qos) throws AwsIotException
action - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuescallback - the action callback will be executed when a message is received.qos - the MQTT quality of service.AwsIotException - on error.public void subscribeToShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result,
AwsIotMessageCallback callback,
int qos)
throws AwsIotException
shadowName - the name of shadowaction - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuescallback - the action callback will be executed when a message is received.qos - the MQTT quality of service.AwsIotException - on error.public void unsubscribeFromShadow(ShadowAction action, ShadowResult result) throws AwsIotException
action - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuesAwsIotException - on errorpublic void unsubscribeFromShadow(java.lang.String shadowName,
ShadowAction action,
ShadowResult result)
throws AwsIotException
shadowName - shadow nameaction - the shadow action see ShadowAction for possible valuesresult - the result to listen too ACCEPTED, REJECTED and (DELTA, DOCUMENT for update only). Use
ShadowResult for possible valuesAwsIotException - on errorpublic AwsIotClientOptions getClientOptions()
protected void dispatch(AwsIotMessage message)
message - received messageprotected void connectionLost(java.lang.Throwable cause)
AwsIotConnectionListener was registered.cause - connection lost cause