Class JsonConfigurationStore
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
The JSON object described by this file represents the root directory. If an entry does not start with a slash, it represents the key of a key value pair. If it does starts with a slash, the value is another JSON object that describes the respective subdirectory.
The component reads the initial values from File
passed
to the constructor. During application bootstrap, it
intercepts the Start
event using a handler with priority
999999. When receiving this event, it fires all known preferences
values on the channels of the start event as a
InitialPreferences
event, using a new EventPipeline
and waiting for its completion. Then, allows the intercepted
Start
event to continue.
Components that depend on configuration values define handlers
for ConfigurationUpdate
events and adapt themselves to the values
received. Note that due to the intercepted Start
event, the initial
preferences values are received before the Start
event, so
components’ configurations can be rearranged before they actually
start doing something.
Besides initially publishing the stored preferences values,
the component also listens for ConfigurationUpdate
events
on its channel and updates the JSON file (may be suppressed).
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Fields inherited from class org.jgrapes.util.NightConfigStore
config, initialChannels, logger
Fields inherited from class org.jgrapes.util.ConfigurationStore
NUMBER
-
Constructor Summary
ConstructorDescriptionJsonConfigurationStore
(Channel componentChannel, File file) Creates a new component with its channel set to the given channel and the given file.JsonConfigurationStore
(Channel componentChannel, File file, boolean update) Creates a new component with its channel set to the given channel and the given file.JsonConfigurationStore
(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
Methods inherited from class org.jgrapes.util.NightConfigStore
isNode, onConfigurationUpdate, onFileChanged, onStart, structured
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
-
Constructor Details
-
JsonConfigurationStore
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
-
JsonConfigurationStore
public JsonConfigurationStore(Channel componentChannel, File file, boolean update) throws IOException 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
-
JsonConfigurationStore
public JsonConfigurationStore(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.
-