[ 
https://issues.apache.org/jira/browse/CONFIGURATION-827?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17679594#comment-17679594
 ] 

Alla Gofman edited comment on CONFIGURATION-827 at 1/23/23 11:28 AM:
---------------------------------------------------------------------

I tried to register Custom Listener Adapter like this:

builder.getFileHandler().addFileHandlerListener(new 
FileHandlerListenerAdapter() {
@Override
public void saving(final FileHandler handler)

{ ... }

});

This doesn't work, because 

FileBasedConfigurationBuilder calls initResultInstance() and FileHandler 
replaced by new instance.

Then AutoSaveListener calls updateFileHandler(final FileHandler fh) 
so, only AutoSaveListener registered on new FH and not my custom listener.

 

Solution is:

builder.addEventListener(ConfigurationBuilderResultCreatedEvent.RESULT_CREATED, 
event -> {
builder.getFileHandler().addFileHandlerListener(new CustomListenerAdapter());
});

 

Bu this is not straight and obvious solution.
Please consider other approach.


was (Author: allag):
I tried to register listener like this:

builder.getFileHandler().addFileHandlerListener(new 
FileHandlerListenerAdapter() {
@Override
public void saving(final FileHandler handler)

{ ... }

});

 

This doesn't work, because 

FileBasedConfigurationBuilder calls initResultInstance() and FileHandler 
replaced by new instance.

Then AutoSaveListener calls updateFileHandler(final FileHandler fh) 
so, only AutoSaveListener registered on new FH and not my custom listener.

 

Otherwise enable access to 

currentFileHandler in FileBasedConfigurationBuilder 

> Enable to set custom AutoSaveListener or register FileHandlerListenerAdapter
> ----------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-827
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-827
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: File reloading
>    Affects Versions: 2.8.0
>            Reporter: Alla Gofman
>            Priority: Major
>
> I would like to extend AutoSaveListener (which package private)
> 1) override onEvent(final ConfigurationEvent event) behavior and set the 
> custom listener in FileBasedConfigurationBuilder.
> 2) register custom AutoSaveListener for saving() event.
> Both unavailable.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to