Menu

JFig update event not getting fired

Help
2014-08-25
2014-08-26
  • prateekjain jain

    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.

     
    • Bruce Conrad

      Bruce Conrad - 2014-08-26

      One other thing to consider. I generally have some sort of GUI interface or
      web service on my applications that will call JFig initialize. I realize
      that's not exactly what you're looking for but it will at least give you a
      manual way to process the updated files.
      On Aug 25, 2014 12:47 AM, "prateekjain jain" prateekjainaa@users.sf.net
      wrote:

      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/

       

Log in to post a comment.