Ejemplo n.º 1
0
  private static void scanForUpdates(final File contextRoot, final WebAppContext context) {
    List<File> scanList = new ArrayList<File>();

    scanList.add(new File(contextRoot, "WEB-INF/web.xml"));
    findFiles(".class", new File(contextRoot, "WEB-INF/classes"), scanList);
    findFiles(".jar", new File(contextRoot, "WEB-INF/lib"), scanList);

    logger.info("Starting autoreloading scanner... ");

    Scanner scanner = new Scanner();
    scanner.setScanInterval(Configurations.getInteger("refine.scanner.period", 1));
    scanner.setScanDirs(scanList);
    scanner.setReportExistingFilesOnStartup(false);

    scanner.addListener(
        new Scanner.BulkListener() {
          @Override
          public void filesChanged(@SuppressWarnings("rawtypes") List changedFiles) {
            try {
              logger.info("Stopping context: " + contextRoot.getAbsolutePath());
              context.stop();

              logger.info("Starting context: " + contextRoot.getAbsolutePath());
              context.start();

              configure(context);
            } catch (Exception ex) {
              throw new RuntimeException(ex);
            }
          }
        });

    scanner.start();
  }
Ejemplo n.º 2
0
  /**
   * add source scanner to restart server when source change
   *
   * @param web
   * @param webAppClassPath
   * @param scanIntervalSeconds
   */
  private static void initScanner(final WebAppContext web, final Configs config) {

    int scanIntervalSeconds = config.getScanIntervalSeconds();

    final ArrayList<File> scanList = new ArrayList<File>();

    System.err.println("init scanning folders...");
    if (config.getScanlist() != null) {
      String[] items = config.getScanlist().split(File.pathSeparator);
      for (String item : items) {
        File f = new File(item);
        scanList.add(f);
        System.err.println("add to scan list:" + item);
      }
    }

    // startScanner
    Scanner scanner = new Scanner();
    scanner.setScanInterval(scanIntervalSeconds);
    scanner.setScanDirs(scanList);
    scanner.setRecursive(true);
    scanner.setReportExistingFilesOnStartup(true);
    scanner.addListener(new RJRFileChangeListener(web, config));
    System.err.println("Starting scanner at interval of " + scanIntervalSeconds + " seconds.");
    scanner.start();
  }