Class DefaultDatumQueue

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.runtime.DefaultDatumQueue
All Implemented Interfaces:
Thread.UncaughtExceptionHandler, DatumQueue, net.solarnetwork.service.Identifiable, net.solarnetwork.settings.SettingSpecifierProvider

public class DefaultDatumQueue extends BaseIdentifiable implements DatumQueue, net.solarnetwork.settings.SettingSpecifierProvider, Thread.UncaughtExceptionHandler
Default implementation of DatumQueue.

Datum passed to offer(NodeDatum) will be persisted via one of the configured DatumDao services, while Datum received via offer(NodeDatum, boolean) with persist set to false will not be persisted. All datum will then be passed to all registered consumers.

The directConsumer passed to the constructor will receive datum after filters have been applied, sequentially in queue order directly on the queue processing thread.

Each registered Consumer will receive datum sequentially in queue order via a single thread.

Since:
1.89
Version:
2.1
Author:
matt
  • Field Details

    • DEFAULT_QUEUE_DELAY_MS

      public static final long DEFAULT_QUEUE_DELAY_MS
      The default value for the queueDelayMs property.
      See Also:
    • DEFAULT_STARTUP_DELAY_MS

      public static final long DEFAULT_STARTUP_DELAY_MS
      The default value for the startupDelayMs property.
      See Also:
    • DEFAULT_STAT_LOG_FREQUENCY

      public static final int DEFAULT_STAT_LOG_FREQUENCY
      The default statisticLogFrequency property.
      See Also:
  • Constructor Details

    • DefaultDatumQueue

      public DefaultDatumQueue(DatumDao nodeDatumDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin)
      Constructor.
      Parameters:
      nodeDatumDao - the node datum DAO to use
      eventAdmin - the event admin
      Throws:
      IllegalArgumentException - if any argument is null
    • DefaultDatumQueue

      public DefaultDatumQueue(DatumDao nodeDatumDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin, net.solarnetwork.service.OptionalService<Consumer<NodeDatum>> directConsumer)
      Constructor.
      Parameters:
      nodeDatumDao - the node datum DAO to use
      eventAdmin - the event admin
      directConsumer - the direct consumer, which is invoked directly on the queue processor thread, after filters are applied but before the DatumDataSource.EVENT_TOPIC_DATUM_CAPTURED is posted and before any consumers added via addConsumer(Consumer)
      Throws:
      IllegalArgumentException - if any argument is null
      Since:
      2.1
  • Method Details

    • startup

      public void startup()
      Startup once configured.
    • shutdown

      public void shutdown()
      Shutdown after no longer needed.
    • offer

      public boolean offer(NodeDatum datum)
      Description copied from interface: DatumQueue
      Offer a new datum to the queue, with persistence enabled.
      Specified by:
      offer in interface DatumQueue
      Parameters:
      datum - the datum to offer
      Returns:
      true if the datum was accepted
    • offer

      public boolean offer(NodeDatum datum, boolean persist)
      Description copied from interface: DatumQueue
      Offer a new datum to the queue, optionally persisting.
      Specified by:
      offer in interface DatumQueue
      Parameters:
      datum - the datum to offer
      persist - true to persist, or false to only pass to consumers
      Returns:
      true if the datum was accepted
    • addConsumer

      public void addConsumer(Consumer<NodeDatum> consumer)
      Description copied from interface: DatumQueue
      Register a consumer to receive processed datum.
      Specified by:
      addConsumer in interface DatumQueue
      Parameters:
      consumer - the consumer to register
    • removeConsumer

      public void removeConsumer(Consumer<NodeDatum> consumer)
      Description copied from interface: DatumQueue
      De-register a previously registered consumer.
      Specified by:
      removeConsumer in interface DatumQueue
      Parameters:
      consumer - the consumer to remove
    • uncaughtException

      public void uncaughtException(Thread t, Throwable e)
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
    • getSettingUid

      public String getSettingUid()
      Specified by:
      getSettingUid in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getSettingSpecifiers

      public List<net.solarnetwork.settings.SettingSpecifier> getSettingSpecifiers()
      Specified by:
      getSettingSpecifiers in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getStartupDelayMs

      public long getStartupDelayMs()
      Get the processing startup delay, in milliseconds.
      Returns:
      the startup delay; defaults to DEFAULT_STARTUP_DELAY_MS
    • setStartupDelayMs

      public void setStartupDelayMs(long startupDelayMs)
      Set the processing startup delay, in milliseconds.
      Parameters:
      startupDelayMs - the delay to set
    • getQueueDelayMs

      public long getQueueDelayMs()
      Get the queue delay, in milliseconds.
      Returns:
      the delay; defaults to DEFAULT_QUEUE_DELAY_MS
    • setQueueDelayMs

      public void setQueueDelayMs(long queueDelayMs)
      Set the queue delay, in milliseconds.
      Parameters:
      queueDelayMs - the delay to set; setting to anything less than 1 essentially disables the delay
    • getDatumFilterService

      public net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> getDatumFilterService()
      Set the configured transform service.
      Returns:
      the transform service, or null
    • setDatumFilterService

      public void setDatumFilterService(net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> transformService)
      Set the configured transform service.
      Parameters:
      transformService - the transform service to set
    • getTransformServiceUid

      public String getTransformServiceUid()
      Get the transform service filter UID.
      Returns:
      the service UID
    • setTransformServiceUid

      public void setTransformServiceUid(String uid)
      Set the transform service filter UID.
      Parameters:
      uid - the service UID
    • getNodeDatumDao

      public DatumDao getNodeDatumDao()
      Get the DAO to persist node datum with.
      Returns:
      the DAO
    • getStatisticLogFrequency

      public int getStatisticLogFrequency()
      Get the statistics log frequency.
      Returns:
      the frequency
    • setStatisticLogFrequency

      public void setStatisticLogFrequency(int logFrequency)
      Set the statistics log frequency.
      Parameters:
      logFrequency - the frequency to set
    • getDatumProcessorExceptionHandler

      public Thread.UncaughtExceptionHandler getDatumProcessorExceptionHandler()
      Get an exception handler for the datum processor.
      Returns:
      the exception handler, or null
    • setDatumProcessorExceptionHandler

      public void setDatumProcessorExceptionHandler(Thread.UncaughtExceptionHandler datumProcessorExceptionHandler)
      Set an exception handler for the datum processor.
      Parameters:
      datumProcessorExceptionHandler - the handler to set
    • getStats

      public net.solarnetwork.util.StatCounter getStats()
      Get the internal statistics.
      Returns:
      the stats
      See Also: