Package org.aoju.bus.core.io.watcher
Class WatchMonitor
java.lang.Object
java.lang.Thread
org.aoju.bus.core.io.watcher.WatchServer
org.aoju.bus.core.io.watcher.WatchMonitor
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable,Runnable
路径监听器 监听器可监听目录或文件 如果监听的Path不存在,则递归创建空目录然后监听此空目录 递归监听目录时,并不会监听新创建的目录
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final WatchEvent.Kind<?> 创建事件static final WatchEvent.Kind<?> 删除事件static final WatchEvent.Kind<?> 修改事件static final WatchEvent.Kind<?>[]全部事件static final WatchEvent.Kind<?> 事件丢失Fields inherited from class org.aoju.bus.core.io.watcher.WatchServer
events, isClosedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionWatchMonitor(File file, WatchEvent.Kind<?>... events) 构造WatchMonitor(String path, WatchEvent.Kind<?>... events) 构造WatchMonitor(Path path, int maxDepth, WatchEvent.Kind<?>... events) 构造
例如设置:WatchMonitor(Path path, WatchEvent.Kind<?>... events) 构造 -
Method Summary
Modifier and TypeMethodDescriptionvoidinit()初始化
初始化包括:static WatchMonitorof(File file, int maxDepth, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(File file, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(String path, int maxDepth, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(String path, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(URI uri, int maxDepth, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(URI uri, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(URL url, int maxDepth, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(URL url, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(Path path, int maxDepth, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitorof(Path path, WatchEvent.Kind<?>... events) 创建并初始化监听static WatchMonitor创建并初始化监听,监听所有事件static WatchMonitor创建并初始化监听,监听所有事件static WatchMonitor创建并初始化监听,监听所有事件static WatchMonitor创建并初始化监听,监听所有事件static WatchMonitor创建并初始化监听,监听所有事件voidrun()setMaxDepth(int maxDepth) 当监听目录时,监听目录的最大深度
当设置值为1(或小于1)时,表示不递归监听子目录 例如设置:setWatcher(Watcher watcher) 设置监听 多个监听请使用WatcherChainvoidwatch()开始监听事件,阻塞当前进程void开始监听事件,阻塞当前进程Methods inherited from class org.aoju.bus.core.io.watcher.WatchServer
close, registerPath, setModifiers, watch, watchMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
OVERFLOW
事件丢失 -
ENTRY_MODIFY
修改事件 -
ENTRY_CREATE
创建事件 -
ENTRY_DELETE
删除事件 -
EVENTS_ALL
全部事件
-
-
Constructor Details
-
WatchMonitor
构造- Parameters:
file- 文件events- 监听的事件列表
-
WatchMonitor
构造- Parameters:
path- 字符串路径events- 监听的事件列表
-
WatchMonitor
构造- Parameters:
path- 字符串路径events- 监听事件列表
-
WatchMonitor
构造
例如设置:maxDepth <= 1 表示只监听当前目录 maxDepth = 2 表示监听当前目录以及下层目录 maxDepth = 3 表示监听当前目录以及下两层
- Parameters:
path- 字符串路径maxDepth- 递归目录的最大深度,当小于2时不递归下层目录events- 监听事件列表
-
-
Method Details
-
of
创建并初始化监听- Parameters:
url- URLevents- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
url- URLmaxDepth- 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
uri- URIevents- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
uri- URImaxDepth- 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
file- 文件events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
file- 文件maxDepth- 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
path- 路径events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
path- 路径maxDepth- 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录events- 监听的事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
path- 路径events- 监听事件列表- Returns:
- 监听对象
-
of
创建并初始化监听- Parameters:
path- 路径maxDepth- 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录events- 监听事件列表- Returns:
- 监听对象
-
ofAll
创建并初始化监听,监听所有事件- Parameters:
uri- URIwatcher-Watcher- Returns:
WatchMonitor
-
ofAll
创建并初始化监听,监听所有事件- Parameters:
url- URLwatcher-Watcher- Returns:
WatchMonitor
-
ofAll
创建并初始化监听,监听所有事件- Parameters:
file- 被监听文件watcher-Watcher- Returns:
WatchMonitor
-
ofAll
创建并初始化监听,监听所有事件- Parameters:
path- 路径watcher-Watcher- Returns:
WatchMonitor
-
ofAll
创建并初始化监听,监听所有事件- Parameters:
path- 路径watcher-Watcher- Returns:
WatchMonitor
-
init
初始化
初始化包括:1、解析传入的路径,判断其为目录还是文件 2、创建
WatchService对象- Overrides:
initin classWatchServer- Throws:
InternalException- 监听异常,IO异常时抛出此异常
-
setWatcher
设置监听 多个监听请使用WatcherChain- Parameters:
watcher- 监听- Returns:
WatchMonitor
-
run
-
watch
public void watch()开始监听事件,阻塞当前进程 -
watch
开始监听事件,阻塞当前进程- Parameters:
watcher- 监听- Throws:
InternalException- 监听异常,如果监听关闭抛出此异常
-
setMaxDepth
当监听目录时,监听目录的最大深度
当设置值为1(或小于1)时,表示不递归监听子目录 例如设置:maxDepth <= 1 表示只监听当前目录 maxDepth = 2 表示监听当前目录以及下层目录 maxDepth = 3 表示监听当前目录以及下层
- Parameters:
maxDepth- 最大深度,当设置值为1(或小于1)时,表示不递归监听子目录,监听所有子目录请传Integer.MAX_VALUE- Returns:
- this
-