com.eurotech.framework.core.cloud
Class CloudClientImpl

java.lang.Object
  extended by com.eurotech.framework.core.cloud.CloudClientImpl
All Implemented Interfaces:
CloudClient, CloudClientListener

public class CloudClientImpl
extends Object
implements CloudClient, CloudClientListener

Implementation of the CloudClient interface.


Constructor Summary
protected CloudClientImpl(String applicationId, DataService dataService, CloudServiceImpl cloudServiceImpl)
           
 
Method Summary
 void addCloudClientListener(CloudClientListener cloudClientListener)
          Adds a CloudCallbackHandler with this CloudClient.
 int controlPublish(String topic, EsfPayload payload, int qos, boolean retain, int priority)
          Publishes a control message to the remote server.
 int controlPublish(String deviceId, String topic, byte[] payload, int qos, boolean retain, int priority)
          Publishes a control message to the remote server addressing it to another device with a raw byte array payload.
 int controlPublish(String deviceId, String topic, EsfPayload payload, int qos, boolean retain, int priority)
          Publishes a control message to the remote server addressing it to another device.
 void controlSubscribe(String topic, int qos)
          Subscribes to a control topic with the remote server.
 void controlUnsubscribe(String topic)
          Unsubscribes to a control topic with the remote server.
 String getApplicationId()
          Returns the applicationId of this CloudApplicationClient
 List<Integer> getDroppedInFlightMessageIds()
          Finds the list of identifiers of in-flight messages that have been dropped.
 List<Integer> getInFlightMessageIds()
          Finds the list of identifiers of messages that are still in-flight (messages published but not confirmed yet).
 List<Integer> getUnpublishedMessageIds()
          Gets the list of identifiers of messages that have not been published yet.
 boolean isConnected()
          Returns an indication of whether the connection to the remote server is established.
 void onConnectionEstablished()
          Called when the CloudClient has successfully connected with the broker.
 void onConnectionLost()
          Called when the client has lost its connection with the broker.
 void onControlMessageArrived(String deviceId, String appTopic, EsfPayload payload, int qos, boolean retain)
          Called by the CloudClient when it receives a published control message from the broker.
 void onMessageArrived(String deviceId, String appTopic, EsfPayload payload, int qos, boolean retain)
          Called by the client when it receives a published data message from the broker.
 void onMessageConfirmed(int pubId, String appTopic)
          Called by the CloudClient when a published message has been fully acknowledged by the broker, as appropriate for the quality of service.
 void onMessagePublished(int pubId, String appTopic)
          Called by the CloudClient when a message has been transfered from the publishing queue to the underlying DataTransportService for publishing on the wire.
 int publish(String topic, byte[] payload, int qos, boolean retain, int priority)
          Publishes a message to the remote server with a raw byte array payload.
 int publish(String topic, EsfPayload payload, int qos, boolean retain)
          Publishes a message to the remote server using the default priority 5.
 int publish(String topic, EsfPayload payload, int qos, boolean retain, int priority)
          Publishes a message to the remote server.
 void release()
          Releases this CloudClient handle.
 void removeCloudClientListener(CloudClientListener cloudClientListener)
          Removes a CloudCallbackHandler from this CloudClient.
 void subscribe(String topic, int qos)
          Subscribes to a topic with the remote server.
 void unsubscribe(String topic)
          Unubscribes to a topic with the remote server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloudClientImpl

protected CloudClientImpl(String applicationId,
                          DataService dataService,
                          CloudServiceImpl cloudServiceImpl)
Method Detail

getApplicationId

public String getApplicationId()
Returns the applicationId of this CloudApplicationClient

Specified by:
getApplicationId in interface CloudClient
Returns:
applicationId

release

public void release()
Releases this CloudClient handle. This instance should no longer be used. Note: CloudClient does not unsubscribes all subscriptions incurred by this client, this responsibility is left to the application developer

Specified by:
release in interface CloudClient

addCloudClientListener

public void addCloudClientListener(CloudClientListener cloudClientListener)
Description copied from interface: CloudClient
Adds a CloudCallbackHandler with this CloudClient. This handler will receive events when a client publication has arrived, and when a publish has been fully acknowledged by the remote server.

Specified by:
addCloudClientListener in interface CloudClient

removeCloudClientListener

public void removeCloudClientListener(CloudClientListener cloudClientListener)
Description copied from interface: CloudClient
Removes a CloudCallbackHandler from this CloudClient. The provided CloudCallbackHandler will no longer receive the events when a published message is received.

Specified by:
removeCloudClientListener in interface CloudClient

isConnected

