com.biocomfort.TO.data_consumer
Class DataConsumer

java.lang.Object
  extended by com.biocomfort.TO.data_consumer.DataConsumer
All Implemented Interfaces:
SDKDataListener
Direct Known Subclasses:
RestDataConsumer

public abstract class DataConsumer
extends java.lang.Object
implements SDKDataListener

With the abstract class DataConsumer it is possible to define custom data processing functionality. Simply extend this class and add it as SDKDataListener to the a object of a SDK implementation by calling the method SDK.addSDKDataListener(SDKDataListener).

See Also:
SDK.addSDKDataListener(SDKDataListener)

Constructor Summary
DataConsumer()
          Constructs a DataConsumer object with initializing it so that it is enabled.
 
Method Summary
 void addDataConsumerListener(DataConsumerListener listener)
          Adds the specified data consumer listener to receive data consumer events.
protected  void fireOnErrorEvent(MedicalDeviceTO medicalDevice, TO data, java.lang.Throwable throwable)
          Invokes an onError event for all data consumer listeners that are registers with this DataConsumer object.
protected  void fireOnSuccessEvent(MedicalDeviceTO medicalDevice, TO data)
          Invokes an onSuccess event for all data consumer listeners that are registers with this DataConsumer object.
 boolean isEnabled()
          Returns true if this DataConsumer object is enabled, false otherwise.
 void onDataReceived(MedicalDeviceTO medicalDevice, TO data)
          If this DataConsumer object was registered as SDKDataListener with the SDK implementation by calling the method SDK.addSDKDataListener this method is invoked when the SDK receives measurement data from a medical device.
protected abstract  void processData(MedicalDeviceTO medicalDevice, TO data)
          If this DataConsumer object was registered as SDKDataListener with the SDK implementation by calling the method SDK.addSDKDataListener and if this data consumer is enabled this method is invoked.
 void removeDataConsumerListener(DataConsumerListener listener)
          Removes the specified data consumer listener so that it no longer receives data consumer events.
 void setEnabled(boolean enabled)
          Enables or disables this DataConsumer object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataConsumer

public DataConsumer()
Constructs a DataConsumer object with initializing it so that it is enabled.

In order to process measurement data with this data consumer object register it with the SDK implementation by calling the method SDK.addSDKDataListener(SDKDataListener).

See Also:
SDK.addSDKDataListener(SDKDataListener)
Method Detail

addDataConsumerListener

public void addDataConsumerListener(DataConsumerListener listener)
Adds the specified data consumer listener to receive data consumer events. If the parameter listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the data consumer listener

removeDataConsumerListener

public void removeDataConsumerListener(DataConsumerListener listener)
Removes the specified data consumer listener so that it no longer receives data consumer events. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added. If the listener listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the data consumer listener to remove

isEnabled

public boolean isEnabled()
Returns true if this DataConsumer object is enabled, false otherwise.

Returns:
true if this data consumer is enabled.

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this DataConsumer object. If the given enabled parameter is true the data consumer will be enabled, otherwise it will be disabled.

Parameters:
enabled - true enables this data consumer

onDataReceived

public void onDataReceived(MedicalDeviceTO medicalDevice,
                           TO data)
If this DataConsumer object was registered as SDKDataListener with the SDK implementation by calling the method SDK.addSDKDataListener this method is invoked when the SDK receives measurement data from a medical device. If the data consumer is enabled the protected method processData of a concrete implementation of this class is called.

Specified by:
onDataReceived in interface SDKDataListener
Parameters:
medicalDevice - the medical device that sends the data
data - the received measurement data
See Also:
SDK.addSDKDataListener(SDKDataListener), processData(MedicalDeviceTO, TO)

fireOnSuccessEvent

protected void fireOnSuccessEvent(MedicalDeviceTO medicalDevice,
                                  TO data)
Invokes an onSuccess event for all data consumer listeners that are registers with this DataConsumer object.

Parameters:
medicalDevice - the medical device that sends the data
data - the received measurement data

fireOnErrorEvent

protected void fireOnErrorEvent(MedicalDeviceTO medicalDevice,
                                TO data,
                                java.lang.Throwable throwable)
Invokes an onError event for all data consumer listeners that are registers with this DataConsumer object.

Parameters:
medicalDevice - the medical device that sends the data
data - the received measurement data
throwable - a Throwable that has caused or describes the error

processData

protected abstract void processData(MedicalDeviceTO medicalDevice,
                                    TO data)
If this DataConsumer object was registered as SDKDataListener with the SDK implementation by calling the method SDK.addSDKDataListener and if this data consumer is enabled this method is invoked.

Within this method a concrete DataConsumer implementation should process the measurement data and fire an onSuccess event after the processing. In case that an error occured an onError event should be fired.

Parameters:
medicalDevice - the medical device that sends the data
data - the received measurement data