Examples of DirWatcher


Examples of br.com.ingenieux.mojo.jbake.util.DirWatcher

    getLog().info(
        "Now listening for changes on path " + inputDirectory.getPath());

    initServer();

    DirWatcher dirWatcher = null;

    try {
      dirWatcher = new DirWatcher(inputDirectory);
      final AtomicBoolean done = new AtomicBoolean(false);
      final BufferedReader reader = new BufferedReader(
          new InputStreamReader(System.in));

      (new Thread() {
        @Override
        public void run() {
          try {
            getLog()
                .info("Running. Enter a blank line to finish. Anything else forces re-rendering.");

            while (true) {
              String line = reader.readLine();

              if (isBlank(line)) {
                break;
              }

              reRender();
            }
          } catch (Exception exc) {
            getLog().info("Ooops", exc);
          } finally {
            done.set(true);
          }
        }
      }).start();

      dirWatcher.start();

      do {
        Long result = dirWatcher.processEvents();

        if (null == result) {
          // do nothing on purpose
        } else if (result >= lastProcessed) {
          getLog().info("Refreshing");

          super.execute();

          lastProcessed = Long.valueOf(System.currentTimeMillis());
        }
      } while (!done.get());
    } catch (Exception exc) {
      getLog().info("Oops", exc);

      throw new MojoExecutionException("Oops", exc);
    } finally {
      getLog().info("Finishing");

      if (null != dirWatcher)
        dirWatcher.stop();

      stopServer();
    }
  }
View Full Code Here

Examples of br.com.ingenieux.mojo.jbake.util.DirWatcher

            done.set(true);
          }
        }
      }).start();

      DirWatcher dirWatcher = new DirWatcher(Paths.get(inputDirectory
          .getPath()));

      do {
        Boolean result = dirWatcher.processEvents();

        if (Boolean.FALSE.equals(result)) {
          Thread.sleep(1000);
        } else if (Boolean.TRUE.equals(result)) {
          getLog().info("Refreshing");
View Full Code Here

Examples of br.com.ingenieux.mojo.jbake.util.DirWatcher

            done.set(true);
          }
        }
      }).start();

      DirWatcher dirWatcher = new DirWatcher(Paths.get(inputDirectory
          .getPath()));

      do {
        Boolean result = dirWatcher.processEvents();

        if (Boolean.FALSE.equals(result)) {
          Thread.sleep(1000);
        } else if (Boolean.TRUE.equals(result)) {
          getLog().info("Refreshing");
View Full Code Here

Examples of com.cloudera.util.dirwatcher.DirWatcher

  }

  private DirWatcher createWatcher(File dir, final String regex,
      final int recurseDepth) {
    // 250 ms between checks
    DirWatcher watcher = new DirWatcher(dir, new RegexFileFilter(regex), 250);
    watcher.addHandler(new DirChangeHandler() {
      Map<String, Cursor> curmap = new HashMap<String, Cursor>();

      @Override
      public void fileCreated(File f) {
        if (f.isDirectory()) {
          if (recurseDepth <= 0) {
            LOG.debug("Tail dir will not read or recurse "
                + "into subdirectory " + f + ", this watcher recurseDepth: "
                + recurseDepth);
            return;
          }

          LOG.info("added dir " + f + ", recurseDepth: " + (recurseDepth - 1));
          DirWatcher watcher = createWatcher(f, regex, recurseDepth - 1);
          watcher.start();
          subdirWatcherMap.put(f.getPath(), watcher);
          subdirsAdded.incrementAndGet();
          return;
        }

        // Add a new file to the multi tail.
        LOG.info("added file " + f);
        Cursor c;
        if (startFromEnd && !dirChecked) {
          // init cursor positions on first dir check when startFromEnd is set
          // to true
          c = new Cursor(tail.sync, f, f.length(), f.length(), f.lastModified());
          try {
            c.initCursorPos();
          } catch (InterruptedException e) {
            LOG.error("Initializing of cursor failed", e);
            c.close();
            return;
          }
        } else {
          c = new Cursor(tail.sync, f);
        }

        curmap.put(f.getPath(), c);
        tail.addCursor(c);
        filesAdded.incrementAndGet();
      }

      @Override
      public void fileDeleted(File f) {
        LOG.debug("handling deletion of file " + f);
        String fileName = f.getPath();
        // we cannot just check here with f.isDirectory() because f was deleted
        // and f.isDirectory() will return false always
        DirWatcher watcher = subdirWatcherMap.remove(fileName);
        if (watcher != null) {
          LOG.info("removed dir " + f);
          LOG.info("stopping watcher for dir: " + f);
          // stop is not thread-safe, but since this watcher belongs only to
          // this current thread it is safe to call it
          watcher.stop();
          // calling check explicitly to notify about deleted subdirs,
          // so that subdirs watchers can be stopped
          watcher.check();
          subdirsDeleted.incrementAndGet();
          return;
        }

        Cursor c = curmap.remove(fileName);
        // this check may seem unneeded but there are cases which it handles,
        // e.g. if unwatched subdirectory was removed c is null.
        if (c != null) {
          LOG.info("removed file " + f);
          tail.removeCursor(c);
          filesDeleted.incrementAndGet();
        }
      }

    });

    // Separate check is needed to init cursor positions
    // (to the end of the files in dir)
    if (startFromEnd) {
      watcher.check();
    }
    return watcher;
  }
View Full Code Here

Examples of com.cloudera.util.dirwatcher.DirWatcher

  }

  private DirWatcher createWatcher(File dir, final String regex,
      final int recurseDepth) {
    // 250 ms between checks
    DirWatcher watcher = new DirWatcher(dir, new RegexFileFilter(regex), 250);
    watcher.addHandler(new DirChangeHandler() {
      Map<String, Cursor> curmap = new HashMap<String, Cursor>();

      @Override
      public void fileCreated(File f) {
        if (f.isDirectory()) {
          if (recurseDepth <= 0) {
            LOG.debug("Tail dir will not read or recurse "
                + "into subdirectory " + f + ", this watcher recurseDepth: "
                + recurseDepth);
            return;
          }

          LOG.info("added dir " + f + ", recurseDepth: " + (recurseDepth - 1));
          DirWatcher watcher = createWatcher(f, regex, recurseDepth - 1);
          watcher.start();
          subdirWatcherMap.put(f.getPath(), watcher);
          subdirsAdded.incrementAndGet();
          return;
        }

        // Add a new file to the multi tail.
        LOG.info("added file " + f);
        Cursor c;
        if (delimRegex == null) {
          if (startFromEnd && !dirChecked) {
            // init cursor positions on first dir check when startFromEnd is set
            // to true
            c = new Cursor(tail.sync, f, f.length(), f.length(), f
                .lastModified());
            try {
              c.initCursorPos();
            } catch (InterruptedException e) {
              LOG.error("Initializing of cursor failed", e);
              c.close();
              return;
            }
          } else {
            c = new Cursor(tail.sync, f);
          }
        } else {
          // special delimiter modes
          if (startFromEnd && !dirChecked) {
            // init cursor positions on first dir check when startFromEnd is set
            // to true
            c = new CustomDelimCursor(tail.sync, f, f.length(), f.length(), f
                .lastModified(), delimRegex, delimMode);
            try {
              c.initCursorPos();
            } catch (InterruptedException e) {
              LOG.error("Initializing of custom delimiter cursor failed", e);
              c.close();
              return;
            }
          } else {
            c = new CustomDelimCursor(tail.sync, f, delimRegex, delimMode);
          }
        }

        curmap.put(f.getPath(), c);
        tail.addCursor(c);
        filesAdded.incrementAndGet();
      }

      @Override
      public void fileDeleted(File f) {
        LOG.debug("handling deletion of file " + f);
        String fileName = f.getPath();
        // we cannot just check here with f.isDirectory() because f was deleted
        // and f.isDirectory() will return false always
        DirWatcher watcher = subdirWatcherMap.remove(fileName);
        if (watcher != null) {
          LOG.info("removed dir " + f);
          LOG.info("stopping watcher for dir: " + f);
          // stop is not thread-safe, but since this watcher belongs only to
          // this current thread it is safe to call it
          watcher.stop();
          // calling check explicitly to notify about deleted subdirs,
          // so that subdirs watchers can be stopped
          watcher.check();
          subdirsDeleted.incrementAndGet();
          return;
        }

        Cursor c = curmap.remove(fileName);
        // this check may seem unneeded but there are cases which it handles,
        // e.g. if unwatched subdirectory was removed c is null.
        if (c != null) {
          LOG.info("removed file " + f);
          tail.removeCursor(c);
          filesDeleted.incrementAndGet();
        }
      }

    });

    // Separate check is needed to init cursor positions
    // (to the end of the files in dir)
    if (startFromEnd) {
      watcher.check();
    }
    return watcher;
  }
