public class WatchServer extends Thread implements Closeable, Serializable
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected WatchEvent.Kind<?>[] |
events
监听事件列表
|
protected boolean |
isClosed
监听是否已经关闭
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
WatchServer() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
关闭监听
|
void |
init()
初始化
初始化包括: |
void |
registerPath(Path path,
int maxDepth)
将指定路径加入到监听中
|
void |
setModifiers(WatchEvent.Modifier[] modifiers)
设置监听选项,例如监听频率等,可设置项包括:
|
void |
watch(Watcher watcher,
Filter<WatchEvent<?>> watchFilter)
执行事件获取并处理
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldprotected WatchEvent.Kind<?>[] events
protected boolean isClosed
public void init()
throws InstrumentException
1、解析传入的路径,判断其为目录还是文件
2、创建WatchService 对象
InstrumentException - 监听异常,IO异常时抛出此异常public void setModifiers(WatchEvent.Modifier[] modifiers)
1、com.sun.nio.file.StandardWatchEventKinds 2、com.sun.nio.file.SensitivityWatchEventModifier
modifiers - 监听选项,例如监听频率等public void registerPath(Path path, int maxDepth)
path - 路径maxDepth - 递归下层目录的最大深度public void watch(Watcher watcher, Filter<WatchEvent<?>> watchFilter)
watcher - WatcherwatchFilter - 监听过滤接口,通过实现此接口过滤掉不需要监听的情况,null表示不过滤public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2020. All rights reserved.