Class AwsIotConnection

  • All Implemented Interfaces:
    AwsIotConnectionCallback
    Direct Known Subclasses:
    AwsIotMqttConnection

    public abstract class AwsIotConnection
    extends Object
    implements AwsIotConnectionCallback
    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.
    • Constructor Detail

      • AwsIotConnection

        public AwsIotConnection​(AbstractAwsIotClient client)
        Instantiates a new connection object.
        Parameters:
        client - the client
    • Method Detail

      • openConnection

        protected abstract void openConnection​(AwsIotMessageCallback callback)
                                        throws AWSIotException
        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

        protected abstract void closeConnection​(AwsIotMessageCallback callback)
                                         throws AWSIotException
        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 request
        AwsIotRetryableException - 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 request
        AwsIotRetryableException - 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 request
        AwsIotRetryableException - this exception is thrown when the request is failed to be sent, which will be queued and retried
      • publish

        public void publish​(AWSIotMessage message)
                     throws AWSIotException
        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 id
        awsSecretAccessKey - the AWS secret access key
        sessionToken - Session token received along with the temporary credentials from services like STS server, AssumeRole, or Amazon Cognito.
      • subscribe

        public void subscribe​(AWSIotMessage message)
                       throws AWSIotException
        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

        public void unsubscribe​(AWSIotMessage message)
                         throws AWSIotException
        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

        public void connect​(AwsIotMessageCallback callback)
                     throws AWSIotException
        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

        public void disconnect​(AwsIotMessageCallback callback)
                        throws AWSIotException
        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
      • getClient

        public AbstractAwsIotClient getClient()
        The client the connection is associated with.
        Returns:
        the current client
      • getConnectionStatus

        public AWSIotConnectionStatus getConnectionStatus()
        The connection status. the new connection status
        Returns:
        the current connection status
      • setConnectionStatus

        public void setConnectionStatus​(AWSIotConnectionStatus connectionStatus)
        The connection status.
        Parameters:
        connectionStatus - the new connection status
      • getRetryTask

        public Future<?> 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

        public AwsIotMessageCallback 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

        public ConcurrentLinkedQueue<AWSIotMessage> getPublishQueue()
        The offline publish queue holding messages while the connection is being established.
        Returns:
        the current offline publish queue
      • getSubscribeQueue

        public ConcurrentLinkedQueue<AWSIotMessage> getSubscribeQueue()
        The offline subscribe request queue holding messages while the connection is being established.
        Returns:
        the current offline subscribe request queue
      • getUnsubscribeQueue

        public ConcurrentLinkedQueue<AWSIotMessage> getUnsubscribeQueue()
        The offline unsubscribe request queue holding messages while the connection is being established.
        Returns:
        the current offline unsubscribe request queue