com.eurotech.framework.core.data
Class DataServiceImpl

java.lang.Object
  extended by com.eurotech.framework.core.data.DataServiceImpl
All Implemented Interfaces:
ConfigurableComponent, DataService, DataTransportListener

public class DataServiceImpl
extends Object
implements DataService, DataTransportListener, ConfigurableComponent


Constructor Summary
DataServiceImpl()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext componentContext, Map<String,Object> properties)
           
 void connect()
          Connects to the broker if not already connected.
protected  void deactivate(org.osgi.service.component.ComponentContext componentContext)
           
 void disconnect(long quiesceTimeout)
          Disconnects from the broker.
 List<Integer> getDroppedInFlightMessageIds(String topicRegex)
          Finds the list of identifiers of in-flight messages that have been dropped.
 List<Integer> getInFlightMessageIds(String topicRegex)
          Finds the list of identifiers of messages that are still in-flight (messages published but not confirmed yet).
 List<Integer> getUnpublishedMessageIds(String topicRegex)
          Finds the list of identifiers of messages that have not been published yet.
 boolean isConnected()
          Answers if the DataService is connected to the broker.
 void onConfigurationUpdated()
          Notifies the DataTransportService has received a configuration update and it has applied the new configuration
 void onConfigurationUpdating()
          Notifies the DataTransportService has received a configuration update.
 void onConnectionEstablished(boolean newSession)
          Notifies the listener of the establishment of the new connection with the remote server.
 void onConnectionLost(Throwable cause)
          Notifies the listener that the connection to the remote server has been lost.
 void onDisconnected()
          Notifies the listener that the connection to the remote server has been terminated.
 void onDisconnecting()
          Notifies the listener that the connection to the remote server is about to be terminated.
 void onMessageArrived(String topic, byte[] payload, int qos, boolean retained)
          Notifies the listener that a new message has been received from the remote server.
 void onMessageConfirmed(DataTransportToken token)
          Notifies the listener that a message has been confirmed by the remote server.
 int publish(String topic, byte[] payload, int qos, boolean retain, int priority)
          Publishes a message to the broker.
 void setDataTransportService(DataTransportService dataTransportService)
           
 void setDbService(DbService dbService)
           
 void subscribe(String topic, int qos)
          Subscribes to the specified topic with the remote server.
 void unsetDataTransportService(DataTransportService dataTransportService)
           
 void unsetDbService(DbService dbService)
           
 void unsubscribe(String topic)
          Unubscribes to the specified topic with the remote server.
 void updated(Map<String,Object> properties)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataServiceImpl

public DataServiceImpl()
Method Detail

activate

protected void activate(org.osgi.service.component.ComponentContext componentContext,
                        Map<String,Object> properties)

updated

public void updated(Map<String,Object> properties)

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext componentContext)

setDataTransportService

public void setDataTransportService(DataTransportService dataTransportService)

unsetDataTransportService

public void unsetDataTransportService(DataTransportService dataTransportService)

setDbService

public void setDbService(DbService dbService)

unsetDbService

public void unsetDbService(DbService dbService)

onConnectionEstablished

public void onConnectionEstablished(boolean newSession)
Description copied from interface: DataTransportListener
Notifies the listener of the establishment of the new connection with the remote server.

Specified by:
onConnectionEstablished in interface DataTransportListener
Parameters:
newSession - true if the connection is to the same broker with the same client ID.

onDisconnecting

public void onDisconnecting()
Description copied from interface: DataTransportListener
Notifies the listener that the connection to the remote server is about to be terminated.

Specified by:
onDisconnecting in interface DataTransportListener

onDisconnected

public void onDisconnected()
Description copied from interface: DataTransportListener
Notifies the listener that the connection to the remote server has been terminated.

Specified by:
onDisconnected in interface DataTransportListener

onConfigurationUpdating

public void onConfigurationUpdating()
Description copied from interface: DataTransportListener
Notifies the DataTransportService has received a configuration update.

Specified by:
onConfigurationUpdating in interface DataTransportListener

onConfigurationUpdated

public void onConfigurationUpdated()
Description copied from interface: DataTransportListener
Notifies the DataTransportService has received a configuration update and it has applied the new configuration

Specified by:
onConfigurationUpdated in interface DataTransportListener

onConnectionLost

public void onConnectionLost(Throwable cause)
Description copied from interface: DataTransportListener
Notifies the listener that the connection to the remote server has been lost.

Specified by:
onConnectionLost in interface DataTransportListener

