Skip to content

Commit

Permalink
Change channels used for firing configuration update events.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed Apr 25, 2024
1 parent 1cf0af7 commit c77782b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions org.jgrapes.util/src/org/jgrapes/util/NightConfigStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class NightConfigStore extends ConfigurationStore {
= Logger.getLogger(NightConfigStore.class.getName());

protected FileConfig config;
protected Channel[] initialChannels;

/**
* Creates a new component with its channel set to the given
Expand Down Expand Up @@ -128,18 +129,21 @@ public NightConfigStore(Channel componentChannel, File file,
/**
* If watching the configuration file is enabled, fire
* a {@link ConfigurationUpdate} event with the complete
* configuration when the file changes.
* configuration when the file changes. The event is fired
* on the same channel(s) as the {@link InitialConfiguration}
* event.
*
* @param event the event
*/
@Handler(dynamic = true)
public void onFileChanged(FileChanged event) {
if (config.getNioPath().equals(event.path())
&& event.change() == FileChanged.Kind.MODIFIED) {
&& event.change() == FileChanged.Kind.MODIFIED
&& initialChannels != null) {
config.load();
ConfigurationUpdate updEvt = new ConfigurationUpdate();
addPrefs(updEvt, "/", config);
fire(updEvt);
fire(updEvt, initialChannels);
}
}

Expand Down Expand Up @@ -228,7 +232,8 @@ public void onStart(Start event)
throws BackingStoreException, InterruptedException {
ConfigurationUpdate updEvt = new InitialConfiguration();
addPrefs(updEvt, "/", config);
newEventPipeline().fire(updEvt, event.channels()).get();
initialChannels = event.channels();
newEventPipeline().fire(updEvt, initialChannels).get();
}

private void addPrefs(ConfigurationUpdate updEvt, String path,
Expand Down

0 comments on commit c77782b

Please sign in to comment.