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
ConstructorsConstructorDescriptionPreferencesStore(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 TypeMethodDescriptionvoidMerges and saves configuration updates.voidIntercepts theStartevent and fires aConfigurationUpdateevent.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, structureMethods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods 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, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 whenConfigurationUpdateevents are received- See Also:
-
-
Method Details
-
onStart
@Handler(priority=999999, channels=Channel.class) public void onStart(Start event) throws BackingStoreException, InterruptedException Intercepts theStartevent and fires aConfigurationUpdateevent.- 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:ConfigurationStoreReturn the values for a given path if they exist.This method should only be used in cases where configuration values are needed before the
InitialConfigurationevent is fired, e.g. while creating the component tree.- Overrides:
valuesin classConfigurationStore- Parameters:
path- the path- Returns:
- the values, if defined for the given path
-
structured
Description copied from class:ConfigurationStoreReturn the properties for a given path if they exists as structured data, seeConfigurationStore.structure(Map).- Overrides:
structuredin classConfigurationStore- Parameters:
path- the path- Returns:
- the values, if defined for the given path
-