Package org.jgrapes.util
Class NightConfigStore
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.util.ConfigurationStore
org.jgrapes.util.NightConfigStore
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
- Direct Known Subclasses:
JsonConfigurationStore
,TomlConfigurationStore
,YamlConfigurationStore
A base class for configuration stored based on the
night config library.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.electronwill.nightconfig.core.file.FileConfig
protected Channel[]
protected static final Logger
Fields inherited from class org.jgrapes.util.ConfigurationStore
NUMBER
-
Constructor Summary
ConstructorDescriptionNightConfigStore
(Channel componentChannel, File file) Deprecated.NightConfigStore
(Channel componentChannel, File file, boolean update) Deprecated.NightConfigStore
(Channel componentChannel, File file, boolean update, boolean watch) Creates a new component with its channel set to the given channel and the given file. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Checks if the name is an entry for a node.void
Merges and saves configuration updates.void
onFileChanged
(FileChanged event) If watching the configuration file is enabled, fire aConfigurationUpdate
event with the complete configuration when the file changes.void
Intercepts theStart
event and fires aConfigurationUpdate
event.structured
(String path) Return the properties for a given path if they exists as structured data, seeConfigurationStore.structure(Map)
.Methods inherited from class org.jgrapes.util.ConfigurationStore
as, asBoolean, asInstant, asNumber, asString, flatten, mergeValue, structure, structure, values
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
logger
-
config
-
initialChannels
-
-
Constructor Details
-
NightConfigStore
Deprecated.Creates a new component with its channel set to the given channel and the given file.The component handles
ConfigurationUpdate
events andFileChanged
events for the configuration file (see- Throws:
IOException
-
NightConfigStore
@Deprecated public NightConfigStore(Channel componentChannel, File file, boolean update) throws IOException Deprecated.Creates a new component with its channel set to the given channel and the given file.The component handles
FileChanged
events for the configuration file (see- Throws:
IOException
-
NightConfigStore
public NightConfigStore(Channel componentChannel, File file, boolean update, boolean watch) throws IOException Creates a new component with its channel set to the given channel and the given file.If
update
istrue
, the configuration file is updated whenConfigurationUpdate
events are received.If
watch
istrue
,FileChanged
events are processed and the configuration file is reloaded when it changes. Note that the generation of theFileChanged
events must be configured independently (seeFileSystemWatcher
).- Parameters:
componentChannel
- the channelfile
- the file used to store the configurationupdate
- if the configuration file is to be updatedwatch
- ifFileChanged
events are to be processed- Throws:
IOException
- Signals that an I/O exception has occurred.
-
-
Method Details
-
onFileChanged
If watching the configuration file is enabled, fire aConfigurationUpdate
event with the complete configuration when the file changes.The event is fired on the same channel(s) as the
InitialConfiguration
event.- Parameters:
event
- the event
-
structured
Description copied from class:ConfigurationStore
Return the properties for a given path if they exists as structured data, seeConfigurationStore.structure(Map)
.- Overrides:
structured
in classConfigurationStore
- Parameters:
path
- the path- Returns:
- the values, if defined for the given path
-
isNode
Checks if the name is an entry for a node.- Parameters:
name
- the name- Returns:
- true, if is node
-
onStart
@Handler(priority=999999, channels=Channel.class) public void onStart(Start event) throws BackingStoreException, InterruptedException Intercepts theStart
event and fires aConfigurationUpdate
event.- Parameters:
event
- the event- Throws:
BackingStoreException
- the backing store exceptionInterruptedException
- the interrupted exception
-
onConfigurationUpdate
@Handler(dynamic=true) public void onConfigurationUpdate(ConfigurationUpdate event) throws IOException Merges and saves configuration updates.- Parameters:
event
- the event- Throws:
IOException
- Signals that an I/O exception has occurred.
-