java.nio.file.WatchService.close()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中java.nio.file.WatchService.close()方法的一些代码示例,展示了WatchService.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WatchService.close()方法的具体详情如下:
包路径:java.nio.file.WatchService
类名称:WatchService
方法名:close

WatchService.close介绍

暂无

代码示例

代码示例来源:origin: syncany/syncany

@Override
public void afterStop() throws IOException {
  watchService.close();
}

代码示例来源:origin: konsoletyper/teavm

public void dispose() throws IOException {
  watchService.close();
}

代码示例来源:origin: jooby-project/jooby

public void stop() throws IOException {
 watcher.close();
}

代码示例来源:origin: neo4j/neo4j

@Override
public void close() throws IOException
{
  stopWatching();
  watchService.close();
}

代码示例来源:origin: spring-cloud/spring-cloud-config

@Override
public synchronized void stop() {
  if (this.running) {
    if (this.watcher != null) {
      try {
        this.watcher.close();
      }
      catch (IOException e) {
        log.error("Failed to close watcher for " + this.directory.toString(),
            e);
      }
    }
    this.running = false;
  }
}

代码示例来源:origin: apache/zeppelin

public void shutdown() throws IOException {
 stop = true;
 clear();
 watcher.close();
}

代码示例来源:origin: dreamhead/moco

public synchronized void stop() {
  if (this.running) {
    try {
      this.running = false;
      this.service.close();
      this.result.get();
    } catch (Exception e) {
      throw new MocoException(e);
    }
  }
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Shuts down this watcher, releasing all resources.
 */
public void destroy()
{
  if ( executorService != null )
  {
    executorService.shutdown();
  }
  synchronized ( watchedStores )
  {
    if ( storeWatcher != null )
    {
      try
      {
        storeWatcher.close();
      }
      catch ( IOException e )
      {
        Log.warn( "Unable to close the watcherservice that is watching for file system changes to certificate stores.", e );
      }
    }
  }
}

代码示例来源:origin: oracle/opengrok

/**
   * Stops the watch dog service.
   */
  public void stop() {
    if (watchDogWatcher != null) {
      try {
        watchDogWatcher.close();
      } catch (IOException ex) {
        LOGGER.log(Level.WARNING, "Cannot close WatchDogService: ", ex);
      }
    }
    if (watchDogThread != null) {
      watchDogThread.interrupt();
      try {
        watchDogThread.join();
      } catch (InterruptedException ex) {
        LOGGER.log(Level.WARNING, "Cannot join WatchDogService thread: ", ex);
      }
    }
    LOGGER.log(Level.INFO, "Watchdog stoped");
  }
}

代码示例来源:origin: apache/zookeeper

@Override
public void run() {
  try {
    LOG.info(getName() + " thread started");
    if (!compareAndSetState(
        FileChangeWatcher.State.STARTING,
        FileChangeWatcher.State.RUNNING)) {
      // stop() called shortly after start(), before
      // this thread started running.
      FileChangeWatcher.State state = FileChangeWatcher.this.getState();
      if (state != FileChangeWatcher.State.STOPPING) {
        throw new IllegalStateException("Unexpected state: " + state);
      }
      return;
    }
    runLoop();
  } catch (Exception e) {
    LOG.warn("Error in runLoop()", e);
    throw e;
  } finally {
    try {
      watchService.close();
    } catch (IOException e) {
      LOG.warn("Error closing watch service", e);
    }
    LOG.info(getName() + " thread finished");
    FileChangeWatcher.this.setState(FileChangeWatcher.State.STOPPED);
  }
}

代码示例来源:origin: apache/hive

void stop() throws IOException {
 shutdown.set(true);
 if (watcherFuture != null) {
  watcherFuture.cancel(true);
 }
 if (expirerFuture != null) {
  expirerFuture.cancel(true);
 }
 watchService.close();
 watcherExecutorService.shutdownNow();
 expirerExecutorService.shutdownNow();
}

代码示例来源:origin: rapidoid/rapidoid

public void cancel() {
  Set<WatchKey> keysToCancel;
  synchronized (keys) {
    keysToCancel = U.set(keys.keySet());
  }
  interrupt();
  keys.clear();
  for (WatchKey key : keysToCancel) {
    key.cancel();
  }
  try {
    watchService.close();
  } catch (IOException e) {
    Log.error("Error occurred while closing a WatchService!", e);
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
void stopWatchingAndCloseEverythingOnClosed() throws IOException
{
  TestFileSystemWatcher watcher = createWatcher();
  watcher.close();
  verify( watchServiceMock ).close();
  assertTrue( watcher.isClosed() );
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public void stop() {
  try {
    this.watcher.close();
    this.watcher = null;
    this.pathKeys.clear();
  }
  catch (IOException e) {
    logger.error("Failed to close watcher for " + FileReadingMessageSource.this.directory, e);
  }
}

代码示例来源:origin: pippo-java/pippo

public void stop() {
  if (running) {
    running = false;
    executorService.shutdownNow();
    try {
      watchService.close();
    } catch (IOException e) {
      log.error("Cannot close the watch service", e);
    }
    watcherTask.cancel(true);
    watcherTask = null;
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-util

/** 
 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop()
 */
@Override
protected void doStop() throws Exception
{
  if (watchService != null)
    watchService.close(); //will invalidate registered watch keys, interrupt thread in take or poll
  watchService = null;
  thread = null;
  keys.clear();
  pending.clear();
  events.clear();
  super.doStop();
}

代码示例来源:origin: eclipse/smarthome

watchService.close();
} catch (IOException e) {
  logger.warn("Cannot deactivate folder watcher", e);

代码示例来源:origin: cincheo/jsweet

watchService.close();
} catch (IOException ioException) {
  logger.error(ioException);

代码示例来源:origin: cincheo/jsweet

private void initialize() {
  List<File> sourcePaths = transpilationTask.getInputDirList();
  try {
    for (;;) {
      WatchService watchService = FileSystems.getDefault().newWatchService();
      List<Path> watchedPaths = new ArrayList<>();
      logger.info("registering source paths");
      for (File sourceDirectory : sourcePaths) {
        Path path = sourceDirectory.toPath();
        watchedPaths.add(path);
        walkDirectoryTree(path, watchedPaths, watchService);
      }
      logger.info("done registering source paths");
      logger.info("listening for file change... ");
      try {
        watch(watchService);
      } catch (Exception exception) {
        watchService.close();
      }
      Thread.yield();
    }
  } catch (IOException ioException) {
    logger.error(ioException);
  }
}

代码示例来源:origin: stackoverflow.com

watcher.close();
}catch(IOException ioe){

相关文章