当前位置: 首页>>代码示例>>Java>>正文


Java ClosedWatchServiceException类代码示例

本文整理汇总了Java中java.nio.file.ClosedWatchServiceException的典型用法代码示例。如果您正苦于以下问题:Java ClosedWatchServiceException类的具体用法?Java ClosedWatchServiceException怎么用?Java ClosedWatchServiceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClosedWatchServiceException类属于java.nio.file包,在下文中一共展示了ClosedWatchServiceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nextEvent

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Override
protected String nextEvent() throws IOException, InterruptedException {
    WatchKey key;
    try {
        key = watcher.take();
    } catch (ClosedWatchServiceException cwse) { // #238261
        @SuppressWarnings({"ThrowableInstanceNotThrown"})
        InterruptedException ie = new InterruptedException();
        throw (InterruptedException) ie.initCause(cwse);
    }
    Path dir = (Path)key.watchable();
           
    String res = dir.toAbsolutePath().toString();
    for (WatchEvent<?> event: key.pollEvents()) {
        if (event.kind() == OVERFLOW) {
            // full rescan
            res = null;
        }
    }
    key.reset();
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:NioNotifier.java

示例2: pollForMoreChanges

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
/**
 * Keep polling for a short time: when (multiple) directories get deleted the watch keys might
 * arrive just a bit later
 */
private void pollForMoreChanges() throws ClosedWatchServiceException, InterruptedException {
    boolean keepPolling = true;
    List<WatchKey> polledKeys = new ArrayList<>();
    final long startPolling = System.currentTimeMillis();
    while (keepPolling) {
        log.debug("Waiting {} ms for more changes...", POLLING_TIME_MILLIS);
        WatchKey key = watcher.poll(POLLING_TIME_MILLIS, TimeUnit.MILLISECONDS);
        if (key == null) {
            keepPolling = false;
        } else {
            log.debug("Found change for '{}' found during extra polling time", key.watchable());
            polledKeys.add(key);
        }
    }
    log.debug("Polled '{}' more changes during '{}' ms", polledKeys.size(), String.valueOf(System.currentTimeMillis() - startPolling));
    for (WatchKey polledKey : polledKeys) {
        processWatchKey(polledKey);
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:24,代码来源:FileSystemWatcher.java

示例3: poll

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
/**
 * Polls the given WatchService in a tight loop. This keeps the event
 * queue drained, it also hogs a CPU core which seems necessary to
 * tickle the original bug.
 */
static void poll(WatchService watcher) {
    try {
        for (;;) {
            WatchKey key = watcher.take();
            if (key != null) {
                key.pollEvents();
                key.reset();
            }
        }
    } catch (ClosedWatchServiceException expected) {
        // nothing to do
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:LotsOfCancels.java

示例4: poll

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
/**
 * Polls the given WatchService in a tight loop. This keeps the event
 * queue drained, it also hogs a CPU core which seems necessary to
 * tickle the original bug.
 */
static void poll(int id, WatchService watcher) {
    System.out.printf("begin poll %d%n", id);
    try {
        for (;;) {
            WatchKey key = watcher.take();
            if (key != null) {
                key.pollEvents();
                key.reset();
            }
        }
    } catch (ClosedWatchServiceException expected) {
        // nothing to do but print
        System.out.printf("poll %d expected exception %s%n", id, expected);
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
    System.out.printf("end poll %d%n", id);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:LotsOfCancels.java

示例5: testWatchServiceTakeBlocks

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Test
@Category( { SlowTest.class, Watchable.class, Writable.class } )
@SuppressWarnings( "PMD.EmptyCatchBlock" )
public void testWatchServiceTakeBlocks() throws Exception {
    Path dir = dirTA();
    final WatchService watcher = dir.getFileSystem().newWatchService();
    dir.register( watcher, ENTRY_CREATE );

    final Ref<Boolean> interrupted = Ref.valueOf( false );

    new Thread( () -> {
        try {
            watcher.take();
        } catch( InterruptedException | ClosedWatchServiceException e ) {
            // nothing to do
        } finally {
            interrupted.set( true );

        }
    } ).start();

    Thread.sleep( 1000 );

    assertThat( interrupted.get() ).isFalse();

}
 
开发者ID:openCage,项目名称:niotest,代码行数:27,代码来源:Tests11Watcher.java

示例6: handleChanges

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
private synchronized void handleChanges() {
    final WatchKey key;
    try {
        key = this.watchService.take();
    } catch (final InterruptedException | ClosedWatchServiceException e) {
        if (!ConfigLoaderImpl.this.closed) {
            LOG.warn(INTERRUPTED, e);
            Thread.currentThread().interrupt();
        }
        return;
    }

    if (key != null) {
        for (final WatchEvent<?> event : key.pollEvents()) {
            handleEvent(event.context().toString());
        }
        final boolean reset = key.reset();
        if (!reset) {
            LOG.warn("Could not reset the watch key.");
        }
    }
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:23,代码来源:ConfigLoaderImpl.java

示例7: Watcher

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
public Watcher(final BiConsumer<Kind<?>, Path> listener, final Path... dirs)
    throws IOException {
  this.watcher = FileSystems.getDefault().newWatchService();
  this.keys = new HashMap<WatchKey, Path>();
  this.listener = listener;
  for (Path dir : dirs) {
    registerAll(dir);
  }

  this.scanner = new Thread(() -> {
    boolean process = true;
    listener.accept(ENTRY_MODIFY, dirs[0]);
    try {
    while (process) {
      process = processEvents();
    }
    } catch (ClosedWatchServiceException ex) {
      log.trace("watch service closed", ex);
    }
  }, "asset-compiler");

  scanner.setDaemon(true);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:Watcher.java

示例8: testNewSingleThreadExecutor

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
/**
 * Tests {@link FileSystemFactory#newWatchService()}.
 *
 * @throws ClosedWatchServiceException if the newly-created service is closed
 * @throws IOException if the test fails
 * @throws InterruptedException hopefully never
 */
@Test
public void testNewSingleThreadExecutor() throws ClosedWatchServiceException, IOException, InterruptedException {
    WatchService service = new FileSystemFactory().newWatchService();
    try {
        assertNotNull(service);
        assertNull(service.poll()); // verifies the service is not closed
    } finally {
        if (service != null) {
            try {
                service.close();
            }catch(IOException ex) {
                //trap
            }
        }
    }
}
 
开发者ID:sworisbreathing,项目名称:sfmf4j,代码行数:24,代码来源:FileSystemFactoryTest.java

示例9: poll

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Override
public WatchKey poll() {
    if (!running) {
        throw new ClosedWatchServiceException();
    }
    WatchKey pending = popPending();
    if (null != pending) {
        return pending;
    }
    for (GlusterWatchKey k : paths) {
        if (k.isValid() && k.isReady() && k.update()) {
            pendingPaths.add(k);
        }
    }
    return popPending();
}
 
开发者ID:gluster,项目名称:glusterfs-java-filesystem,代码行数:17,代码来源:GlusterWatchService.java

示例10: pumpEvents

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
private void pumpEvents() throws InterruptedException {
    while (isRunning()) {
        try {
            List<FileWatcherEvent> events = poller.takeEvents();
            if (events != null) {
                deliverEvents(events);
            }
        } catch (ClosedWatchServiceException e) {
            LOGGER.debug("Received ClosedWatchServiceException, stopping");
            stop();
        }
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:WatchServiceFileWatcherBacking.java

示例11: addWatch

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Override
protected WatchKey addWatch(String pathStr) throws IOException {
    Path path = Paths.get(pathStr);
    try {
        WatchKey key = path.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
        return key;
    } catch (ClosedWatchServiceException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:NioNotifier.java

示例12: removeWatch

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Override
protected void removeWatch(WatchKey key) throws IOException {
    try {
        key.cancel();
    } catch (ClosedWatchServiceException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:NioNotifier.java

示例13: scanner

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
protected void scanner ()
{
    logger.trace ( "Watching for events" );
    while ( true )
    {
        WatchKey key = null;
        try
        {
            key = this.ws.take ();
            logger.trace ( "Took events: {}", key.watchable () );

            final List<WatchEvent<?>> events = key.pollEvents ();
            for ( final WatchEvent<?> evt : events )
            {
                processEvent ( evt );
            }
        }
        catch ( final InterruptedException | ClosedWatchServiceException e )
        {
            return;
        }
        finally
        {
            if ( key != null )
            {
                key.reset ();
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:31,代码来源:AbstractMergeWatcher.java

示例14: run

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
@Override
public void run() {
    try {
        log.info("Watch started");
        while (true) {
            processChanges();
        }
    } catch (ClosedWatchServiceException e) {
        log.info("Watch closed", e);
    } finally {
        IOUtils.closeQuietly(watcher);
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:14,代码来源:FileSystemWatcher.java

示例15: doPrivilegedRegister

import java.nio.file.ClosedWatchServiceException; //导入依赖的package包/类
private PollingWatchKey doPrivilegedRegister(Path path,
                                             Set<? extends WatchEvent.Kind<?>> events,
                                             int sensitivityInSeconds)
    throws IOException
{
    // check file is a directory and get its file key if possible
    BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
    if (!attrs.isDirectory()) {
        throw new NotDirectoryException(path.toString());
    }
    Object fileKey = attrs.fileKey();
    if (fileKey == null)
        throw new AssertionError("File keys must be supported");

    // grab close lock to ensure that watch service cannot be closed
    synchronized (closeLock()) {
        if (!isOpen())
            throw new ClosedWatchServiceException();

        PollingWatchKey watchKey;
        synchronized (map) {
            watchKey = map.get(fileKey);
            if (watchKey == null) {
                // new registration
                watchKey = new PollingWatchKey(path, this, fileKey);
                map.put(fileKey, watchKey);
            } else {
                // update to existing registration
                watchKey.disable();
            }
        }
        watchKey.enable(events, sensitivityInSeconds);
        return watchKey;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:PollingWatchService.java


注:本文中的java.nio.file.ClosedWatchServiceException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。