Class PreferencesStore
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
Preferences
.Preferences are maps of key value pairs that are associated with a path. A common base path is passed to the component on creation. The application’s configuration information is stored using paths relative to that base path.
The component reads the initial values from the Java Preferences
tree denoted by the base path. 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 preferences store (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.ConfigurationStore
NUMBER
-
Constructor Summary
ConstructorDescriptionPreferencesStore
(Channel componentChannel, Class<?> appClass) Creates a new component with its channel set to the given channel and a base path derived from the given class.PreferencesStore
(Channel componentChannel, Class<?> appClass, boolean update) Allows the creation of a “read-only” store. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Merges and saves configuration updates.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)
.Return the values for a given path if they exist.Methods inherited from class org.jgrapes.util.ConfigurationStore
as, asBoolean, asInstant, asNumber, asString, flatten, mergeValue, structure, structure
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
-
PreferencesStore
Creates a new component with its channel set to the given channel and a base path derived from the given class.- Parameters:
componentChannel
- the channelappClass
- the application class; the base path is formed by replacing each dot in the class’s package’s full name with a slash, prepending a slash, and appending “/PreferencesStore
”.
-
PreferencesStore
Allows the creation of a “read-only” store.- Parameters:
componentChannel
- the channelappClass
- the application class; the base path is formed by replacing each dot in the class’s package’s full name with a slash, prepending a slash, and appending “/PreferencesStore
”.update
- whether to update the store whenConfigurationUpdate
events are received- See Also:
-
-
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 BackingStoreException Merges and saves configuration updates.- Parameters:
event
- the event- Throws:
IOException
- Signals that an I/O exception has occurred.BackingStoreException
-
values
Description copied from class:ConfigurationStore
Return the values for a given path if they exist.This method should only be used in cases where configuration values are needed before the
InitialConfiguration
event is fired, e.g. while creating the component tree.- Overrides:
values
in classConfigurationStore
- Parameters:
path
- the path- Returns:
- the values, if defined for the given path
-
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
-