Class DatumDataSourceSupport
java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.service.support.DatumDataSourceSupport
- All Implemented Interfaces:
net.solarnetwork.service.Identifiable
Helper class for
DatumDataSource and
MultiDatumDataSource implementations to
extend.- Since:
- 2.0
- Version:
- 1.1
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThepublishDeviceInfoMetadataproperty default value.static final longThesubSampleStartDelayproperty default value.A transform properties instance that can be used to signal "sub-sampling" mode to the transform service.Fields inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
logFields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddSourceMetadata(String sourceId, net.solarnetwork.domain.datum.GeneralDatumMetadata meta) Add source metadata using the configuredDatumMetadataService(if available).protected NodeDatumapplyDatumFilter(NodeDatum datum, Map<String, Object> props) Apply the configured datum filter service to a given datum.booleanSupport theDeviceInfoProviderpublish setting.static final voidClear the source metadata cache.net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> Get a datum filter service to use.net.solarnetwork.service.OptionalService<DatumMetadataService> Get the configuredDatumMetadataService.net.solarnetwork.service.OptionalService<DatumQueue> Get the datum queue.net.solarnetwork.service.OptionalService<DatumService> Get the datum service.protected List<net.solarnetwork.settings.SettingSpecifier> Get setting specifiers for device info metadata publishing support.Get the expression configurations.intGet the number of configuredexpressionConfigselements.protected List<net.solarnetwork.settings.SettingSpecifier> Get setting specifiers for theuidandgroupUidproperties.Get a sub-sample frequency at which to request datum.protected List<net.solarnetwork.settings.SettingSpecifier> Get setting specifiers for the sub-sample supporting properties.longGet the sub-sample start delay.org.springframework.scheduling.TaskSchedulerGet the task scheduler.booleanGet the desired device info metadata publish mode.protected booleanTest if sub-sampling is currently active.protected final voidofferDatumCapturedEvent(NodeDatum datum) Offer a non-persisted datum event to the configuredDatumQueue, if available.protected voidpopulateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs) Evaluate a set of expression configurations and store the results as properties on a datum.protected voidpopulateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs, Object root) Evaluate a set of expression configurations and store the results as properties on a datum.protected voidreadSubSampleDatum(DatumDataSource dataSource) Read a sub-sample datum value.protected voidsaveMetadata(String sourceId) Save theBasicIdentifiable.getMetadata()data as datum source metadata.voidsetDatumFilterService(net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> datumFilterService) Set a datum filter service to use.voidsetDatumMetadataService(net.solarnetwork.service.OptionalService<DatumMetadataService> datumMetadataService) Set aDatumMetadataServiceto use for managing datum metadata.voidsetDatumQueue(net.solarnetwork.service.OptionalService<DatumQueue> datumQueue) Set the datum queue.voidsetDatumService(net.solarnetwork.service.OptionalService<DatumService> datumService) Set the datum service.voidsetExpressionConfigs(ExpressionConfig[] expressionConfigs) Set the expression configurations to use.voidsetExpressionConfigsCount(int count) Adjust the number of configuredExpressionConfigelements.voidsetPublishDeviceInfoMetadata(boolean publishDeviceInfoMetadata) Get the desired device info metadata publish mode.voidsetSubSampleFrequency(Long subSampleFrequency) Set a sub-sample frequency at which to request datum.voidsetSubSampleStartDelay(long subSampleStartDelay) Set the sub-sample start delay.voidsetTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Set the task scheduler.protected ScheduledFuture<?> startSubSampling(DatumDataSource dataSource) Schedule sub-sampling with the given data source.protected voidStop any running sub-sampling task.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, getUid
-
Field Details
-
SUB_SAMPLE_PROPS
A transform properties instance that can be used to signal "sub-sampling" mode to the transform service. -
DEFAULT_SUBSAMPLE_START_DELAY
public static final long DEFAULT_SUBSAMPLE_START_DELAYThesubSampleStartDelayproperty default value.- See Also:
-
DEFAULT_PUBLISH_DEVICE_INFO_METADATA
public static final boolean DEFAULT_PUBLISH_DEVICE_INFO_METADATAThepublishDeviceInfoMetadataproperty default value.- See Also:
-
-
Constructor Details
-
DatumDataSourceSupport
public DatumDataSourceSupport()Default constructor.
-
-
Method Details
-
clearSourceMetadataCache
public static final void clearSourceMetadataCache()Clear the source metadata cache.This is designed to support testing primarily.
- Since:
- 1.1
-
offerDatumCapturedEvent
Offer a non-persisted datum event to the configuredDatumQueue, if available.- Parameters:
datum- the datum that was captured
-
addSourceMetadata
protected boolean addSourceMetadata(String sourceId, net.solarnetwork.domain.datum.GeneralDatumMetadata meta) Add source metadata using the configuredDatumMetadataService(if available). The metadata will be cached so that subsequent calls to this method with the same metadata value will not try to re-save the unchanged value. This method will catch all exceptions and silently discard them.- Parameters:
sourceId- the source ID to add metadata to; place holders will be resolved viaBaseIdentifiable.resolvePlaceholders(String)meta- the metadata to add- Returns:
- true if the metadata was saved successfully, or does not need to be updated
-
getIdentifiableSettingSpecifiers
Get setting specifiers for theuidandgroupUidproperties.- Returns:
- list of setting specifiers
-
getSubSampleSettingSpecifiers
Get setting specifiers for the sub-sample supporting properties.- Returns:
- list of setting specifiers
-
getDeviceInfoMetadataSettingSpecifiers
Get setting specifiers for device info metadata publishing support.- Returns:
- list of settings
-
canPublishDeviceInfo
public boolean canPublishDeviceInfo()Support theDeviceInfoProviderpublish setting.- Returns:
- the
isPublishDeviceInfoMetadata()value
-
startSubSampling
Schedule sub-sampling with the given data source.- Parameters:
dataSource- the data source- Returns:
- the scheduled future or null if sub-sampling support is not configured; canceling this will stop the sub-sampling task
- See Also:
-
readSubSampleDatum
Read a sub-sample datum value.This method is invoked by a task scheduled after calling
startSubSampling(DatumDataSource). It simply callsDatumDataSource.readCurrentDatum(). Extending classes may want to override this behavior.- Parameters:
dataSource- the data source previously passed tostartSubSampling(DatumDataSource)
-
stopSubSampling
protected void stopSubSampling()Stop any running sub-sampling task.- See Also:
-
isSubSampling
protected boolean isSubSampling()Test if sub-sampling is currently active.- Returns:
- true if sub-sampling is active
-
applyDatumFilter
Apply the configured datum filter service to a given datum.- Parameters:
datum- the datum to possibly filterprops- optional transform properties to pass toDatumFilterService.filter(net.solarnetwork.domain.datum.Datum, DatumSamplesOperations, Map)- Returns:
- the same datum, possibly transformed, or null if the datum has been filtered out completely
-
populateExpressionDatumProperties
protected void populateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs) Evaluate a set of expression configurations and store the results as properties on a datum.This method will create a new
ExpressionRootinstance for the expression root object and pass that topopulateExpressionDatumProperties(MutableNodeDatum, ExpressionConfig[], Object).- Parameters:
d- the datum to store the results of expression evaluations onexpressionConfs- the expression configurations- See Also:
-
populateExpressionDatumProperties
protected void populateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs, Object root) Evaluate a set of expression configurations and store the results as properties on a datum.- Parameters:
d- the datum to store the results of expression evaluations onexpressionConfs- the expression configurationsroot- the expression root object
-
saveMetadata
Save theBasicIdentifiable.getMetadata()data as datum source metadata.- Parameters:
sourceId- the source ID to save the metadata on- Since:
- 1.1
-
getDatumMetadataService
Get the configuredDatumMetadataService.- Returns:
- the service to use
-
setDatumMetadataService
public void setDatumMetadataService(net.solarnetwork.service.OptionalService<DatumMetadataService> datumMetadataService) Set aDatumMetadataServiceto use for managing datum metadata.- Parameters:
datumMetadataService- the service to use
-
getTaskScheduler
public org.springframework.scheduling.TaskScheduler getTaskScheduler()Get the task scheduler.- Returns:
- the task scheduler
-
setTaskScheduler
public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Set the task scheduler.- Parameters:
taskScheduler- the task scheduler to set
-
getSubSampleFrequency
Get a sub-sample frequency at which to request datum.- Returns:
- the sub-sample frequency, in milliseconds, or null or anything less than 1 to disable sub-sampling
-
setSubSampleFrequency
Set a sub-sample frequency at which to request datum.This is designed to work with a
setDatumFilterService(OptionalFilterableService)transformer that performs down-sampling of higher frequency data.- Parameters:
subSampleFrequency- the frequency, to set, in milliseconds
-
getSubSampleStartDelay
public long getSubSampleStartDelay()Get the sub-sample start delay.- Returns:
- the delay, in milliseconds
-
setSubSampleStartDelay
public void setSubSampleStartDelay(long subSampleStartDelay) Set the sub-sample start delay.- Parameters:
subSampleStartDelay- the sub-sample start delay to set, in milliseconds
-
getDatumFilterService
public net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> getDatumFilterService()Get a datum filter service to use.- Returns:
- the service
-
setDatumFilterService
public void setDatumFilterService(net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> datumFilterService) Set a datum filter service to use.- Parameters:
datumFilterService- the service to set
-
getExpressionConfigs
Get the expression configurations.- Returns:
- the expression configurations
-
setExpressionConfigs
Set the expression configurations to use.- Parameters:
expressionConfigs- the configs to use
-
getExpressionConfigsCount
public int getExpressionConfigsCount()Get the number of configuredexpressionConfigselements.- Returns:
- the number of
expressionConfigselements
-
setExpressionConfigsCount
public void setExpressionConfigsCount(int count) Adjust the number of configuredExpressionConfigelements.Any newly added element values will be set to new
ExpressionConfiginstances.- Parameters:
count- The desired number ofexpressionConfigselements.
-
isPublishDeviceInfoMetadata
public boolean isPublishDeviceInfoMetadata()Get the desired device info metadata publish mode.- Returns:
- true to publish device metadata; defaults to
DEFAULT_PUBLISH_DEVICE_INFO_METADATA
-
setPublishDeviceInfoMetadata
public void setPublishDeviceInfoMetadata(boolean publishDeviceInfoMetadata) Get the desired device info metadata publish mode.- Parameters:
publishDeviceInfoMetadata- true to publish device metadata once, after the first datum has been captured
-
getDatumQueue
Get the datum queue.- Returns:
- the queue
-
setDatumQueue
Set the datum queue.- Parameters:
datumQueue- the queue to set
-
getDatumService
Get the datum service.- Returns:
- the datum service
-
setDatumService
Set the datum service.- Parameters:
datumService- the datum service
-