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
-
Constructor Summary
ConstructorsConstructorDescriptionJsonConfigurationStore
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Merges and saves configuration updates.void
Intercepts theStart
event and fires aConfigurationUpdate
event.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, 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.- Parameters:
componentChannel
- the channelfile
- the file used to store the JSON- Throws:
org.jdrupes.json.JsonDecodeException
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.- Parameters:
componentChannel
- the channelfile
- the file used to store the JSON- Throws:
org.jdrupes.json.JsonDecodeException
IOException
-
-
Method Details
-
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.
-