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


Java WatchKey.cancel方法代码示例

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


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

示例1: run

import java.nio.file.WatchKey; //导入方法依赖的package包/类
@Override
protected void run() {
    while(isRunning()) {
        try {
            final WatchKey key = watchService.take();
            final WatchedDirectory watchedDirectory = dirsByKey.get(key);
            if(watchedDirectory == null) {
                logger.warning("Cancelling unknown key " + key);
                key.cancel();
            } else {
                for(WatchEvent<?> event : key.pollEvents()) {
                    watchedDirectory.dispatch((WatchEvent<Path>) event);
                }
                key.reset();
            }
        } catch(InterruptedException e) {
            // ignore, just check for termination
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:21,代码来源:PathWatcherServiceImpl.java

示例2: manageDirectoryDeletion

import java.nio.file.WatchKey; //导入方法依赖的package包/类
private void manageDirectoryDeletion(Path filename) throws IOException {
    PhotatoFolder parentFolder = getCurrentFolder(filename.getParent());
    parentFolder.subFolders.remove(filename.getFileName().toString());
    WatchKey removed = watchedDirectoriesKeys.remove(filename);
    if (removed != null) {
        removed.cancel();
        watchedDirectoriesPaths.remove(removed);
    }

    PhotatoFolder currentFolder = getCurrentFolder(filename);
    if (currentFolder.medias != null) {
        for (PhotatoMedia media : currentFolder.medias) {
            try {
                searchManager.removeMedia(media);
                albumsManager.removeMedia(media);
                thumbnailGenerator.deleteThumbnail(media.fsPath, media.lastModificationTimestamp);
                fullScreenImageGetter.deleteImage(media);
            } catch (IOException ex) {
            }
        }
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:23,代码来源:PhotatoFilesManager.java

示例3: handle

import java.nio.file.WatchKey; //导入方法依赖的package包/类
/**
 * Stress the given WatchService, specifically the cancel method, in
 * the given directory. Closes the WatchService when done.
 */
static void handle(Path dir, WatchService watcher) {
    try {
        try {
            Path file = dir.resolve("anyfile");
            for (int i=0; i<2000; i++) {
                WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE);
                Files.createFile(file);
                Files.delete(file);
                key.cancel();
            }
        } finally {
            watcher.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:LotsOfCancels.java

示例4: handle

import java.nio.file.WatchKey; //导入方法依赖的package包/类
/**
 * Stress the given WatchService, specifically the cancel method, in
 * the given directory. Closes the WatchService when done.
 */
static void handle(int id, Path dir, WatchService watcher) {
    System.out.printf("begin handle %d%n", id);
    try {
        try {
            Path file = dir.resolve("anyfile");
            for (int i=0; i<2000; i++) {
                WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE);
                Files.createFile(file);
                Files.delete(file);
                key.cancel();
            }
        } finally {
            System.out.printf("WatchService %d closing ...%n", id);
            watcher.close();
            System.out.printf("WatchService %d closed %n", id);
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
    System.out.printf("end handle %d%n", id);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:LotsOfCancels.java

示例5: close

import java.nio.file.WatchKey; //导入方法依赖的package包/类
@Override
public void close() throws IOException
{
  ArrayList<JWatchKey> watchList = new ArrayList<>();

  if (_isClosed.getAndSet(true)) {
    return;
  }

  watchList.addAll(_watchList);
  _watchList.clear();

  for (WatchKey key : watchList) {
    key.cancel();
  }
}
 
开发者ID:baratine,项目名称:baratine,代码行数:17,代码来源:JWatchService.java

示例6: removeWatch

import java.nio.file.WatchKey; //导入方法依赖的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

示例7: cancel

import java.nio.file.WatchKey; //导入方法依赖的package包/类
public synchronized void cancel(Path path) {
  WatchKey watchKey = pathWatchKeyMap.get(path);
  if (watchKey != null) {
    pathWatchKeyMap.remove(path);
    watchKey.cancel();
  }
}
 
开发者ID:WenzheLiu,项目名称:filewatcher,代码行数:8,代码来源:FileWatchService.java

示例8: clear

import java.nio.file.WatchKey; //导入方法依赖的package包/类
/**
 * Clears all previously registered watched folders.
 */
public void clear() {
	synchronized ( keyInfoMap ) {
		for ( final WatchKey key : keyInfoMap.keySet() )
			key.cancel();
		keyInfoMap.clear();
	}
}
 
开发者ID:icza,项目名称:scelight,代码行数:11,代码来源:Watcher.java

示例9: monitor

import java.nio.file.WatchKey; //导入方法依赖的package包/类
private void monitor(File file) throws Exception{
    watchService = FileSystems.getDefault().newWatchService();
    file.toPath().register(watchService, StandardWatchEventKinds.ENTRY_CREATE,StandardWatchEventKinds.ENTRY_DELETE); 
    while(running){
        WatchKey watchKey = watchService.take();
        List<WatchEvent<?>> events = watchKey.pollEvents();
        
        if(events != null){
            for(WatchEvent<?> e : events){
                //事件处理
                final WatchEvent<Path> watchEventPath = (WatchEvent<Path>)e; 
                final Path filename = watchEventPath.context(); 
                
                if(e.kind() == StandardWatchEventKinds.ENTRY_CREATE){
                    addDataSource(filename.toString());
                }else if(e.kind() == StandardWatchEventKinds.ENTRY_DELETE){
                    removeDataSource(filename.toString());
                }
            }
        }
        if(!watchKey.reset()){
            watchKey.cancel();
            logger.error("移除dataSource文件目录监控服务");
            break;
        }
    }
    running = false;
    watchService.close();
}
 
开发者ID:javen-hao,项目名称:osmp,代码行数:30,代码来源:DataSourceMonitor.java

示例10: monitor

import java.nio.file.WatchKey; //导入方法依赖的package包/类
private void monitor(Path path) throws Exception{
    watchService = FileSystems.getDefault().newWatchService();
    
    registerTree(path);
    while(running){
        WatchKey watchKey = watchService.take();
        List<WatchEvent<?>> events = watchKey.pollEvents();
        
         
        if(events != null){
            for(WatchEvent<?> e : events){
                //事件处理
                final WatchEvent<Path> watchEventPath = (WatchEvent<Path>)e; 
                final Path filename = watchEventPath.context(); 
                
                final Path directory_path = directories.get(watchKey); 
                final Path child = directory_path.resolve(filename); 
                boolean isChildDirectory = Files.isDirectory(child, LinkOption.NOFOLLOW_LINKS);
                
                if(e.kind() == StandardWatchEventKinds.ENTRY_CREATE){
                    if(isChildDirectory){
                        registerTree(child); 
                    }else{
                        updateSqlFile(child.toFile(),false);
                    }
                    logger.info("新增文件:"+child.toAbsolutePath());
                }else if(e.kind() == StandardWatchEventKinds.ENTRY_MODIFY){
                    boolean isExsist = child.toFile().exists(); 
                    if(isExsist && !isChildDirectory){
                        updateSqlFile(child.toFile(),false);
                        logger.info("更新sql文件:"+child.toAbsolutePath());
                    }
                }else if(e.kind() == StandardWatchEventKinds.ENTRY_DELETE){
                    updateSqlFile(child.toFile(),true);
                    logger.info("删除文件:"+child.toAbsolutePath());
                }
            }
        }
        if(!watchKey.reset()){
            Path pth = directories.remove(watchKey);
            watchKey.cancel();
            logger.error("移除sql文件目录"+pth.toString()+"监控服务");
            if(directories.isEmpty()){
                break;
            }
        }
    }
    running = false;
    watchService.close();
}
 
开发者ID:javen-hao,项目名称:osmp,代码行数:51,代码来源:SqlStatementMonitor.java


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