Package engineering.swat.watch.impl.jdk
Class JDKBaseWatch
- java.lang.Object
-
- engineering.swat.watch.impl.jdk.JDKBaseWatch
-
- All Implemented Interfaces:
ActiveWatch
,EventHandlingWatch
,Closeable
,AutoCloseable
- Direct Known Subclasses:
JDKDirectoryWatch
,JDKFileTreeWatch
,JDKFileWatch
public abstract class JDKBaseWatch extends Object implements EventHandlingWatch
-
-
Field Summary
Fields Modifier and Type Field Description protected Predicate<WatchEvent>
eventFilter
protected BiConsumer<EventHandlingWatch,WatchEvent>
eventHandler
protected Executor
exec
protected Path
path
protected AtomicBoolean
started
-
Constructor Summary
Constructors Modifier Constructor Description protected
JDKBaseWatch(Path path, Executor exec, BiConsumer<EventHandlingWatch,WatchEvent> eventHandler, Predicate<WatchEvent> eventFilter)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Path
getPath()
Gets the path watched by this watch.void
handleEvent(WatchEvent e)
Handles `event`.void
open()
protected abstract void
start()
Starts this watch.protected boolean
startIfFirstTime()
Starts this watch if it's the first time.protected WatchEvent.Kind
translate(WatchEvent.Kind<?> jdkKind)
protected WatchEvent
translate(WatchEvent<?> jdkEvent)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface engineering.swat.watch.ActiveWatch
getScope
-
Methods inherited from interface engineering.swat.watch.impl.EventHandlingWatch
relativize
-
-
-
-
Field Detail
-
path
protected final Path path
-
exec
protected final Executor exec
-
eventHandler
protected final BiConsumer<EventHandlingWatch,WatchEvent> eventHandler
-
eventFilter
protected final Predicate<WatchEvent> eventFilter
-
started
protected final AtomicBoolean started
-
-
Constructor Detail
-
JDKBaseWatch
protected JDKBaseWatch(Path path, Executor exec, BiConsumer<EventHandlingWatch,WatchEvent> eventHandler, Predicate<WatchEvent> eventFilter)
-
-
Method Detail
-
open
public void open() throws IOException
- Throws:
IOException
-
start
protected abstract void start() throws IOException
Starts this watch.- Throws:
IOException
- When an I/O exception of some sort has occurred (e.g., a nested watch failed to start)
-
startIfFirstTime
protected boolean startIfFirstTime() throws IOException
Starts this watch if it's the first time.- Returns:
- `true` iff it's the first time this method is called
- Throws:
IOException
- When an I/O exception of some sort has occurred (e.g., a nested watch failed to start)
-
translate
protected WatchEvent translate(WatchEvent<?> jdkEvent)
-
translate
protected WatchEvent.Kind translate(WatchEvent.Kind<?> jdkKind)
-
getPath
public Path getPath()
Description copied from interface:ActiveWatch
Gets the path watched by this watch.- Specified by:
getPath
in interfaceActiveWatch
-
handleEvent
public void handleEvent(WatchEvent e)
Description copied from interface:EventHandlingWatch
Handles `event`. The purpose of this method is to trigger the event handler of this watch "from the outside" (in addition to having native file system libraries trigger the event handler "from the inside"). This is useful to report synthetic events (e.g., while handling overflows).- Specified by:
handleEvent
in interfaceEventHandlingWatch
-
-