private void startFileMonitor(long scanInterval) throws FileSystemException {
   FileSystemManager fsManager = VFS.getManager();
   FileObject listenFile = fsManager.resolveFile(propertyFile.getAbsolutePath());
   DefaultFileMonitor defaultFileMonitor = new DefaultFileMonitor(new ServiceIdFileMonitor(this));
   defaultFileMonitor.setDelay(scanInterval);
   defaultFileMonitor.addFile(listenFile);
   defaultFileMonitor.start();
   LOGGER.info("Started file monitor on " + propertyFile.getAbsolutePath());
 }
Пример #2
0
  /** @param aLauncher Launcher being used in background */
  public NuxeoLauncherGUI(NuxeoLauncher aLauncher) {
    launcher = aLauncher;
    // Set OS-specific decorations
    if (PlatformUtils.isMac()) {
      System.setProperty("apple.laf.useScreenMenuBar", "true");
      System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
      System.setProperty("com.apple.mrj.application.live-resize", "true");
      System.setProperty("com.apple.macos.smallTabs", "true");
    }
    initFrame();
    dumpedConfigMonitor =
        new DefaultFileMonitor(
            new FileListener() {
              @Override
              public void fileDeleted(FileChangeEvent event) {
                // Ignore
              }

              @Override
              public void fileCreated(FileChangeEvent event) {
                updateNuxeoFrame();
              }

              @Override
              public void fileChanged(FileChangeEvent event) {
                updateNuxeoFrame();
              }

              private synchronized void updateNuxeoFrame() {
                waitForFrameLoaded();
                log.debug("Configuration changed. Reloading frame...");
                launcher.init();
                updateServerStatus();
                try {
                  Properties props = new Properties();
                  props.load(new FileReader(getConfigurationGenerator().getDumpedConfig()));
                  nuxeoFrame.updateLogsTab(props.getProperty("log.id"));
                } catch (IOException e) {
                  log.error(e);
                }
              }
            });
    try {
      dumpedConfigMonitor.setRecursive(false);
      FileObject dumpedConfig =
          VFS.getManager().resolveFile(getConfigurationGenerator().getDumpedConfig().getPath());
      dumpedConfigMonitor.addFile(dumpedConfig);
      dumpedConfigMonitor.start();
    } catch (FileSystemException e) {
      throw new RuntimeException("Couldn't find " + getConfigurationGenerator().getNuxeoConf(), e);
    }
  }
Пример #3
0
  public ConfigurationWatcher(ConfigChangeListener<C> configListener, Class<C> confClass) {
    this.configListener = configListener;
    this.confClass = confClass;
    this.confFilePath = ConfigurationManager.getConfFilePath(confClass);

    try {
      FileSystemManager fsManager = VFS.getManager();
      FileObject file = fsManager.resolveFile(this.confFilePath);
      fileMonitor = new DefaultFileMonitor(this);
      fileMonitor.setRecursive(false);
      fileMonitor.addFile(file);
      fileMonitor.start();

      this.notifyListener();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void killLogstashAgent(int logAgentNumber, String logstashLogPath) {

    FileObject listendir;
    CustomFileListener listener = new CustomFileListener();
    long TIMEOUT_BETWEEN_FILE_QUERYING = 1000;
    long LOOP_TIMEOUT_IN_MILLIS = 10 * 1000;

    try {
      FileSystemManager fileSystemManager = VFS.getManager();
      listendir = fileSystemManager.resolveFile(logstashLogPath);
    } catch (FileSystemException e) {
      e.printStackTrace();
      return;
    }

    DefaultFileMonitor fm = new DefaultFileMonitor(listener);
    fm.setRecursive(true);
    fm.addFile(listendir);
    fm.setDelay(TIMEOUT_BETWEEN_FILE_QUERYING);
    fm.start();

    LogUtils.log("waiting to destroy logger");
    long startTimeMillis = System.currentTimeMillis();

    while (true) {

      if (!listener.isProcessUp()) {
        break;
      }

      listener.setProcessUp(false);

      try {
        TimeUnit.MILLISECONDS.sleep(LOOP_TIMEOUT_IN_MILLIS);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    long endTimeMillis = System.currentTimeMillis();
    LogUtils.log("destroying logstash agent " + logAgentNumber);
    LogUtils.log("waited " + (endTimeMillis - startTimeMillis) / 1000 + " seconds");
    fm.stop();

    //        File logstashOutputFile = new File(logstashLogPath);

    if (logAgentNumber == 1) {

      process.destroy();
      process = null;
    } else {

      process2.destroy();
      process2 = null;
    }

    //        try {
    //            TimeUnit.SECONDS.sleep(5);
    //
    //            LogUtils.log("returning logstash config file to initial state");
    //            if(logAgentNumber == 1){
    //                IOUtils.replaceFileWithMove(new File(confFilePath), new File(backupFilePath));
    //                FileUtils.deleteQuietly(new File(backupFilePath));
    //            }
    //            else{
    //                IOUtils.replaceFileWithMove(new File(confFilePath2), new
    // File(backupFilePath2));
    //                FileUtils.deleteQuietly(new File(backupFilePath2));
    //
    //            }
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        } catch (InterruptedException e) {
    //            e.printStackTrace();
    //        }

    //        if(logstashOutputFile.exists()){
    //            FileUtils.deleteQuietly(logstashOutputFile);
    //        }
  }