本文整理匯總了Java中java.nio.file.StandardWatchEventKinds.OVERFLOW屬性的典型用法代碼示例。如果您正苦於以下問題:Java StandardWatchEventKinds.OVERFLOW屬性的具體用法?Java StandardWatchEventKinds.OVERFLOW怎麽用?Java StandardWatchEventKinds.OVERFLOW使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.nio.file.StandardWatchEventKinds
的用法示例。
在下文中一共展示了StandardWatchEventKinds.OVERFLOW屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleEvent
@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 );
}
}
示例2: run
@Override
public void run() {
while (true) {
try {
WatchKey key = watchService.take();
if (key == trustedKey) {
for (WatchEvent<?> watchEvent : key.pollEvents()) {
WatchEvent.Kind<?> kind = watchEvent.kind();
if (kind != StandardWatchEventKinds.OVERFLOW) {
synchronizeTrustedCertificates();
}
}
}
if (!key.reset()) {
break;
}
} catch (InterruptedException e) {
logger.error("Watcher interrupted.", e);
}
}
}
示例3: run
@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) {}
}
}
示例4: processEvent
/** 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();
}
}
示例5: handleEvent
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);
}
}
}
}
示例6: createOverflowEvent
private WatchEvent<Object> createOverflowEvent() {
return new WatchEvent<Object>() {
@Override
public Kind<Object> kind() {
return StandardWatchEventKinds.OVERFLOW;
}
@Override
public int count() {
return 1;
}
@Override
public Object context() {
return null;
}
@Override
public String toString() {
return "Watchman Overflow WatchEvent " + kind();
}
};
}
示例7: testCreateContextStringForOverflowEvent
@Test
public void testCreateContextStringForOverflowEvent() {
WatchEvent<Object> overflowEvent = new WatchEvent<Object>() {
@Override
public Kind<Object> kind() {
return StandardWatchEventKinds.OVERFLOW;
}
@Override
public int count() {
return 0;
}
@Override
public Object context() {
return new Object() {
@Override
public String toString() {
return "I am the context string.";
}
};
}
};
assertEquals("I am the context string.", filesystem.createContextString(overflowEvent));
}
示例8: createOverflowEvent
public static WatchEvent<Object> createOverflowEvent() {
return new WatchEvent<Object>() {
@Override
public Kind<Object> kind() {
return StandardWatchEventKinds.OVERFLOW;
}
@Override
public int count() {
return 0;
}
@Override
public Object context() {
return null;
}
};
}
示例9: processFileSystemChanges
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);
}
}
}
}
示例10: processChange
void processChange(final WatchEvent.Kind<?> kind, final Path changedAbsPath, final boolean isDirectory) {
if (isDirectory) {
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
listener.directoryCreated(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
listener.directoryModified(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
listener.directoryDeleted(changedAbsPath);
} else if (kind == StandardWatchEventKinds.OVERFLOW) {
if (Files.exists(changedAbsPath)) {
log.info("Having an event overflow for '{}'. Entire directory '{}' will be recreated",
changedAbsPath, changedAbsPath);
listener.directoryCreated(changedAbsPath);
} else {
log.info("Having an event overflow for non existing directory '{}'. Directory will be removed",
changedAbsPath, changedAbsPath);
listener.directoryDeleted(changedAbsPath);
}
}
} else {
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
listener.fileCreated(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
listener.fileModified(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
listener.fileDeleted(changedAbsPath);
} else if (kind == StandardWatchEventKinds.OVERFLOW) {
throw new IllegalStateException("Only a directory should even possibly overflow in events, for example" +
" by saving 1000 new files in one go.");
}
}
}
示例11: signalEvent
/**
* Adds the event to this key and signals it.
*
* @param kind event kind
* @param context context
*/
@SuppressWarnings("unchecked")
final void signalEvent(WatchEvent.Kind<?> kind, Object context) {
synchronized(this) {
int size = events.size();
if(size > 1) {
// don't let list get too big
if(size >= MAX_EVENT_LIST_SIZE) {
kind = StandardWatchEventKinds.OVERFLOW;
context = null;
}
// repeated event
WatchEvent<?> prev = events.get(size - 1);
if(kind == prev.kind()) {
boolean isRepeat;
if(context == null) {
isRepeat = (prev.context() == null);
}
else {
isRepeat = context.equals(prev.context());
}
if(isRepeat) {
((Event<?>) prev).increment();
return;
}
}
}
// non-repeated event
events.add(new Event<Object>((WatchEvent.Kind<Object>) kind, context));
signal();
}
}
示例12: pollConfigFileForChanges
/**
* Polls the configuration file for changes.
*/
private void pollConfigFileForChanges() {
WatchKey key = watcher.poll();
try {
if (key == null) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
Kind<?> kind = event.kind();
if (StandardWatchEventKinds.OVERFLOW == kind) {
continue;
}
// The filename is the context of the event.
Path filename = (Path) event.context();
if (configFile.endsWith(filename.toString())) {
LOG.info("CORS Filter: Detected change in " + configFile + " , configuration reload required");
reloadRequired = true;
}
}
} finally {
if (key != null) {
key.reset();
}
}
}
示例13: FileSystemEvent
FileSystemEvent(WatchEvent event) {
WatchEvent.Kind kind = event.kind();
if (StandardWatchEventKinds.OVERFLOW != kind) {
this.path = (Path) event.context();
}
this.fileSystemEventKind = FileSystemEventKind.toFileSystemEventKind(kind);
}
示例14: run
@Override
public void run() {
while (running) {
WatchKey key;
try {
key = watcher.take();
} catch (InterruptedException ex) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
@SuppressWarnings("unchecked")
WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path fileName = ev.context();
if (kind == StandardWatchEventKinds.OVERFLOW) {
continue;
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
if (fileName.equals(this.lockFile.getFileName())) {
running = false;
}
}
}
boolean valid = key.reset();
if (!valid) {
break;
}
}
try {
watcher.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: watchRNDir
public void watchRNDir(Path path) throws IOException, InterruptedException {
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
//給path路徑加上文件觀察服務
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_DELETE);
// start an infinite loop
while (true) {
// retrieve and remove the next watch key
final WatchKey key = watchService.take();
// get list of pending events for the watch key
for (WatchEvent<?> watchEvent : key.pollEvents()) {
// get the kind of event (create, modify, delete)
final Kind<?> kind = watchEvent.kind();
// handle OVERFLOW event
if (kind == StandardWatchEventKinds.OVERFLOW) {
continue;
}
//創建事件
if(kind == StandardWatchEventKinds.ENTRY_CREATE){
}
//修改事件
if(kind == StandardWatchEventKinds.ENTRY_MODIFY){
}
//刪除事件
if(kind == StandardWatchEventKinds.ENTRY_DELETE){
}
// get the filename for the event
@SuppressWarnings("unchecked")
final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;
final Path filename = watchEventPath.context();
// print it out
System.out.println(kind + " -> " + filename);
}
// reset the keyf
boolean valid = key.reset();
// exit loop if the key is not valid (if the directory was
// deleted, for
if (!valid) {
break;
}
}
}
}