Beispiel #1
0
  @OnOpen
  public void setMonitor(@PathParam("directory") String directory, Session s) {
    System.out.printf("Watch for %s%n", directory);
    try {
      watchService = FileSystems.getDefault().newWatchService();
      session = s;
      Path p = new File(directory).toPath();
      p.register(
          watchService,
          StandardWatchEventKinds.ENTRY_CREATE,
          StandardWatchEventKinds.ENTRY_DELETE,
          StandardWatchEventKinds.ENTRY_MODIFY);
      session.getBasicRemote().sendText("Registered " + p);
      pollThr = new Thread(this);
      pollThr.start();
    } catch (IOException e) {
      try {
        session.getBasicRemote().sendText("Can't setup watcher :" + e);
      } catch (IOException e2) {

      }
    }
  }
Beispiel #2
0
 @OnClose
 public void stopWatch() {
   if (pollThr != null) pollThr.interrupt();
 }