public boolean isConnected()
Description copied from interface: CloudClient
Returns an indication of whether the connection to the remote server is established. If your application needs to manage the connection directly, it can use the DataService.connect() and DataService.disconnect(long) methods.

Specified by:
isConnected in interface CloudClient
Returns:
boolean, whether connection to broker is established.

publish

public int publish(String topic,
                   EsfPayload payload,
                   int qos,
                   boolean retain)
            throws EsfException
Description copied from interface: CloudClient
Publishes a message to the remote server using the default priority 5. Before passing the message the to DataService, the CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and device identification. It is also responsible to encode the EsfPayload payload into binary format.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit.

Specified by:
publish in interface CloudClient
Parameters:
topic - A String specifying the application portion of the topic the message is published on.
payload - An EsfPayload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
Returns:
The published message's ID.
Throws:
EsfException

publish

public int publish(String topic,
                   EsfPayload payload,
                   int qos,
                   boolean retain,
                   int priority)
            throws EsfException
Description copied from interface: CloudClient
Publishes a message to the remote server. Before passing the message the to DataService, the CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and device identification. It is also responsible to encode the EsfPayload payload into binary format.
The priority argument can be used to control the relative ordering of this message with other messages that may be currently queued for publishing. Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. Life-cycle messages (e.g. device start and stop) are an example of messages that are published by the framework with priority 0. Priority 1 messages are used by the framework to publish response messages in request/response conversations to prevent a timeout at the requester. Application should consider using priority 5 or higher.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit. The limit does not apply to internal messages with the priority less than 2. These priority levels are reserved to the framework which uses it for life-cycle messages - birth and death certificates - and replies to request/response flows.

Specified by:
publish in interface CloudClient
Parameters:
topic - A String specifying the application portion of the topic the message is published on.
payload - An EsfPayload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
priority - Relative ordering of this message with other messages that may be currently queued for publishing.
Returns:
The published message's ID.
Throws:
EsfException

publish

public int publish(String topic,
                   byte[] payload,
                   int qos,
                   boolean retain,
                   int priority)
            throws EsfException
Description copied from interface: CloudClient
Publishes a message to the remote server with a raw byte array payload. This is the lowest level publish API exposed by the CloudClient. Before passing the message the to DataService, the CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and device identification.
The priority argument can be used to control the relative ordering of this message with other messages that may be currently queued for publishing. Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. Life-cycle messages (e.g. device start and stop) are an example of messages that are published by the framework with priority 0. Priority 1 messages are used by the framework to publish response messages in request/response conversations to prevent a timeout at the requester. Application should consider using priority 5 or higher.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit. The limit does not apply to internal messages with the priority less than 2. These priority levels are reserved to the framework which uses it for life-cycle messages - birth and death certificates - and replies to request/response flows.

Specified by:
publish in interface CloudClient
Parameters:
topic - A String specifying the application portion of the topic the message is published on.
payload - Binary payload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
priority - Relative ordering of this message with other messages that may be currently queued for publishing.
Returns:
The published message's ID.
Throws:
EsfException

controlPublish

public int controlPublish(String topic,
                          EsfPayload payload,
                          int qos,
                          boolean retain,
                          int priority)
                   throws EsfException
Description copied from interface: CloudClient
Publishes a control message to the remote server. Control messages are qualified with an additional prefix appended at the beginning of the target topic. The prefix is configured as a property of the CloudService and it appended automatically by this controlPublish method. Just as CloudClient.publish(java.lang.String, com.eurotech.framework.message.EsfPayload, int, boolean), the controlPublish method will manipulate the provided topic by appending the necessary parts to achieve topic partitioning including device identification and encode the EsfPayload payload into binary format.
The priority argument can be used to control the relative ordering of this message with other messages that may be currently queued for publishing. Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. Life-cycle messages (e.g. device start and stop) are an example of messages that are published by the framework with priority 0. Priority 1 messages are used by the framework to publish response messages in request/response conversations to prevent a timeout at the requester. Application should consider using priority 5 or higher.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit. The limit does not apply to internal messages with the priority less than 2. These priority levels are reserved to the framework which uses it for life-cycle messages - birth and death certificates - and replies to request/response flows.

Specified by:
controlPublish in interface CloudClient
Parameters:
topic - A String specifying the application topic the message is published on.
payload - An EsfPayload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
priority - Relative ordering of this message with other messages that may be currently queued for publishing.
Returns:
The published message's ID.
Throws:
EsfException

controlPublish

public int controlPublish(String deviceId,
                          String topic,
                          EsfPayload payload,
                          int qos,
                          boolean retain,
                          int priority)
                   throws EsfException