onMessageArrived

public void onMessageArrived(String topic,
                             byte[] payload,
                             int qos,
                             boolean retained)
Description copied from interface: DataTransportListener
Notifies the listener that a new message has been received from the remote server.

Specified by:
onMessageArrived in interface DataTransportListener

onMessageConfirmed

public void onMessageConfirmed(DataTransportToken token)
Description copied from interface: DataTransportListener
Notifies the listener that a message has been confirmed by the remote server.

Specified by:
onMessageConfirmed in interface DataTransportListener

connect

public void connect()
             throws EsfConnectException
Description copied from interface: DataService
Connects to the broker if not already connected.

Specified by:
connect in interface DataService
Throws:
EsfConnectException

isConnected

public boolean isConnected()
Description copied from interface: DataService
Answers if the DataService is connected to the broker.

Specified by:
isConnected in interface DataService
Returns:

disconnect

public void disconnect(long quiesceTimeout)
Description copied from interface: DataService
Disconnects from the broker. This method will block, up to the specified duration, allowing the protocol implementation to complete delivery of in-flight messages before actually disconnecting from the broker. If the Data Service is configured to auto-connect on startup and it's explicitly disconnected it will not automatically reconnect.

Specified by:
disconnect in interface DataService

subscribe

public void subscribe(String topic,
                      int qos)
               throws EsfTimeoutException,
                      EsfException,
                      EsfNotConnectedException
Description copied from interface: DataService
Subscribes to the specified topic with the remote server. The method requires an active connection with the remote server and it is operates synchronously. The implementation is a pass-through to the DataTransportService.subscribe(java.lang.String, int) method.

Specified by:
subscribe in interface DataService
Throws:
EsfTimeoutException
EsfException
EsfNotConnectedException - TODO

unsubscribe

public void unsubscribe(String topic)
                 throws EsfTimeoutException,
                        EsfException,
                        EsfNotConnectedException
Description copied from interface: DataService
Unubscribes to the specified topic with the remote server. The method requires an active connection with the remote server and it is operates synchronously. The implementation is a pass-through to the DataTransportService.unsubscribe(java.lang.String) method.

Specified by:
unsubscribe in interface DataService
Throws:
EsfTimeoutException
EsfException
EsfNotConnectedException - TODO

publish

public int publish(String topic,
                   byte[] payload,
                   int qos,
                   boolean retain,
                   int priority)
            throws EsfStoreException
Description copied from interface: DataService
Publishes a message to the broker. This method quickly returns deferring the actual message publication accordingly to the current service policy and to the specified priority, 0 being the highest. Messages are confirmed asynchronously to the caller by the DataServiceListener.onMessageConfirmed(int, java.lang.String) callback. A unique identifier is always returned, independently on the specified QoS or priority level, which can be used to match the asynchronous message confirm. The actual semantics associated to a message confirm is as follows: Priority level 0 (highest) should be used sparingly and reserved for messages that should be sent with the minimum latency. For example Cloud life-cycle messages are published with priority 0 as soon the connection is established and just before disconnecting.
Data messages, tolerating an higher latency, may be published with a lower priority. Within each priority level and each QoS level, messages are guaranteed do be delivered in order (oldest first).
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 DataService
Returns:
Throws:
EsfStoreException

getUnpublishedMessageIds

public List<Integer> getUnpublishedMessageIds(String topicRegex)
                                       throws EsfStoreException
Description copied from interface: DataService
Finds the list of identifiers of messages that have not been published yet. Given the service has no means of knowing who published the message, a regex topic must be specified in order to find only the relevant identifiers.

Specified by:
getUnpublishedMessageIds in interface DataService
Returns:
Throws:
EsfStoreException

getInFlightMessageIds

public List<Integer> getInFlightMessageIds(String topicRegex)
                                    throws EsfStoreException
Description copied from interface: DataService
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. Given the service has no means of knowing who published the message, a regex topic must be specified in order to find only the relevant identifiers.

Specified by:
getInFlightMessageIds in interface DataService
Returns:
Throws:
EsfStoreException

getDroppedInFlightMessageIds

public List<Integer> getDroppedInFlightMessageIds(String topicRegex)
                                           throws EsfStoreException
Description copied from interface: DataService
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. Given the service has no means of knowing who published the message, a regex topic must be specified in order to find only the relevant identifiers.

Specified by:
getDroppedInFlightMessageIds in interface DataService
Throws:
EsfStoreException


Copyright © 2013. All Rights Reserved.