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

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

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

WatchService.poll介绍

暂无

代码示例

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

private boolean pollNow() throws IOException {
  WatchKey key = watchService.poll();
  if (key == null) {
    return false;
  }
  return filter(key);
}

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

private boolean poll(int milliseconds) throws IOException, InterruptedException {
  long end = System.currentTimeMillis() + milliseconds;
  while (true) {
    int timeToWait = (int) (end - System.currentTimeMillis());
    if (timeToWait <= 0) {
      return false;
    }
    WatchKey key = watchService.poll(timeToWait, TimeUnit.MILLISECONDS);
    if (key == null) {
      continue;
    }
    if (filter(key)) {
      return true;
    }
  }
}

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

WatchKey key = null;
try {
 key = watcher.poll(1, TimeUnit.SECONDS);
} catch (InterruptedException | ClosedWatchServiceException e) {
 break;

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

try {
  LOGGER.debug("Polling for new NARs at {}", new Object[]{autoLoadPath});
  key = watchService.poll(pollIntervalMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException x) {
  LOGGER.info("WatchService interrupted, returning...");

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

return files;
WatchKey key = this.watcher.poll();
while (key != null) {
  for (WatchEvent<?> event : key.pollEvents()) {
  key = this.watcher.poll();

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

try
  key = storeWatcher.poll( 5, TimeUnit.SECONDS );

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

public class WatchServiceRunnableWrapper implements Runnable {

  private WatchService WatchService;

  public WatchServiceRunnableWrapper(WatchService watchService) {
    this.watchService = watchService;
  }

  public void run() {
    watchService.poll();
    //
  }
}

代码示例来源:origin: HubSpot/Singularity

public void watch() throws IOException, InterruptedException {
 LOG.info("Watching directory {} for event(s) {}", watchDirectory, watchEvents);
 WatchKey watchKey = watchDirectory.register(watchService, watchEvents.toArray(new WatchEvent.Kind[watchEvents.size()]));
 while (!stopped) {
  if (watchKey != null) {
   processWatchKey(watchKey);
   if (!watchKey.reset()) {
    LOG.warn("WatchKey for {} no longer valid", watchDirectory);
    break;
   }
  }
  watchKey = watchService.poll(pollWaitCheckShutdownMillis, TimeUnit.MILLISECONDS);
 }
}

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

private Set<File> filesFromEvents() {
  WatchKey key = this.watcher.poll();
  Set<File> files = new LinkedHashSet<>();
  while (key != null) {
    File parentDir = ((Path) key.watchable()).toAbsolutePath().toFile();
    for (WatchEvent<?> event : key.pollEvents()) {
      if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE ||
          event.kind() == StandardWatchEventKinds.ENTRY_MODIFY ||
          event.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
        processFilesFromNormalEvent(files, parentDir, event);
      }
      else if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
        processFilesFromOverflowEvent(files, event);
      }
    }
    key.reset();
    key = this.watcher.poll();
  }
  return files;
}

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

key = wait_time<0?watch.take():wait_time>0?watch.poll(wait_time,updateQuietTimeUnit):watch.poll();
  key = watch.poll();

代码示例来源:origin: cinchapi/concourse

/**
 * @throws ClosedWatchServiceException {@inheritDoc}
 */
@Override
public WatchKey poll() {
  return service.poll();
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
public WatchKey poll(final long timeout, final TimeUnit unit) throws InterruptedException {
  return monitor.poll(timeout, unit);
}

代码示例来源:origin: cinchapi/concourse

/**
 * @throws ClosedWatchServiceException {@inheritDoc}
 */
@Override
public WatchKey poll(long timeout, TimeUnit unit)
    throws InterruptedException {
  return service.poll(timeout, unit);
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
public WatchKey poll() {
  return monitor.poll();
}

代码示例来源:origin: org.gradle/gradle-core

@Nullable
public List<FileWatcherEvent> takeEvents() throws InterruptedException {
  WatchKey watchKey = watchService.poll(POLL_TIMEOUT_SECONDS, TimeUnit.SECONDS);
  if (watchKey != null) {
    return handleWatchKey(watchKey);
  }
  return null;
}

代码示例来源:origin: com.ofg/micro-infra-spring-config

private void waitForChanges() throws InterruptedException {
  final WatchKey key = watcher.poll(10, TimeUnit.SECONDS);
  if (key != null) {
    handleChange(key);
  }
}

代码示例来源:origin: com.darylteo/directory-watcher

/**
  * Notifies all subscribers or any file system changes (if any)
  */
 public void poll() {
  super.handleWatchKey(super.getWatchService().poll());
 }
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( { SlowTest.class, Watchable.class, Writable.class } )
public void testPollAnEmptyWatchServiceReturnsNull() throws Exception {
  Path dir = dirTA();
  final WatchService watcher = dir.getFileSystem().newWatchService();
  dir.register( watcher, ENTRY_CREATE );
  assertThat( watcher.poll() ).isNull();
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test( timeout = 30000 )
@Category( { SlowTest.class, Watchable.class, Writable.class, Delete.class } )
public void testWatchADeletePollWithTimeOut() throws Exception {
  Path toBeDeleted = watchedFileA();
  watcherSetup( ENTRY_DELETE );
  Files.delete( toBeDeleted );
  assertThat( correctKey( waitForWatchService().poll( 1000, TimeUnit.MILLISECONDS ), toBeDeleted, ENTRY_DELETE ) ).isTrue();
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test( timeout = 30000 )
@Category( { SlowTest.class, Watchable.class, Writable.class } )
public void testWatchPollWithTimeoutTimesOut() throws Exception {
  watcherSetup( ENTRY_DELETE );
  // no events
  getWatchService().poll( 1000, TimeUnit.MILLISECONDS );
  assertThat( "did we reach that?" ).isNotNull();
}

相关文章