Class AwsIotConnection
java.lang.Object
com.amazonaws.services.iot.client.core.AwsIotConnection
- All Implemented Interfaces:
AwsIotConnectionCallback
- Direct Known Subclasses:
AwsIotMqttConnection
This class provides an abstract layer for the library to communicate with the
AWS IoT service without having to directly interact with the actual MQTT
implementation. The abstraction layer also provides connection retry logic as
well as offline message queuing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractAwsIotClientThe client the connection is associated with.protected AWSIotConnectionStatusThe connection status. -
Constructor Summary
ConstructorsConstructorDescriptionAwsIotConnection(AbstractAwsIotClient client) Instantiates a new connection object. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcloseConnection(AwsIotMessageCallback callback) Abstract method which is called to terminate an underneath connection.voidconnect(AwsIotMessageCallback callback) The actual connect method exposed by this class.voiddisconnect(AwsIotMessageCallback callback) The actual disconnect method exposed by this class.The client the connection is associated with.The callback functions for the connect request.The connection status.The offline publish queue holding messages while the connection is being established.Future<?>The future object holding the retry task.intThe retry times.The offline subscribe request queue holding messages while the connection is being established.The offline unsubscribe request queue holding messages while the connection is being established.booleanFlag to indicate user disconnect is in progress.voidOn connection closed.voidOn connection failure.voidOn connection success.protected abstract voidopenConnection(AwsIotMessageCallback callback) Abstract method which is called to establish an underneath connection.voidpublish(AWSIotMessage message) The actual publish method exposed by this class.protected abstract voidpublishMessage(AWSIotMessage message) Abstract method which is called to publish a message.voidsetConnectionStatus(AWSIotConnectionStatus connectionStatus) The connection status.voidsubscribe(AWSIotMessage message) The actual subscribe method exposed by this class.protected abstract voidsubscribeTopic(AWSIotMessage message) Abstract method which is called to subscribe to a topic.voidunsubscribe(AWSIotMessage message) The actual unsubscribe method exposed by this class.protected abstract voidunsubscribeTopic(AWSIotMessage message) Abstract method which is called to unsubscribe to a topic.voidupdateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) Updates credentials for the connection, which will be used for new connections.
-
Field Details
-
client
The client the connection is associated with. -
connectionStatus
The connection status.
-
-
Constructor Details
-
AwsIotConnection
Instantiates a new connection object.- Parameters:
client- the client
-
-
Method Details
-
openConnection
Abstract method which is called to establish an underneath connection.- Parameters:
callback- connection callback functions- Throws:
AWSIotException- this exception is thrown when the request is failed to be sent
-
closeConnection
Abstract method which is called to terminate an underneath connection.- Parameters:
callback- connection callback functions- Throws:
AWSIotException- this exception is thrown when the request is failed to be sent
-
publishMessage
protected abstract void publishMessage(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException Abstract method which is called to publish a message.- Parameters:
message- the message to be published- Throws:
AWSIotException- this exception is thrown when there's an unrecoverable error happened while processing the requestAwsIotRetryableException- this exception is thrown when the request is failed to be sent, which will be queued and retried
-
subscribeTopic
protected abstract void subscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException Abstract method which is called to subscribe to a topic.- Parameters:
message- the topic to be subscribed to- Throws:
AWSIotException- this exception is thrown when there's an unrecoverable error happened while processing the requestAwsIotRetryableException- this exception is thrown when the request is failed to be sent, which will be queued and retried
-
unsubscribeTopic
protected abstract void unsubscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException Abstract method which is called to unsubscribe to a topic.- Parameters:
message- the topic to be unsubscribed to- Throws:
AWSIotException- this exception is thrown when there's an unrecoverable error happened while processing the requestAwsIotRetryableException- this exception is thrown when the request is failed to be sent, which will be queued and retried
-
publish
The actual publish method exposed by this class.- Parameters:
message- the message to be published- Throws:
AWSIotException- this exception is thrown when the underneath failed to process the request
-
updateCredentials
public void updateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) Updates credentials for the connection, which will be used for new connections.- Parameters:
awsAccessKeyId- the AWS access key idawsSecretAccessKey- the AWS secret access keysessionToken- Session token received along with the temporary credentials from services like STS server, AssumeRole, or Amazon Cognito.
-
subscribe
The actual subscribe method exposed by this class.- Parameters:
message- the topic to be subscribed to- Throws:
AWSIotException- this exception is thrown when the underneath failed to process the request
-
unsubscribe
The actual unsubscribe method exposed by this class.- Parameters:
message- the topic to be unsubscribed to- Throws:
AWSIotException- this exception is thrown when the underneath failed to process the request
-
connect
The actual connect method exposed by this class.- Parameters:
callback- user callback functions- Throws:
AWSIotException- this exception is thrown when the underneath layer failed to process the request
-
disconnect
The actual disconnect method exposed by this class.- Parameters:
callback- user callback functions- Throws:
AWSIotException- this exception is thrown when the underneath layer failed to process the request
-
onConnectionSuccess
public void onConnectionSuccess()Description copied from interface:AwsIotConnectionCallbackOn connection success.- Specified by:
onConnectionSuccessin interfaceAwsIotConnectionCallback
-
onConnectionFailure
public void onConnectionFailure()Description copied from interface:AwsIotConnectionCallbackOn connection failure.- Specified by:
onConnectionFailurein interfaceAwsIotConnectionCallback
-
onConnectionClosed
public void onConnectionClosed()Description copied from interface:AwsIotConnectionCallbackOn connection closed.- Specified by:
onConnectionClosedin interfaceAwsIotConnectionCallback
-
getClient
The client the connection is associated with.- Returns:
- the current client
-
getConnectionStatus
The connection status.- Returns:
- the current connection status
-
setConnectionStatus
The connection status.- Parameters:
connectionStatus- the new connection status
-
getRetryTask
The future object holding the retry task.- Returns:
- the current retry task
-
getRetryTimes
public int getRetryTimes()The retry times.- Returns:
- the current retry times
-
getConnectCallback
The callback functions for the connect request.- Returns:
- the current connect callback
-
isUserDisconnect
public boolean isUserDisconnect()Flag to indicate user disconnect is in progress.- Returns:
- the current user disconnect flag
-
getPublishQueue
The offline publish queue holding messages while the connection is being established.- Returns:
- the current offline publish queue
-
getSubscribeQueue
The offline subscribe request queue holding messages while the connection is being established.- Returns:
- the current offline subscribe request queue
-
getUnsubscribeQueue
The offline unsubscribe request queue holding messages while the connection is being established.- Returns:
- the current offline unsubscribe request queue
-