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


Java SensitivityWatchEventModifier类代码示例

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


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

示例1: addProblem

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public ProblemSync addProblem(Problem newProblem) throws IOException {
    ProblemSync newProblemSync = new ProblemSync(workspaceDirectory, newProblem);
    String directory = newProblemSync.getDirectory();
    for (ProblemSync problemSync : problemSyncs) {
        if (problemSync.getDirectory().equals(directory)) {
            throw new IOException("Problem with such directory already exists: " + problemSync.getDirectory());
        }
    }
    newProblemSync.initialize();
    synchronized (workspaceWatcher) {
        problemSyncs.add(newProblemSync);
        WatchKey key = Paths.get(directory).register(workspaceWatcher,
                new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
                SensitivityWatchEventModifier.HIGH);
        watchKeys.add(key);
    }
    return newProblemSync;
}
 
开发者ID:AlCash07,项目名称:ACHelper,代码行数:19,代码来源:WorkspaceManager.java

示例2: JavaWatchObserver

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public JavaWatchObserver(File fileToWatch) throws IOException {
    if (fileToWatch == null || !fileToWatch.exists()) {
        throw new RuntimeException("fileToWatch must not be null and must already exist.");
    }
    this.fileToWatch = fileToWatch;
    lastModified = fileToWatch.lastModified();
    length = fileToWatch.length();

    watchService = FileSystems.getDefault().newWatchService();
    // Note that poll depends on us only registering events that are of type path
    if (OsData.getOsType() != OsData.OsType.MAC) {
        key = fileToWatch.getParentFile().toPath().register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
                StandardWatchEventKinds.ENTRY_MODIFY);
    } else {
        // Unfortunately the default watch service on Mac is broken, it uses a separate thread and really slow polling to detect file changes
        // rather than integrating with the OS. There is a hack to make it poll faster which we can use for now. See
        // http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
        key = fileToWatch.getParentFile().toPath().register(watchService, new WatchEvent.Kind[]
                {StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
                StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);
    }
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:23,代码来源:JavaWatchObserver.java

示例3: watch

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void watch(
        final Path dir,
        final Kind<Path>[] kinds) throws IOException {

    WatchService service = FileSystems.getDefault().newWatchService();
    // Rationale for SensitivityWatchEventModifier.HIGH: 
    // http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
    dir.register(
            service,
            kinds,
            SensitivityWatchEventModifier.HIGH);

    m_logger.info("Watching directory: {}", dir);
    m_watcher = new WatcherThread(service, m_eventBus);
    m_watcher.start(); // Start watcher thread
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:17,代码来源:NioDirWatcher.java

示例4: observePathSet

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void observePathSet(PathSet pathSet, Listener listener) throws IOException {
    Preconditions.checkNotNull(listener);
    Preconditions.checkNotNull(pathSet);

    final Path rootPath = pathSet.getRootPath();

    log.debug("Watching directory {} for changes matching: {}", rootPath, pathSet);

    final WatchKey key = rootPath.register(watcher, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
            SensitivityWatchEventModifier.HIGH);

    // Synchronize on keys to make the two operations atomic.
    synchronized (keys) {
        keys.putIfAbsent(key, Sets.<WatchPath>newConcurrentHashSet());
        keys.get(key).add(new WatchPath(pathSet, listener));
    }
}
 
开发者ID:graylog-labs,项目名称:collector,代码行数:18,代码来源:FileObserver.java

示例5: register

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
 * Register the given directory with the WatchService
 */
private void register(Path dir) throws IOException {
    WatchKey key = dir.register(watcher, new WatchEvent.Kind[]{
            ENTRY_CREATE,
            ENTRY_DELETE,
            ENTRY_MODIFY,
    }, SensitivityWatchEventModifier.HIGH);

    Path prev = keys.get(key);
    if (prev == null) {
        System.out.format("register: %s\n", dir);
    } else {
        if (!dir.equals(prev)) {
            System.out.format("update: %s -> %s\n", prev, dir);
        }
    }

    keys.put(key, dir);
}
 
开发者ID:omnidrive,项目名称:omnidrive,代码行数:22,代码来源:DirWatcher.java

示例6: addWatch

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void addWatch(final String directoryToWatch) throws IOException {

        final Path path = Paths.get(directoryToWatch);
        if (path == null) {
            throw new IllegalArgumentException("Directory " + directoryToWatch + " not found");
        }

        // Handlers
        mFileProcessor.addHandler(PathEventProcessor.PathEvent.EVENT_CREATE, new NewJpegFileHandler(path));

        final WatchService watcher = path.getFileSystem().newWatchService();
        final QueueReader queueReader = new QueueReader(watcher);
        final Thread thread = new Thread(queueReader, "FileWatcher" + (int) (Math.random() * 10000));

        // Register operations
        path.register(watcher, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_CREATE}, SensitivityWatchEventModifier.HIGH);
        mThreadList.add(thread);
    }
 
开发者ID:rizzow,项目名称:atombox-standalone,代码行数:19,代码来源:PathWatcher.java

示例7: observePathSet

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void observePathSet(PathSet pathSet, Listener listener) throws IOException {
    Preconditions.checkNotNull(listener);
    Preconditions.checkNotNull(pathSet);

    final Path rootPath = pathSet.getRootPath();

    log.debug("Watching directory {} for changes matching: {}", rootPath, pathSet);

    final WatchKey key = rootPath.register(watcher, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
            SensitivityWatchEventModifier.HIGH);

    // Synchronize on keys to make the two operations atomic.
    synchronized (keys) {
        keys.putIfAbsent(key, Sets.newConcurrentHashSet());
        keys.get(key).add(new WatchPath(pathSet, listener));
    }
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:18,代码来源:FileObserver.java

示例8: walkFiles

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void walkFiles( File folder, Kind[] events) throws IOException {
    Queue<File> dirsq = new LinkedList<>();
    dirsq.add(folder);

    while (!dirsq.isEmpty()) {
        for (File f : dirsq.poll().listFiles()) {
            if (f.isDirectory()) {
                dirsq.add(f);
                f.toPath().register(folderWatcher, events, SensitivityWatchEventModifier.HIGH);
            }
        }
    }
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:14,代码来源:RealTimeFolderWatcher.java

示例9: doPrivilegedRegister

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private PollingWatchKey doPrivilegedRegister(Path path,
                                             Set<? extends WatchEvent.Kind<?>> events,
                                             SensitivityWatchEventModifier sensivity)
    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, sensivity.sensitivityValueInSeconds());
        return watchKey;
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:PollingWatchService.java

示例10: register

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
static void register(Path[] dirs, WatchService watcher) throws IOException {
    SensitivityWatchEventModifier[] sensitivtives =
        SensitivityWatchEventModifier.values();
    for (int i=0; i<dirs.length; i++) {
        SensitivityWatchEventModifier sensivity =
            sensitivtives[ rand.nextInt(sensitivtives.length) ];
        Path dir = dirs[i];
        dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_MODIFY }, sensivity);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:SensitivityModifier.java

示例11: registerWatcherForFolder

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private void registerWatcherForFolder(IWatchEventHandler handler, String folder) {
    Path itemsDir = FileSystems.getDefault().getPath(folder);
    try {
        if (new File(itemsDir.toString()).isDirectory()) {
            itemsDir.register(watcher, new WatchEvent.Kind[]{
                    StandardWatchEventKinds.ENTRY_MODIFY,
                    StandardWatchEventKinds.ENTRY_CREATE,
                    StandardWatchEventKinds.ENTRY_DELETE
            }, SensitivityWatchEventModifier.HIGH);
            Log.fine("Folder registered with watcher {0}", folder);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:StallionCMS,项目名称:stallion-core,代码行数:16,代码来源:FileSystemWatcherRunner.java

示例12: register

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private void register(Path dir) throws IOException {
    WatchKey key = dir.register(watcher, new WatchEvent.Kind[]{
            StandardWatchEventKinds.ENTRY_CREATE,
            StandardWatchEventKinds.ENTRY_DELETE,
            StandardWatchEventKinds.ENTRY_MODIFY
    }, SensitivityWatchEventModifier.HIGH);
    keys.put(key, dir);
}
 
开发者ID:JavaEden,项目名称:Orchid,代码行数:9,代码来源:FileWatcher.java

示例13: register

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
     * Register the given directory with the WatchService
     */
    private void register(Path dir) throws IOException {
//        WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    	// following works better on Mac OS X, which as of Java7 does not use native watchservice.  OS X still slow relative to PC.  See:
    	WatchKey key;
    	// http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
    	try {		// Windows (only) supports built-in recursive monitoring
    		key = dir.register(watcher, new WatchEvent.Kind[]{ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE}, SensitivityWatchEventModifier.HIGH, ExtendedWatchEventModifier.FILE_TREE);
    	} catch(Exception e) {
    		key = dir.register(watcher, new WatchEvent.Kind[]{ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE}, SensitivityWatchEventModifier.HIGH);
    	}
    	
        keys.put(key, dir);
    }
 
开发者ID:cycronix,项目名称:cloudturbine,代码行数:17,代码来源:CTsync.java

示例14: WatcherPinListener

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public WatcherPinListener(Pin pin) throws IOException {
    super();
    this.pin = pin;
    service = FileSystems.getDefault().newWatchService();

    try {
        key = pin.getPath().toPath().getParent().register(service, new WatchEvent.Kind[]{ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);

    } catch (IOException e) {
        Logger.error(TAG, "Error at registering pin %s", e, pin.getCode());
        throw e;
    }
}
 
开发者ID:serayuzgur,项目名称:heartbeat,代码行数:14,代码来源:WatcherPinListener.java

示例15: WatchThread

import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
 * @param dir the directory to watch
 * @throws IOException if there's a problem watching the directory
 */
public WatchThread(Path dir) throws IOException {
	setName(getClass().getSimpleName());
	setDaemon(true);

	this.dir = dir;
	watcher = FileSystems.getDefault().newWatchService();
	dir.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY }, SensitivityWatchEventModifier.HIGH);
}
 
开发者ID:Unihedro,项目名称:JavaBot,代码行数:13,代码来源:JavadocDao.java


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