Description copied from interface: CloudClient
Publishes a control message to the remote server addressing it to another device. Control messages are qualified with an additional prefix appended at the beginning of the target topic. The prefix is configured as a property of the CloudService and it appended automatically by this controlPublish method. Just as CloudClient.publish(java.lang.String, com.eurotech.framework.message.EsfPayload, int, boolean), the controlPublish method will manipulate the provided topic by appending the necessary parts to achieve topic partitioning including device identification and encode the EsfPayload payload into binary format.
The priority argument can be used to control the relative ordering of this message with other messages that may be currently queued for publishing. Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. Life-cycle messages (e.g. device start and stop) are an example of messages that are published by the framework with priority 0. Priority 1 messages are used by the framework to publish response messages in request/response conversations to prevent a timeout at the requester. Application should consider using priority 5 or higher.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit. The limit does not apply to internal messages with the priority less than 2. These priority levels are reserved to the framework which uses it for life-cycle messages - birth and death certificates - and replies to request/response flows.

Specified by:
controlPublish in interface CloudClient
Parameters:
deviceId - A String specifying the asset ID.
topic - A String specifying the application topic the message is published on.
payload - An EsfPayload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
priority - Relative ordering of this message with other messages that may be currently queued for publishing.
Returns:
The published message's ID.
Throws:
EsfException

controlPublish

public int controlPublish(String deviceId,
                          String topic,
                          byte[] payload,
                          int qos,
                          boolean retain,
                          int priority)
                   throws EsfException
Description copied from interface: CloudClient
Publishes a control message to the remote server addressing it to another device with a raw byte array payload. Control messages are qualified with an additional prefix appended at the beginning of the target topic. The prefix is configured as a property of the CloudService and it appended automatically by this controlPublish method. Just as CloudClient.publish(java.lang.String, com.eurotech.framework.message.EsfPayload, int, boolean), the controlPublish method will manipulate the provided topic by appending the necessary parts to achieve topic partitioning including device identification.
The priority argument can be used to control the relative ordering of this message with other messages that may be currently queued for publishing. Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. Life-cycle messages (e.g. device start and stop) are an example of messages that are published by the framework with priority 0. Priority 1 messages are used by the framework to publish response messages in request/response conversations to prevent a timeout at the requester. Application should consider using priority 5 or higher.
The EsfStoreCapacityReachedException is thrown if the database buffer has reached its capacity for messages that are not yet published or they are still in transit. The limit does not apply to internal messages with the priority less than 2. These priority levels are reserved to the framework which uses it for life-cycle messages - birth and death certificates - and replies to request/response flows.

Specified by:
controlPublish in interface CloudClient
Parameters:
deviceId - A String specifying the asset ID.
topic - A String specifying the application topic the message is published on.
payload - Binary payload representing the message to be published
qos - An integer specifying the quality of service the message was published on.
retain - Whether or not the broker should retain the message
priority - Relative ordering of this message with other messages that may be currently queued for publishing.
Returns:
The published message's ID.
Throws:
EsfException

subscribe

public void subscribe(String topic,
                      int qos)
               throws EsfException
Description copied from interface: CloudClient
Subscribes to a topic with the remote server. The topic is specified as a String object and the QoS is specified as an integer. The CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and device identification.
This is a synchronous call. If the subscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Specified by:
subscribe in interface CloudClient
Parameters:
topic - A String object containing the application topic.
qos - An int containing the Quality of Service.
Throws:
EsfException

controlSubscribe

public void controlSubscribe(String topic,
                             int qos)
                      throws EsfException
Description copied from interface: CloudClient
Subscribes to a control topic with the remote server. The topic is specified as a String object and the QoS is specified as an integer. The CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and including control prefix and device identification.
This is a synchronous call. If the subscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Specified by:
controlSubscribe in interface CloudClient
Parameters:
topic - A String object containing the application topic.
qos - An int containing the Quality of Service.
Throws:
EsfException

unsubscribe

public void unsubscribe(String topic)
                 throws EsfException
Description copied from interface: CloudClient
Unubscribes to a topic with the remote server. The topic is specified as a String object and the QoS is specified as an integer. The CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and device identification.
This is a synchronous call. If the unsubscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Specified by:
unsubscribe in interface CloudClient
Parameters:
topic - A String object containing the application topic.
Throws:
EsfException

controlUnsubscribe

public void controlUnsubscribe(String topic)
                        throws EsfException
Description copied from interface: CloudClient
Unsubscribes to a control topic with the remote server. The topic is specified as a String object and the QoS is specified as an integer. The CloudClient will manipulate the provided topic by appending the necessary parts to achieve topic partitioning and including control prefix and device identification.
This is a synchronous call. If the unsubscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Specified by:
controlUnsubscribe in interface CloudClient
Parameters:
topic - A String object containing the application topic.
Throws:
EsfException

