Java 类java.nio.file.Watchable 实例源码

项目:cyberduck    文件:FSEventWatchService.java   
public MacOSXWatchKey(final Watchable file, final FSEventWatchService service, final WatchEvent.Kind<?>[] events) {
    super(service);
    this.file = file;

    boolean reportCreateEvents = false;
    boolean reportModifyEvents = false;
    boolean reportDeleteEvents = false;

    for(WatchEvent.Kind<?> event : events) {
        if(event == StandardWatchEventKinds.ENTRY_CREATE) {
            reportCreateEvents = true;
        }
        else if(event == StandardWatchEventKinds.ENTRY_MODIFY) {
            reportModifyEvents = true;
        }
        else if(event == StandardWatchEventKinds.ENTRY_DELETE) {
            reportDeleteEvents = true;
        }
    }
    this.reportCreateEvents = reportCreateEvents;
    this.reportDeleteEvents = reportDeleteEvents;
    this.reportModifyEvents = reportModifyEvents;
}
项目:jimfs    文件:PollingWatchService.java   
@Override
public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes)
    throws IOException {
  JimfsPath path = checkWatchable(watchable);

  Key key = super.register(path, eventTypes);

  Snapshot snapshot = takeSnapshot(path);

  synchronized (this) {
    snapshots.put(key, snapshot);
    if (pollingFuture == null) {
      startPolling();
    }
  }

  return key;
}
项目:cyberduck    文件:FSEventWatchService.java   
@Override
public WatchKey register(final Watchable folder,
                         final WatchEvent.Kind<?>[] events,
                         final WatchEvent.Modifier... modifiers)
        throws IOException {
    if(log.isInfoEnabled()) {
        log.info(String.format("Register file %s for events %s", folder, Arrays.toString(events)));
    }
    final Pointer[] values = {
            CFStringRef.toCFString(folder.toString()).getPointer()};

    final MacOSXWatchKey key = new MacOSXWatchKey(folder, this, events);

    final double latency = 1.0; // Latency in seconds

    final Map<File, Long> timestamps = createLastModifiedMap(new File(folder.toString()));
    final FSEvents.FSEventStreamCallback callback = new Callback(key, timestamps);
    final FSEventStreamRef stream = library.FSEventStreamCreate(
            Pointer.NULL, callback, Pointer.NULL,
            library.CFArrayCreate(null, values, CFIndex.valueOf(1), null),
            -1, latency,
            kFSEventStreamCreateFlagNoDefer);
    final CountDownLatch lock = new CountDownLatch(1);
    final CFRunLoop loop = new CFRunLoop(lock, stream);
    threadFactory.newThread(loop).start();
    try {
        lock.await();
    }
    catch(InterruptedException e) {
        throw new IOException(String.format("Failure registering for events in %s", folder), e);
    }
    loops.put(key, loop);
    callbacks.put(key, callback);
    return key;
}
项目:cyberduck    文件:FSEventWatchServiceTest.java   
@Test
public void testRegister() throws Exception {
    final RegisterWatchService fs = new FSEventWatchService();
    final Watchable folder = Paths.get(
            File.createTempFile(UUID.randomUUID().toString(), "t").getParent());
    final WatchKey key = fs.register(folder, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY});
    assertTrue(key.isValid());
    fs.close();
    assertFalse(key.isValid());
}
项目:cyberduck    文件:NIOEventWatchService.java   
@Override
public WatchKey register(final Watchable folder, final WatchEvent.Kind<?>[] events,
                         final WatchEvent.Modifier... modifiers) throws IOException {
    if(null == monitor) {
        monitor = FileSystems.getDefault().newWatchService();
    }
    final WatchKey key = folder.register(monitor, events, modifiers);
    if(log.isInfoEnabled()) {
        log.info(String.format("Registered for events for %s", key));
    }
    return key;
}
项目:cyberduck    文件:NIOEventWatchServiceTest.java   
@Test
public void testRegister() throws Exception {
    final RegisterWatchService fs = new NIOEventWatchService();
    final Watchable folder = Paths.get(
            File.createTempFile(UUID.randomUUID().toString(), "t").getParent());
    final WatchKey key = fs.register(folder, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY});
    assertTrue(key.isValid());
    fs.close();
    assertFalse(key.isValid());
}
项目:directory-watcher    文件:DirectoryWatcher.java   
public DirectoryWatcher(Path directory, Watchable directoryToMonitor, WatchService watchService, DirectoryChangeListener listener, boolean isMac) throws IOException {
  this.directory = directory;
  this.watchService = watchService;
  this.listener = listener;
  this.isMac = isMac;

  if (isMac) {
    register(directoryToMonitor);
  } else {
    jdkWatcher = new DirectoryWatcherJdk(directory, listener);
  }
}
项目:directory-watcher    文件:AbstractWatchKey.java   
public AbstractWatchKey(
  AbstractWatchService watcher,
  @Nullable Watchable watchable,
  Iterable<? extends WatchEvent.Kind<?>> subscribedTypes) {
  this.watcher = checkNotNull(watcher);
  this.watchable = watchable; // nullable for Watcher poison
  this.subscribedTypes = ImmutableSet.copyOf(subscribedTypes);
}
项目:jimfs    文件:PollingWatchService.java   
private JimfsPath checkWatchable(Watchable watchable) {
  if (!(watchable instanceof JimfsPath) || !isSameFileSystem((Path) watchable)) {
    throw new IllegalArgumentException(
        "watchable ("
            + watchable
            + ") must be a Path "
            + "associated with the same file system as this watch service");
  }

  return (JimfsPath) watchable;
}
项目:jimfs    文件:AbstractWatchService.java   
public Key(
    AbstractWatchService watcher,
    @Nullable Watchable watchable,
    Iterable<? extends WatchEvent.Kind<?>> subscribedTypes) {
  this.watcher = checkNotNull(watcher);
  this.watchable = watchable; // nullable for Watcher poison
  this.subscribedTypes = ImmutableSet.copyOf(subscribedTypes);
}
项目:jimfs    文件:AbstractWatchServiceTest.java   
@Test
public void testRegister() throws IOException {
  Watchable watchable = new StubWatchable();
  AbstractWatchService.Key key = watcher.register(watchable, ImmutableSet.of(ENTRY_CREATE));
  assertThat(key.isValid()).isTrue();
  assertThat(key.pollEvents()).isEmpty();
  assertThat(key.subscribesTo(ENTRY_CREATE)).isTrue();
  assertThat(key.subscribesTo(ENTRY_DELETE)).isFalse();
  assertThat(key.watchable()).isEqualTo(watchable);
  assertThat(key.state()).isEqualTo(READY);
}
项目:cas-5.1.0    文件:AbstractResourceBasedServiceRegistryDao.java   
@Override
public <T extends Watchable> T getWatchableResource() {
    final Watchable watchable = this.serviceRegistryDirectory;
    return (T) watchable;
}
项目:cyberduck    文件:FSEventWatchService.java   
@Override
public Watchable watchable() {
    return file;
}
项目:cyberduck    文件:RegisterWatchService.java   
WatchKey register(Watchable folder,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers) throws IOException;
项目:cyberduck    文件:AbstractWatchService.java   
@Override
public Watchable watchable() {
    return null;
}
项目:cyberduck    文件:DisabledWatchService.java   
@Override
public WatchKey register(final Watchable folder, final WatchEvent.Kind<?>[] events, final WatchEvent.Modifier... modifiers) throws IOException {
    return null;
}
项目:baratine    文件:JWatchKey.java   
@Override
public Watchable watchable()
{
  return _path;
}
项目:directory-watcher    文件:DirectoryWatcher.java   
private void register(Watchable dir) throws IOException {
  dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
}
项目:directory-watcher    文件:MacOSXWatchKey.java   
@Override
public Watchable watchable() {
  return null;
}
项目:directory-watcher    文件:AbstractWatchKey.java   
@Override
public Watchable watchable() {
  return watchable;
}
项目:RxJavaFileUtils    文件:MacOSXWatchKey.java   
@Override
public Watchable watchable() {
    return path;
}
项目:RxJavaFileUtils    文件:AbstractWatchService.java   
@Override
public Watchable watchable() {
    return null;
}
项目:ephemeralfs    文件:EphemeralFsWatchKey.java   
@Override
public Watchable watchable() {
    return watchable;
}
项目:jimfs    文件:AbstractWatchService.java   
/**
 * Registers the given watchable with this service, returning a new watch key for it. This
 * implementation just checks that the service is open and creates a key; subclasses may override
 * it to do other things as well.
 */
public Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes)
    throws IOException {
  checkOpen();
  return new Key(this, watchable, eventTypes);
}
项目:jimfs    文件:AbstractWatchService.java   
@Override
public Watchable watchable() {
  return watchable;
}
项目:cas-5.1.0    文件:ResourceBasedServiceRegistryDao.java   
/**
 * Gets the watchable resource.
 *
 * @param <T> the type parameter
 * @return the watchable resource
 */
<T extends Watchable> T getWatchableResource();