View Full Code Here

Examples of com.cloudera.util.dirwatcher.DirWatcher

  synchronized public void open() throws IOException {
    Preconditions.checkState(watcher == null,
        "Attempting to open an already open TailDirSource (" + dir + ", \""
        + regex + ", \"" + startFromDateInEpoch + "\")");
    // 250 ms between checks
    this.watcher = new DirWatcher(dir, new RegexFileFilter(regex), 250);
    synchronized (watcher) {
      this.watcher.addHandler(new DirChangeHandler() {
        Map<String, TailSource.Cursor> curmap = new HashMap<String, TailSource.Cursor>();

        @Override
View Full Code Here

Examples of eu.admire.seismo.common.DirWatcher

    File processingFolder   = new File(path);
  
   if(!processingFolder.exists())
     processingFolder.mkdirs();
  
    DirWatcher task = new DirWatcher(path, "seed" ) {
        protected void onChange( File file, String action ) {
          // here we code the action on a change
         try{
        
         System.out.println( "File "+ file.getName() +" action: " + action );
View Full Code Here

Examples of eu.admire.seismo.common.DirWatcher

    File processingFolder   = new File(path);
  
   if(!processingFolder.exists())
     processingFolder.mkdirs();
  
    DirWatcher task = new DirWatcher(path, "seed" ) {
        protected void onChange( File file, String action ) {
          // here we code the action on a change
         try{
        
         System.out.println( "File "+ file.getName() +" action: " + action );
View Full Code Here

Examples of eu.admire.seismo.common.DirWatcher

  public void CheckFiles() throws Exception
  {   
    final HashMap stamap = new HashMap();
    
      
      DirWatcher task = new DirWatcher("./", "seed" ) {
          protected void onChange( File file, String action ) {
            // here we code the action on a change
           try{ System.out.println( "File "+ file.getName() +" action: " + WaveformDasetsAggregationActivity.extractStationCode(file.getName()) );
            
           } catch (Exception e)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.