Class HeartbeatWatcher


  • public class HeartbeatWatcher
    extends java.lang.Object
    Implements the basis of a device heartbeat watcher.
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> metricsCallback  
      private java.util.Map<java.lang.String,​java.lang.Long> received  
      private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> statusCallback  
      private long timeout  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears all devices/entries.
      de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> createMetricsReceptionCallback()
      Creates a reception callback to be used with StreamNames.SERVICE_METRICS or StreamNames.RESOURCE_METRICS.
      de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> createStatusReceptionCallback()
      Creates a reception callback to be used with StreamNames.STATUS_STREAM.
      void deleteOutdated​(long timeout, java.util.function.Consumer<java.lang.String> outdatedHandler)
      Deletes outdated entries and informs outdatedHandler about the removed entry.
      void deleteOutdated​(java.util.function.Consumer<java.lang.String> outdatedHandler)
      Deletes outdated entries and informs outdatedHandler about the removed entry.
      int getDeviceCount()
      Returns the number of devices known to this class.
      void installInto​(de.iip_ecosphere.platform.transport.connectors.TransportConnector connector)
      Creates two reception callbacks and installs them into connector.
      void notifyRecordDeleted​(java.lang.String deviceId)
      Called to notify that we received a deletion signal from deviceId.
      void notifyRecordReceived​(java.lang.String deviceId)
      Called to notify that we received a signal from deviceId.
      long setTimeout​(long tout)
      Changes the timeout.
      void uninstallFrom​(de.iip_ecosphere.platform.transport.connectors.TransportConnector connector)
      Uninstalls the two stored callbacks from connector.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • timeout

        private long timeout
      • received

        private java.util.Map<java.lang.String,​java.lang.Long> received
      • metricsCallback

        private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> metricsCallback
      • statusCallback

        private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> statusCallback
    • Constructor Detail

      • HeartbeatWatcher

        public HeartbeatWatcher()
    • Method Detail

      • createMetricsReceptionCallback

        public de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> createMetricsReceptionCallback()
        Creates a reception callback to be used with StreamNames.SERVICE_METRICS or StreamNames.RESOURCE_METRICS. You may also directly call notifyRecordReceived(String).
        Returns:
        the reception callback
      • createStatusReceptionCallback

        public de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> createStatusReceptionCallback()
        Creates a reception callback to be used with StreamNames.STATUS_STREAM. You may also directly call notifyRecordReceived(String).
        Returns:
        the reception callback
      • installInto

        public void installInto​(de.iip_ecosphere.platform.transport.connectors.TransportConnector connector)
                         throws java.io.IOException
        Creates two reception callbacks and installs them into connector. Stores the callbacks in this class.
        Parameters:
        connector - the connector to install the callbacks into
        Throws:
        java.io.IOException - if installation fails
      • uninstallFrom

        public void uninstallFrom​(de.iip_ecosphere.platform.transport.connectors.TransportConnector connector)
                           throws java.io.IOException
        Uninstalls the two stored callbacks from connector. Deletes the callbacks from this class.
        Parameters:
        connector - the connector to uninstall the callbacks from
        Throws:
        java.io.IOException - if uninstallation fails
      • notifyRecordReceived

        public void notifyRecordReceived​(java.lang.String deviceId)
        Called to notify that we received a signal from deviceId.
        Parameters:
        deviceId - the deviceId we received a signal/event from
      • notifyRecordDeleted

        public void notifyRecordDeleted​(java.lang.String deviceId)
        Called to notify that we received a deletion signal from deviceId.
        Parameters:
        deviceId - the deviceId we received a signal/event from
      • deleteOutdated

        public void deleteOutdated​(java.util.function.Consumer<java.lang.String> outdatedHandler)
        Deletes outdated entries and informs outdatedHandler about the removed entry. To be used in an existing timer. Uses timeout as timeout for entries.
        Parameters:
        outdatedHandler - the outdated handler
      • deleteOutdated

        public void deleteOutdated​(long timeout,
                                   java.util.function.Consumer<java.lang.String> outdatedHandler)
        Deletes outdated entries and informs outdatedHandler about the removed entry. To be used in an existing timer.
        Parameters:
        timeout - for deletion in ms
        outdatedHandler - the outdated handler
      • getDeviceCount

        public int getDeviceCount()
        Returns the number of devices known to this class.
        Returns:
        the number of devices
      • clear

        public void clear()
        Clears all devices/entries.
      • setTimeout

        public long setTimeout​(long tout)
        Changes the timeout.
        Parameters:
        tout - the timeout in ms
        Returns:
        the timeout set before calling this method