本文整理汇总了Java中java.nio.file.WatchEvent.kind方法的典型用法代码示例。如果您正苦于以下问题:Java WatchEvent.kind方法的具体用法?Java WatchEvent.kind怎么用?Java WatchEvent.kind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.WatchEvent
的用法示例。
在下文中一共展示了WatchEvent.kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextEvent
import java.nio.file.WatchEvent; //导入方法依赖的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;
}
示例2: run
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public void run() {
WatchService watchService = WatchServiceUtil.watchModify(pluginDir);
WatchKey key;
while (watchService != null){
try {
key = watchService.take();
for (WatchEvent<?> watchEvent : key.pollEvents()) {
if(watchEvent.kind() == ENTRY_MODIFY){
String fileName = watchEvent.context() == null ? "" : watchEvent.context().toString();
Plugin plugin = PluginLibraryHelper.getPluginByConfigFileName(fileName);
if(plugin != null){
plugin.init(PluginLibraryHelper.getPluginConfig(plugin));
log.info("已完成插件{}的配置重新加载",plugin.pluginName());
}
}
}
key.reset();
} catch (Exception e) {
log.error("插件配置文件监听异常",e);
break;
}
}
}
示例3: processSubevents
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
/**
* Processes subevents of the key.
* @param key That has new events.
* @param dir For the key.
* @throws IOException If a subdirectory cannot be registered.
*/
private void processSubevents(final WatchKey key, final Path dir)
throws IOException {
for (final WatchEvent event : key.pollEvents()) {
final WatchEvent.Kind kind = event.kind();
final Path name = (Path) event.context();
final Path child = dir.resolve(name);
Logger.debug(
this,
"%s: %s%n", event.kind().name(), child
);
if (kind == ENTRY_CREATE) {
try {
if (Files.isDirectory(child)) {
this.processSubevents(child);
}
} catch (final IOException ex) {
throw new IOException(
"Failed to register subdirectories.",
ex
);
}
}
}
}
示例4: run
import java.nio.file.WatchEvent; //导入方法依赖的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) {}
}
}
示例5: processWatchEvent
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
/**
* Handles a watchevent, it currently only handles the DELETE and MODIFY - create isn't handled
* as when you create a new file you get two events - one of the create and one for the modify,
* therefore it can be safely handled in the modify only.
*
* If the delete corresponds to a adapter loaded - it deregisterWithAdapterManager it with the
* adatperManager If the modify is new / modified it passes it to the load method that handles
* re-registering existing adapters
*
* @param event
*/
public void processWatchEvent(final WatchEvent<?> event) {
synchronized (propertiesToAdapter) {
if (LOG.isInfoEnabled()) {
LOG.info("Logging watch event:" + event.kind() + ": " + event.context());
}
// check it is ended with .properties
if (isPropertyFile(event)) {
String path = ((Path) event.context()).toString();
Adapter adapter = propertiesToAdapter.get(path);
// if we have already seen this then deregister it
if (adapter != null) {
removeAdapter(path, adapter);
}
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE
|| event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
File file = new File(getPathToWatch().toString(), ((Path) event.context()).toString());
load(file);
}
}
}
}
示例6: processEvent
import java.nio.file.WatchEvent; //导入方法依赖的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();
}
}
示例7: processWatchKey
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private void processWatchKey(WatchKey watchKey) throws IOException {
final long start = System.currentTimeMillis();
final List<WatchEvent<?>> events = watchKey.pollEvents();
int processed = 0;
for (WatchEvent<?> event : events) {
WatchEvent.Kind<?> kind = event.kind();
if (!watchEvents.contains(kind)) {
LOG.trace("Ignoring an {} event to {}", event.context());
continue;
}
WatchEvent<Path> ev = cast(event);
Path filename = ev.context();
if (processEvent(kind, filename)) {
processed++;
}
}
LOG.debug("Handled {} out of {} event(s) for {} in {}", processed, events.size(), watchDirectory, JavaUtils.duration(start));
}
示例8: handleEvent
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private void handleEvent(final WatchKeyHolder watchKeys, final WatchKey key) throws IOException {
for (final WatchEvent<?> event : key.pollEvents()) {
if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
continue;
}
final WatchEvent<Path> watchEvent = cast(event);
Path path = watchKeys.get(key);
if (path == null) {
continue;
}
path = path.resolve(watchEvent.context());
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
watchKeys.register(path);
}
} else {
// Dispatch
FileEvent fe = toEvent(watchEvent, path);
if (fe != null) {
this.eventBus.post(fe);
}
}
}
}
示例9: run
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
public void run() {
Logger.info(TAG, "Modified %s STARTED", pin.getCode());
while (!closed) {
WatchKey key = null;
try {
key = service.take();
} catch (InterruptedException e) {
}
if (this.key.equals(key)) {
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (!kind.equals(ENTRY_MODIFY) || !event.context().toString().equals(pin.getPath().getName()))
continue;
onChange(pin);
}
}
boolean valid = key.reset();
if (!valid) {
break;
}
}
}
示例10: handleEvent
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
/**
* Handle event.
*
* @param key the key
*/
private void handleEvent(final WatchKey key) {
this.readLock.lock();
try {
for (final WatchEvent<?> event : key.pollEvents()) {
if (event.count() <= 1) {
final WatchEvent.Kind kind = event.kind();
//The filename is the context of the event.
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path filename = ev.context();
final Path parent = (Path) key.watchable();
final Path fullPath = parent.resolve(filename);
final File file = fullPath.toFile();
LOGGER.trace("Detected event [{}] on file [{}]. Loading change...", kind, file);
if (kind.name().equals(ENTRY_CREATE.name()) && file.exists()) {
handleCreateEvent(file);
} else if (kind.name().equals(ENTRY_DELETE.name())) {
handleDeleteEvent();
} else if (kind.name().equals(ENTRY_MODIFY.name()) && file.exists()) {
handleModifyEvent(file);
}
}
}
} finally {
this.readLock.unlock();
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:36,代码来源:JsonServiceRegistryConfigWatcher.java
示例11: run
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public void run() {
WatchService watchService = WatchServiceUtil.watchModify(confDir);
WatchKey key;
while (watchService != null){
try {
key = watchService.take();
for (WatchEvent<?> watchEvent : key.pollEvents()) {
if(watchEvent.kind() == ENTRY_MODIFY){
String fileName = watchEvent.context() == null ? "" : watchEvent.context().toString();
if("authorization.properties".equals(fileName)){
log.info("检测到授权文件authorization.properties有改动,正在重新配置相关插件配置");
Set<Plugin> plugins = PluginLibraryHelper.getPluginsAboutAuthorization();
for (Plugin plugin : plugins) {
plugin.init(PluginLibraryHelper.getPluginConfig(plugin));
log.info("已完成插件{}的配置重新加载",plugin.pluginName());
}
}
}
}
key.reset();
} catch (Exception e) {
log.error("插件配置文件监听异常",e);
break;
}
}
}
示例12: handleEvent
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
public void handleEvent ( final Path watchable, final WatchEvent<?> event ) throws IOException
{
final Path path = (Path)event.context ();
logger.debug ( "Change {} for base: {} on {}", new Object[] { event.kind (), watchable, path } );
if ( watchable.endsWith ( "native" ) && path.toString ().equals ( "settings.xml" ) )
{
if ( event.kind () != StandardWatchEventKinds.ENTRY_DELETE )
{
check ();
}
else
{
storageRemoved ();
}
}
else
{
if ( path.toString ().equals ( "settings.xml" ) )
{
if ( event.kind () == StandardWatchEventKinds.ENTRY_CREATE )
{
this.nativeKey = new File ( watchable.toFile (), "native" ).toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE );
}
}
else if ( path.toString ().endsWith ( ".hds" ) )
{
if ( this.id != null )
{
this.storageManager.fileChanged ( this.path.toFile (), this.id, path.toFile () );
}
}
}
}
示例13: checkBaseEvents
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private void checkBaseEvents ( final WatchKey key, final List<WatchEvent<?>> events )
{
for ( final WatchEvent<?> event : events )
{
if ( ! ( event.context () instanceof Path ) )
{
continue;
}
final Path path = this.base.resolve ( (Path)event.context () );
logger.debug ( "Event for {}, {} : {} -> {}", new Object[] { event.context (), key.watchable (), event.kind (), path } );
if ( event.kind () == StandardWatchEventKinds.ENTRY_DELETE )
{
// check delete
checkDeleteStorage ( path );
}
else
{
try
{
checkAddStorage ( path );
}
catch ( final IOException e )
{
logger.warn ( "Failed to check for storage", e );
}
}
}
}
示例14: processFileSystemChanges
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private void processFileSystemChanges(final Path watchedDirectory, final WatchKey key) {
final ChangesProcessor processor = getChangesProcessorOrNull(watchedDirectory);
if (processor == null) {
log.warn("Ignoring change in {}: no change processor found", watchedDirectory);
return;
}
processor.start();
for (WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
final Object eventContext = event.context();
log.debug("Processing {} {} in {}", kind.name(), eventContext, watchedDirectory);
if (kind == StandardWatchEventKinds.OVERFLOW) {
log.info("event overflow in {}. Reimporting and registering watchedDirectory '{}' to avoid half synced state",
watchedDirectory, watchedDirectory);
if (Files.exists(watchedDirectory)) {
registerQuietly(watchedDirectory);
}
processor.processChange(kind, watchedDirectory, true);
} else {
final Path changedRelPath = (Path) eventContext;
final Path changedAbsPath = watchedDirectory.resolve(changedRelPath);
final boolean isDirectory = isDirectory(changedAbsPath, kind);
if (watchedFiles.matches(changedAbsPath, isDirectory)) {
if (isDirectory && kind == StandardWatchEventKinds.ENTRY_CREATE) {
registerQuietly(changedAbsPath);
}
processor.processChange(kind, changedAbsPath, isDirectory);
} else {
log.debug("Skipping excluded path {}", changedAbsPath);
}
}
}
}
示例15: callback
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private void callback(final Local folder, final WatchEvent<?> event, final FileWatcherListener l) {
final WatchEvent.Kind<?> kind = event.kind();
if(log.isInfoEnabled()) {
log.info(String.format("Process file system event %s for %s", kind.name(), event.context()));
}
if(ENTRY_MODIFY == kind) {
l.fileWritten(this.normalize(folder, event.context().toString()));
}
else if(ENTRY_DELETE == kind) {
l.fileDeleted(this.normalize(folder, event.context().toString()));
}
else if(ENTRY_CREATE == kind) {
l.fileCreated(this.normalize(folder, event.context().toString()));
}
else {
log.debug(String.format("Ignored file system event %s for %s", kind.name(), event.context()));
}
}