Package net.solarnetwork.node.runtime
Class DefaultOperationalModesService
java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.runtime.DefaultOperationalModesService
- All Implemented Interfaces:
InstructionHandler,OperationalModesService,net.solarnetwork.service.Identifiable,net.solarnetwork.service.ServiceLifecycleObserver,net.solarnetwork.settings.SettingSpecifierProvider
public class DefaultOperationalModesService
extends BaseIdentifiable
implements OperationalModesService, InstructionHandler, net.solarnetwork.settings.SettingSpecifierProvider, net.solarnetwork.service.ServiceLifecycleObserver
Default implementation of
OperationalModesService.- Version:
- 2.1
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default rate at which to look for auto-expired modes, in seconds.static final longThe default startup delay value.static final LongAn expiration value meaning "no expiration".static final StringThe setting key for operational modes.static final StringThe setting key for operational mode expiration dates.Fields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTYFields inherited from interface net.solarnetwork.node.reactor.InstructionHandler
PARAM_MESSAGE, PARAM_SERVICE, PARAM_SERVICE_ARGUMENT, PARAM_SERVICE_RESULT, PARAM_STATUS_CODE, TOPIC_DEMAND_BALANCE, TOPIC_SET_CONTROL_PARAMETER, TOPIC_SET_OPERATING_STATE, TOPIC_SHED_LOAD, TOPIC_SIGNAL, TOPIC_SYSTEM_CONFIGUREFields inherited from interface net.solarnetwork.node.service.OperationalModesService
EVENT_PARAM_ACTIVE_OPERATIONAL_MODES, EVENT_TOPIC_OPERATIONAL_MODES_CHANGED, INSTRUCTION_PARAM_EXPIRATION, INSTRUCTION_PARAM_OPERATIONAL_MODE, TOPIC_DISABLE_OPERATIONAL_MODES, TOPIC_ENABLE_OPERATIONAL_MODES -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOperationalModesService(ConcurrentMap<String, Long> modeCache, net.solarnetwork.service.OptionalService<SettingDao> settingDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Constructor.DefaultOperationalModesService(net.solarnetwork.service.OptionalService<SettingDao> settingDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionGet the set of active operational modes.protected org.osgi.service.event.EventcreateOperationalModesChangedEvent(Set<String> activeModes) Create an operational modes changed event.disableOperationalModes(Set<String> modes) Disable a set of operational modes.enableOperationalModes(Set<String> modes) Enable a set of operational modes.enableOperationalModes(Set<String> modes, Instant expire) Enable a set of operational modes.voidManually run the auto-expire task.List<net.solarnetwork.settings.SettingSpecifier>net.solarnetwork.service.OptionalService<org.springframework.transaction.PlatformTransactionManager>Get the transaction manager.booleanhandlesTopic(String topic) Test if a topic is handled by this handler.booleanTest if a specific mode is active.protected final voidpostEvent(org.osgi.service.event.Event event) Post an event.processInstruction(Instruction instruction) Process an instruction.voidvoidvoidsetAutoExpireModesFrequency(int autoExpireModesFrequency) Set the frequency, in seconds, at which to look for auto-expired operational modes.voidsetStartupDelay(long startupDelay) A startup delay before posting an event of the active operational modes.voidsetTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Configure a task scheduler.voidsetTransactionManager(net.solarnetwork.service.OptionalService<org.springframework.transaction.PlatformTransactionManager> transactionManager) Set the transaction manager.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, 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
getGroupUid, getUidMethods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider
getMessageSource
-
Field Details
-
SETTING_OP_MODE
The setting key for operational modes.- See Also:
-
SETTING_OP_MODE_EXPIRE
The setting key for operational mode expiration dates.- Since:
- 1.1
- See Also:
-
DEFAULT_STARTUP_DELAY
public static final long DEFAULT_STARTUP_DELAYThe default startup delay value. -
DEFAULT_AUTO_EXPIRE_MODES_FREQUENCY
public static final int DEFAULT_AUTO_EXPIRE_MODES_FREQUENCYThe default rate at which to look for auto-expired modes, in seconds.- See Also:
-
NO_EXPIRATION
An expiration value meaning "no expiration".- Since:
- 1.3
-
-
Constructor Details
-
DefaultOperationalModesService
public DefaultOperationalModesService(net.solarnetwork.service.OptionalService<SettingDao> settingDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Constructor.- Parameters:
settingDao- the setting DAO to persist operational mode changes witheventAdmin- the event service to post notifications with- Throws:
IllegalArgumentException- ifsettingDaois null
-
DefaultOperationalModesService
public DefaultOperationalModesService(ConcurrentMap<String, Long> modeCache, net.solarnetwork.service.OptionalService<SettingDao> settingDao, net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Constructor.- Parameters:
modeCache- the cache to use for active mode trackingsettingDao- the setting DAO to persist operational mode changes witheventAdmin- the event service to post notifications with- Throws:
IllegalArgumentException- ifsettingDaoormodeCacheis null- Since:
- 1.3
-
-
Method Details
-
serviceDidStartup
public void serviceDidStartup()- Specified by:
serviceDidStartupin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
expireNow
public void expireNow()Manually run the auto-expire task.This is primarily designed to support testing.
-
serviceDidShutdown
public void serviceDidShutdown()- Specified by:
serviceDidShutdownin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
getSettingUid
- Specified by:
getSettingUidin interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
getDisplayName
- Specified by:
getDisplayNamein interfacenet.solarnetwork.service.Identifiable- Specified by:
getDisplayNamein interfacenet.solarnetwork.settings.SettingSpecifierProvider- Overrides:
getDisplayNamein classnet.solarnetwork.service.support.BasicIdentifiable
-
getSettingSpecifiers
- Specified by:
getSettingSpecifiersin interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
handlesTopic
Description copied from interface:InstructionHandlerTest if a topic is handled by this handler.- Specified by:
handlesTopicin interfaceInstructionHandler- Parameters:
topic- the topic- Returns:
- true only if this handler can execute the job for the given topic
-
processInstruction
Description copied from interface:InstructionHandlerProcess an instruction.- Specified by:
processInstructionin interfaceInstructionHandler- Parameters:
instruction- the instruction to process- Returns:
- the status for the instruction, or null if the instruction was not handled
-
isOperationalModeActive
Description copied from interface:OperationalModesServiceTest if a specific mode is active.Note that a null or empty
modeargument will be treated as testing if the default mode is active, which is always true.- Specified by:
isOperationalModeActivein interfaceOperationalModesService- Parameters:
mode- the mode to test; the mode can be prefixed with ! to test if the given mode is not active- Returns:
- true if
modeis active, or ifmodestarts with ! then true ifmodeis not active
-
activeOperationalModes
Description copied from interface:OperationalModesServiceGet the set of active operational modes.- Specified by:
activeOperationalModesin interfaceOperationalModesService- Returns:
- the active operational modes, never null
-
enableOperationalModes
Description copied from interface:OperationalModesServiceEnable a set of operational modes.- Specified by:
enableOperationalModesin interfaceOperationalModesService- Parameters:
modes- the modes to enable- Returns:
- the active operational modes, after activating
modes, never null
-
enableOperationalModes
Description copied from interface:OperationalModesServiceEnable a set of operational modes.- Specified by:
enableOperationalModesin interfaceOperationalModesService- Parameters:
modes- the modes to enableexpire- a date after whichmodesshould be automatically disabled, or null for no expiration- Returns:
- the active operational modes, after activating
modes, never null
-
disableOperationalModes
Description copied from interface:OperationalModesServiceDisable a set of operational modes.- Specified by:
disableOperationalModesin interfaceOperationalModesService- Parameters:
modes- the modes to disable- Returns:
- the active operational modes, after deactivating
modes, never null
-
createOperationalModesChangedEvent
Create an operational modes changed event.- Parameters:
activeModes- the active modes- Returns:
- the event
-
postEvent
protected final void postEvent(org.osgi.service.event.Event event) Post an event.- Parameters:
event- the event to post
-
setStartupDelay
public void setStartupDelay(long startupDelay) A startup delay before posting an event of the active operational modes.Note this requires a
setTaskScheduler(TaskScheduler)to be configured if set to anything > 0.- Parameters:
startupDelay- a startup delay, in milliseconds, or 0 for no delay; defaults toDEFAULT_STARTUP_DELAY
-
setTaskScheduler
public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Configure a task scheduler.This is required by
setStartupDelay(long)as well as for supporting auto-expiring modes.- Parameters:
taskScheduler- a task executor- See Also:
-
setAutoExpireModesFrequency
public void setAutoExpireModesFrequency(int autoExpireModesFrequency) Set the frequency, in seconds, at which to look for auto-expired operational modes.- Parameters:
autoExpireModesFrequency- the frequency, in seconds- Throws:
IllegalArgumentException- ifautoExpireModesFrequencyis less than 1- Since:
- 1.1
-
getTransactionManager
public net.solarnetwork.service.OptionalService<org.springframework.transaction.PlatformTransactionManager> getTransactionManager()Get the transaction manager.- Returns:
- the transaction manager to use
- Since:
- 1.3
-
setTransactionManager
public void setTransactionManager(net.solarnetwork.service.OptionalService<org.springframework.transaction.PlatformTransactionManager> transactionManager) Set the transaction manager.- Parameters:
transactionManager- the transaction manager to use- Since:
- 1.3
-