getUnpublishedMessageIds

public List<Integer> getUnpublishedMessageIds()
                                       throws EsfException
Description copied from interface: CloudClient
Gets the list of identifiers of messages that have not been published yet.

Specified by:
getUnpublishedMessageIds in interface CloudClient
Returns:
Throws:
EsfException

getInFlightMessageIds

public List<Integer> getInFlightMessageIds()
                                    throws EsfException
Description copied from interface: CloudClient
Finds the list of identifiers of messages that are still in-flight (messages published but not confirmed yet). This only applies to messages published with QoS > 0.

Specified by:
getInFlightMessageIds in interface CloudClient
Returns:
Throws:
EsfException

getDroppedInFlightMessageIds

public List<Integer> getDroppedInFlightMessageIds()
                                           throws EsfException
Description copied from interface: CloudClient
Finds the list of identifiers of in-flight messages that have been dropped. This only applies to messages published with QoS > 0. On the establishment of a new connection, the service can be configured either to republish or drop in-flight messages. The former option can be used if service users tolerate publishing message duplicates. The latter option can be used it service users tolerate losing messages.

Specified by:
getDroppedInFlightMessageIds in interface CloudClient
Returns:
Throws:
EsfException

onMessageArrived

public void onMessageArrived(String deviceId,
                             String appTopic,
                             EsfPayload payload,
                             int qos,
                             boolean retain)
Description copied from interface: CloudClientListener
Called by the client when it receives a published data message from the broker. If the message received has a binary payload that it has NOT been encoded using the the EsfPayload class, the received bytes will be set as the body field of a new EsfPaylaod instance which is passed to the callback Listener interface.

Specified by:
onMessageArrived in interface CloudClientListener
Parameters:
deviceId - The asset ID of the semanticTopic prefix the message arrived on.
appTopic - The appTopic the message arrived on.
payload - The EsfPayload that arrived.
qos - The Quality of Service that the message was received on.
retain - Whether the message was retained by the broker.

onControlMessageArrived

public void onControlMessageArrived(String deviceId,
                                    String appTopic,
                                    EsfPayload payload,
                                    int qos,
                                    boolean retain)
Description copied from interface: CloudClientListener
Called by the CloudClient when it receives a published control message from the broker. If the message received has a binary payload that it has NOT been encoded using the the EsfPayload class, the received bytes will be set as the body field of a new EsfPaylaod instance which is passed to the callback Listener interface.

Specified by:
onControlMessageArrived in interface CloudClientListener
Parameters:
deviceId - The deviceId this message was addressed to.
appTopic - The appTopic the message arrived on.
payload - The EsfPayload that arrived.
qos - The Quality of Service that the message was received on.
retain - Whether the message was retained by the broker.

onMessageConfirmed

public void onMessageConfirmed(int pubId,
                               String appTopic)
Description copied from interface: CloudClientListener
Called by the CloudClient when a published message has been fully acknowledged by the broker, as appropriate for the quality of service. The published method is not called for QoS 0 publications.

Specified by:
onMessageConfirmed in interface CloudClientListener
Parameters:
pubId - The message id of the published message

onMessagePublished

public void onMessagePublished(int pubId,
                               String appTopic)
Description copied from interface: CloudClientListener
Called by the CloudClient when a message has been transfered from the publishing queue to the underlying DataTransportService for publishing on the wire.

Specified by:
onMessagePublished in interface CloudClientListener

onConnectionEstablished

public void onConnectionEstablished()
Description copied from interface: CloudClientListener
Called when the CloudClient has successfully connected with the broker.
If the bundle using the client relies on subscriptions beyond the default ones, it is responsibility of the application to implement the CloudClientListener.onConnectionEstablished() callback method to restore the subscriptions it needs after a connection loss.

Specified by:
onConnectionEstablished in interface CloudClientListener

onConnectionLost

public void onConnectionLost()
Description copied from interface: CloudClientListener
Called when the client has lost its connection with the broker. Depending on the DataService configuration, the client will attempt to reconnect and call the CloudClientListener.onConnectionEstablished() method upon a successful reconnect. This is only a notification, the callback handler should not attempt to handle the reconnect.
If the bundle using the client relies on subscriptions beyond the default ones, it is responsibility of the application to implement the CloudClientListener.onConnectionEstablished() callback method to restore the subscriptions it needs after a connection loss.

Specified by:
onConnectionLost in interface CloudClientListener


Copyright © 2013. All Rights Reserved.