Package net.solarnetwork.node.runtime
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default value for thequeueDelayMsproperty.static final longThe default value for thestartupDelayMsproperty.static final intThe defaultstatisticLogFrequencyproperty.Fields inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
logFields inherited from interface net.solarnetwork.node.service.DatumQueue
EVENT_TOPIC_DATUM_ACQUIREDFields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultDatumQueue(DatumDao nodeDatumDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Constructor.DefaultDatumQueue(DatumDao nodeDatumDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin, net.solarnetwork.service.OptionalService<Consumer<NodeDatum>> directConsumer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConsumer(Consumer<NodeDatum> consumer) Register a consumer to receive processed datum.net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> Set the configured transform service.Get an exception handler for the datum processor.Get the DAO to persist node datum with.longGet the queue delay, in milliseconds.List<net.solarnetwork.settings.SettingSpecifier> longGet the processing startup delay, in milliseconds.intGet the statistics log frequency.net.solarnetwork.util.StatCountergetStats()Get the internal statistics.Get the transform service filter UID.booleanOffer a new datum to the queue, with persistence enabled.booleanOffer a new datum to the queue, optionally persisting.voidremoveConsumer(Consumer<NodeDatum> consumer) De-register a previously registered consumer.voidsetDatumFilterService(net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> transformService) Set the configured transform service.voidsetDatumProcessorExceptionHandler(Thread.UncaughtExceptionHandler datumProcessorExceptionHandler) Set an exception handler for the datum processor.voidsetQueueDelayMs(long queueDelayMs) Set the queue delay, in milliseconds.voidsetStartupDelayMs(long startupDelayMs) Set the processing startup delay, in milliseconds.voidsetStatisticLogFrequency(int logFrequency) Set the statistics log frequency.voidSet the transform service filter UID.voidshutdown()Shutdown after no longer needed.voidstartup()Startup once configured.voiduncaughtException(Thread t, Throwable e) Methods inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
baseIdentifiableSettings, baseIdentifiableSettings, getExpressionServices, getPlaceholderService, populateExpressionDatumProperties, resolvePlaceholders, resolvePlaceholders, setExpressionServices, setPlaceholderServiceMethods inherited from class net.solarnetwork.service.support.BasicIdentifiable
basicIdentifiableMetadataSettings, basicIdentifiableSettings, basicIdentifiableSettings, basicIdentifiableSettings, doubleMetadataValue, getDisplayName, getGroupUid, getGroupUID, getMessageSource, getMetadata, getMetadataCount, getUid, getUID, integerMetadataValue, metadataValue, numberMetadataValue, saveMetadataValue, saveMetadataValue, setDisplayName, setGroupUid, setGroupUID, setMessageSource, setMetadata, setMetadataCount, setUid, setUID, smartMetadataValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.service.Identifiable
getDisplayName, getGroupUid, getUidMethods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider
getDisplayName, getMessageSource, templateSettingSpecifiers
-
Field Details
-
DEFAULT_QUEUE_DELAY_MS
public static final long DEFAULT_QUEUE_DELAY_MSThe default value for thequeueDelayMsproperty.- See Also:
-
DEFAULT_STARTUP_DELAY_MS
public static final long DEFAULT_STARTUP_DELAY_MSThe default value for thestartupDelayMsproperty.- See Also:
-
DEFAULT_STAT_LOG_FREQUENCY
public static final int DEFAULT_STAT_LOG_FREQUENCYThe defaultstatisticLogFrequencyproperty.- 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 useeventAdmin- 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 useeventAdmin- the event admindirectConsumer- the direct consumer, which is invoked directly on the queue processor thread, after filters are applied but before theDatumDataSource.EVENT_TOPIC_DATUM_CAPTUREDis posted and before any consumers added viaaddConsumer(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
Description copied from interface:DatumQueueOffer a new datum to the queue, with persistence enabled.- Specified by:
offerin interfaceDatumQueue- Parameters:
datum- the datum to offer- Returns:
- true if the datum was accepted
-
offer
Description copied from interface:DatumQueueOffer a new datum to the queue, optionally persisting.- Specified by:
offerin interfaceDatumQueue- Parameters:
datum- the datum to offerpersist- true to persist, or false to only pass to consumers- Returns:
- true if the datum was accepted
-
addConsumer
Description copied from interface:DatumQueueRegister a consumer to receive processed datum.- Specified by:
addConsumerin interfaceDatumQueue- Parameters:
consumer- the consumer to register
-
removeConsumer
Description copied from interface:DatumQueueDe-register a previously registered consumer.- Specified by:
removeConsumerin interfaceDatumQueue- Parameters:
consumer- the consumer to remove
-
uncaughtException
- Specified by:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler
-
getSettingUid
- Specified by:
getSettingUidin interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
getSettingSpecifiers
- Specified by:
getSettingSpecifiersin interfacenet.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 than1essentially 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
Get the transform service filter UID.- Returns:
- the service UID
-
setTransformServiceUid
Set the transform service filter UID.- Parameters:
uid- the service UID
-
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
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:
-