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


Java Kind类代码示例

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


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

示例1: handleEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@SuppressWarnings ( "unchecked" )
private void handleEvent ( final WatchEvent<?> event )
{
    final Kind<?> kind = event.kind ();

    if ( kind == StandardWatchEventKinds.OVERFLOW )
    {
        // FIXME: full rescan
        return;
    }

    final Path path = this.path.resolve ( ( (WatchEvent<Path>)event ).context () );

    if ( kind == StandardWatchEventKinds.ENTRY_CREATE )
    {
        this.listener.event ( path, Event.ADDED );
    }
    else if ( kind == StandardWatchEventKinds.ENTRY_DELETE )
    {
        this.listener.event ( path, Event.REMOVED );
    }
    else if ( kind == StandardWatchEventKinds.ENTRY_MODIFY )
    {
        this.listener.event ( path, Event.MODIFIED );
    }
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:27,代码来源:Watcher.java

示例2: registerAll

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
/**
 * A method to register all the files which will be under the given start path to look
 * @param start the path to start the search files to be registered
 * @throws IOException 
 */
public void registerAll(Path start) throws IOException {
    try {
        // walk all folders here recursively call the below method for each folder(not file!) the variable dir is a Path Object!!!
        Kind[] events = { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY};
        walkFiles( start.toFile(), events);
        
        /*Files.walk(start)
            .filter(path -> Files.isDirectory(path))
            .forEach(path -> {
            try {
                path.register(folderWatcher, events, SensitivityWatchEventModifier.HIGH);
                // System.out.println("The reg path: " + path);
            } catch (IOException ex) {
                Logger.getLogger(RealTimeFolderWatcher.class.getName()).log(Level.SEVERE, null, ex);
            }
        });*/
    } catch (IOException ex) {
        Logger.getLogger(RealTimeFolderWatcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:26,代码来源:RealTimeFolderWatcher.java

示例3: run

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run() {
	while (running) {
		try {
			final WatchKey watchKey = watcher.take();
			for (final WatchEvent<?> event : watchKey.pollEvents()) {
				Path changed = (Path) event.context();
				if (changed == null || event.kind() == StandardWatchEventKinds.OVERFLOW) {
					System.out.println("bad file watch event: " + event);
					continue;
				}
				changed = watchedDirectory.resolve(changed);
				for (final ListenerAndPath x : listeners) {
					if (Thread.interrupted() && !running)
						return;
					if (changed.startsWith(x.startPath)) {
						x.listener.fileChanged(changed, (Kind<Path>) event.kind());
					}
				}
			}
			watchKey.reset();
		} catch (final InterruptedException e) {}
	}
}
 
开发者ID:Njol,项目名称:Motunautr,代码行数:26,代码来源:FileWatcher.java

示例4: processEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
/** Notify file system event. */
void processEvent() {
	while(true) {
		WatchKey signal;
		
		try {
			signal = watcher.take();
		} catch (InterruptedException e) {
			return;
		}
		
		for(WatchEvent<?> event : signal.pollEvents()) {
			Kind<?> kind = event.kind();
			
			if(kind == StandardWatchEventKinds.OVERFLOW) {
				continue;
			}
			
			Path name = (Path)event.context();
			notify(name.toAbsolutePath().toString(), kind);
		}
		
		key.reset();
	}
}
 
开发者ID:yoking-zhang,项目名称:demo,代码行数:26,代码来源:DirectoryWatcher.java

示例5: processEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@Override
protected boolean processEvent(Kind<?> kind, Path filename) throws IOException {
  if (!isMetadataFile(filename)) {
    return false;
  }

  LOG.trace("Handling {} event on {}", kind, filename);

  Optional<TailMetadata> tail = read(Paths.get(baseConfiguration.getLogWatcherMetadataDirectory()).resolve(filename));

  if (!tail.isPresent()) {
    return false;
  }

  synchronized (listeners) {
    for (TailMetadataListener listener : listeners) {
      listener.tailChanged(tail.get());
    }
  }
  return true;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:22,代码来源:FileBasedSimpleStore.java

示例6: processWatchEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
private void processWatchEvent(final Kind<Path> watchEventKind, final Path path) {
    final String dropboxPathLower = PathUtil.extractDropboxPath(localDir, path)
            .toLowerCase(Locale.getDefault());
    if (globalOperationsTracker.isTracked(dropboxPathLower)) {
        LOG.trace("Path already tracked. Skipping: {}", () -> path);
    } else {
        final LocalFolderChangeType changeType = LocalFolderChangeType
                .fromWatchEventKind(watchEventKind);

        final LocalFolderData localPathChange = new LocalFolderData(path,
                changeType);

        LOG.trace("Local event {} on path {}", changeType, path);

        try {
            localPathChanges.put(localPathChange);
        } catch (final Exception ex) {
            LOG.error("Interrupted", ex);
        }
    }
}
 
开发者ID:yuriytkach,项目名称:dsync-client,代码行数:22,代码来源:LocalFolderWatching.java

示例7: main

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
    String tempDirPath = "/tmp";
    System.out.println("Starting watcher for " + tempDirPath);
    Path p = Paths.get(tempDirPath);
    WatchService watcher = 
        FileSystems.getDefault().newWatchService();
    Kind<?>[] watchKinds = { ENTRY_CREATE, ENTRY_MODIFY };
    p.register(watcher, watchKinds);
    mainRunner = Thread.currentThread();
    new Thread(new DemoService()).start();
    while (!done) {
        WatchKey key = watcher.take();
        for (WatchEvent<?> e : key.pollEvents()) {
            System.out.println(
                "Saw event " + e.kind() + " on " + 
                e.context());
            if (e.context().toString().equals("MyFileSema.for")) {
                System.out.println("Semaphore found, shutting down watcher");
                done = true;
            }
        }
        if (!key.reset()) {
            System.err.println("Key failed to reset!");
        }
    }
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:27,代码来源:FileWatchServiceDemo.java

示例8: watch

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

示例9: EphemeralFsWatchKey

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
EphemeralFsWatchKey(
        EphemeralFsWatchService watchService, 
        EphemeralFsPath watchable,
        INode iNode,
        EphemeralFsFileSystem fs,
        Kind<?>... events) {
    this.watchService = watchService;
    if(!watchable.isAbsolute()) {
        throw new IllegalArgumentException("path must be absolute");
    }
    this.watchable = watchable;
    this.iNode = iNode;
    this.fs = fs;
    interestOps = new HashSet<>();
    for(Kind<?> event : events) {
        interestOps.add(event);
    }
            
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:20,代码来源:EphemeralFsWatchKey.java

示例10: processEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
private void processEvent(Path dir, WatchEvent<Path> event) {
    // Context for directory entry event is the file name of entry
    Path relChild = event.context();
    Path child = dir.resolve(relChild);

    Kind<Path> kind = event.kind();

    if(kind == ENTRY_MODIFY) {
        handleModification(child, externalInitiator);
    } else if(kind == ENTRY_CREATE) {
        handleCreation(child, externalInitiator);
    } else if(kind == ENTRY_DELETE) {
        model.delete(child, externalInitiator);
    } else {
        throw new AssertionError("unreachable code");
    }
}
 
开发者ID:TomasMikula,项目名称:LiveDirsFX,代码行数:18,代码来源:LiveDirs.java

示例11: handleEvent

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
/**
 * Precondition: Event and child must not be null.
 * @param kind type of the event (create, modify, ...)
 * @param source Identifies the related file.
 */
private void handleEvent(Kind<Path> kind, Path source) {
	try {
		if(PathUtils.isFileHidden(source)){
			return;
		}
		if (kind.equals(ENTRY_CREATE)) {
			addNotifyEvent(new NotifyFileCreated(source));
		} else if (kind.equals(ENTRY_MODIFY)) {
			addNotifyEvent(new NotifyFileModified(source));
		} else if (kind.equals(ENTRY_DELETE)) {
			addNotifyEvent(new NotifyFileDeleted(source));
		} else if (kind.equals(OVERFLOW)) {
			// error - overflow... should not happen here (continue if such an event occurs).
			// handled already
			logger.warn("Overflow event from watch service. Too many events?");
		} else {
			logger.warn("Unknown event received");
		}
	} catch (InterruptedException iex) {
		// put into queue failed
		logger.info("Handling event interrupted.", iex);
	}
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:29,代码来源:FolderWatchService.java

示例12: Watcher

import java.nio.file.WatchEvent.Kind; //导入依赖的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;
    while (!stopped && process) {
      process = processEvents();
    }
  }, "HotswapScanner");

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

示例13: registerTreeRecursive

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void registerTreeRecursive() throws Exception {
  new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class,
      WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class)
      .expect(newThread)
      .expect(registerTree(true, false))
      .expect(takeInterrupt)
      .run(unit -> {
        FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class),
            unit.get(WatchService.class),
            ImmutableSet.of(unit.get(FileEventOptions.class)));
        unit.captured(ThreadFactory.class).get(0).newThread(monitor);
      }, unit -> {
        unit.captured(Runnable.class).get(0).run();
        unit.captured(FileVisitor.class).get(0).preVisitDirectory(unit.get(Path.class), null);
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:FileMonitorTest.java

示例14: registerTree

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@Test
public void registerTree() throws Exception {
  new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class,
      WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class)
      .expect(newThread)
      .expect(registerTree(false, false))
      .expect(takeInterrupt)
      .run(unit -> {
        FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class),
            unit.get(WatchService.class),
            ImmutableSet.of(unit.get(FileEventOptions.class)));
        unit.captured(ThreadFactory.class).get(0).newThread(monitor);
      }, unit -> {
        unit.captured(Runnable.class).get(0).run();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:FileMonitorTest.java

示例15: registerTreeErr

import java.nio.file.WatchEvent.Kind; //导入依赖的package包/类
@Test
public void registerTreeErr() throws Exception {
  new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class,
      WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class)
      .expect(newThread)
      .expect(registerTree(false, true))
      .expect(takeInterrupt)
      .run(unit -> {
        FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class),
            unit.get(WatchService.class),
            ImmutableSet.of(unit.get(FileEventOptions.class)));
        unit.captured(ThreadFactory.class).get(0).newThread(monitor);
      }, unit -> {
        unit.captured(Runnable.class).get(0).run();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:FileMonitorTest.java


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