Menu

Fwd: RE: [jfig:discussion] JFig update event not getting fired

Help
2014-08-26
2014-08-26
  • Bruce Conrad

    Bruce Conrad - 2014-08-26

    ---------- Forwarded message ----------
    From: "Conrad, Bruce A." conrad4@llnl.gov
    Date: Aug 25, 2014 9:48 AM
    Subject: RE: [jfig:discussion] JFig update event not getting fired
    To: "Bruce Conrad" baconrad@ultramondo.com, "prateekjain jain" prateekjainaa@users.sf.net
    Cc:

    The JFigListener is listening for changes to configuration values that are
    made via a call to JFig.getInstance().setValue(

    , <key>,
    <value>); It is not listening for file change events. The documentation for
    this may be a bit misleading. I may have attempted something like this in
    older versions. What version are you using? I do see some posts for how to
    watch for file change events which you could implement including an apache
    FileAlterationListener.

    Also, I see you are doing some interesting stuff with maintaining multiple
    JFig instances. Since the default implementation of JFig is a singleton, I
    would expect that only the last one would have any listeners in effect. The
    more recent versions of JFig (after 2.0) allow for multiple named
    instances. You should take a look at that as it may make your code simpler.
    The named instance is identified by a string (JFig.getInstance("JFIG1");
    ) so you might have to use a stringified version of your ICEXConfMapKey or
    maintain a map to use it.

    Also, I’d be interested to know who you and your company are, how long
    you’ve been using jfig, etc as I have no idea who is out there using it and
    am always eager to get feedback.

    (I will repost this on sourceforge discussion. My password is not working
    at the moment)

    From: baconrad@gmail.com [mailto:baconrad@gmail.com] On Behalf Of Bruce
    Conrad
    Sent: Monday, August 25, 2014 8:37 AM
    To: bconrad@llnl.gov
    Subject: Fwd: [jfig:discussion] JFig update event not getting fired

    ---------- Forwarded message ----------
    From: "prateekjain jain" prateekjainaa@users.sf.net
    Date: Aug 25, 2014 12:47 AM
    Subject: [jfig:discussion] JFig update event not getting fired
    To: "[jfig:discussion]" 293438@discussion.jfig.p.re.sf.net
    Cc:

    Hi,
    We are using jfig to load configuration files in a webapp deployed under
    tomcat 8.x. Everything is working fine and we are getting values as
    expected the only issue is once we change the files those are not getting
    reflected at runtime but if we restart the server then new values are
    available.

    I have attached the sample code below which we are using to load config
    files and attaching listeners:

    public class FileLoader implements JFigListener {

    private List<File> configurationFiles;

    private final static String DIR_TO_LOAD = FileUtils

        .getEvnProperty("ICEX_HOME") + "/conf/tenants/";
    

    private Map<ICEXConfMapKey, JFigImpl=""> configMap = new
    HashMap<ICEXConfMapKey, JFigImpl="">();

    private static FileLoader loader;

    public static FileLoader getInstance() {

    if(null==loader) {
    
        loader = new FileLoader();
    
    }
    
    return loader;
    

    }

    public Collection<JFigImpl> getFigObjects() {

    return configMap.values();
    

    }

    public void loadFile(File file) {

    ICEXConfMapKey key = makeICEXConfMapKey(file);
    
    JFigImpl fig = (JFigImpl)explicitLoad(file);
    
    configMap.put(key, fig);
    

    }

    public JFigIF explicitLoad(File file) {

    JFigLocatorIF i = new JFigLocator(file.getAbsolutePath());
    
    JFigIF fig = null;
    
    try {
    
        fig = JFig.initialize(i);
    
        fig.addConfigEventListener(loader);
    
    } catch (JFigException e) {
    
        // TODO Auto-generated catch block
    
        e.printStackTrace();
    
    }
    
    return fig;
    

    }

    public Map<ICEXConfMapKey, JFigImpl=""> getConfigMap() {

    return configMap;
    

    }

    private ICEXConfMapKey makeICEXConfMapKey(File file) {

    String tenantID = FileUtil.getTenantIDFromPath(file.getAbsolutePath());
    
    String moduleID = FileUtil.getModuleIDFromPath(file.getAbsolutePath());
    
    String fileName = file.getName();
    
    return new ICEXConfMapKey(tenantID, moduleID, fileName);
    

    }

    private void startup() {

    System.out.println("Starting to load configuration files");
    
    configurationFiles = FileUtils.getAllFilesFromDirectory(DIR_TO_LOAD);
    
    for (File f : configurationFiles) {
    
        if(ICEXConstants.MODULE_CONFIG_FILE_NAME.toString().equalsIgnoreCase(f.getName()))
    

    {

            System.out.println("Loading file " + f.getAbsolutePath());
    
            loadFile(f);
    
        }
    
    }
    
    System.out.println("Configuration file loading done");
    

    }

    public static void main(String[] args) {

    System.out.println("hhkjhh");
    
    FileLoader.getInstance();
    

    }

    @Override

    public void configurationUpdate(JFigEvent event) {

    System.err.println("Re-loading configurations");

    Collection<JFigImpl> figs = getFigObjects();

    for(JFigImpl f : figs) {

      try {
    
        f.reprocessConfiguration();
    
    } catch (JFigException e) {
    
        System.out.println("Failed to reload configurations");
    
        e.printStackTrace();
    
    }
    

    }

    }

    private FileLoader() {

    startup();
    

    }

    }

    It would be great if you have any pointers to this.


    JFig update event not getting fired
    https://sourceforge.net/p/jfig/discussion/293438/thread/3e297b7f/?limit=25#cf72


    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/jfig/discussion/293438/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/subscriptions/

     
  • prateekjain jain

    thanks for your feedback Bruce. Everything else is working fine for us. We are using 2.3.1 version of jfig. Although, the first thought was to use apache-commons only, but we were tempted to use jfig as; one of product we were evaluating for our business problem was using it.

     

Log in to post a comment.