Package io.methvin.watchservice
Class MacOSXListeningWatchService
- java.lang.Object
-
- io.methvin.watchservice.MacOSXListeningWatchService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.file.WatchService
public class MacOSXListeningWatchService extends java.lang.Object
This class contains the bulk of my implementation of the Watch Service API. It hooks into Carbon's File System Events API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MacOSXListeningWatchService.CFRunLoopThread
static interface
MacOSXListeningWatchService.Config
Configuration for the watch service.
-
Constructor Summary
Constructors Constructor Description MacOSXListeningWatchService()
MacOSXListeningWatchService(MacOSXListeningWatchService.Config config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelled(io.methvin.watchservice.AbstractWatchKey key)
Called when the given key is cancelled.protected void
checkOpen()
Checks that the watch service is open, throwingClosedWatchServiceException
if not.void
close()
void
close(MacOSXListeningWatchService.CFRunLoopThread runLoopThread, CarbonAPI.FSEventStreamCallback callback, java.nio.file.Path path)
boolean
isOpen()
Returns whether or not this watch service is open.java.nio.file.WatchKey
poll()
java.nio.file.WatchKey
poll(long timeout, java.util.concurrent.TimeUnit unit)
io.methvin.watchservice.AbstractWatchKey
register(WatchablePath watchable, java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> events)
Registers the given watchable with this service, returning a new watch key for it.java.nio.file.WatchKey
take()
-
-
-
Constructor Detail
-
MacOSXListeningWatchService
public MacOSXListeningWatchService(MacOSXListeningWatchService.Config config)
-
MacOSXListeningWatchService
public MacOSXListeningWatchService()
-
-
Method Detail
-
register
public io.methvin.watchservice.AbstractWatchKey register(WatchablePath watchable, java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> events) throws java.io.IOException
Registers the given watchable with this service, returning a new watch key for it. This implementation just checks that the service is open and creates a key; subclasses may override it to do other things as well.- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfacejava.nio.file.WatchService
-
close
public void close(MacOSXListeningWatchService.CFRunLoopThread runLoopThread, CarbonAPI.FSEventStreamCallback callback, java.nio.file.Path path)
-
isOpen
public boolean isOpen()
Returns whether or not this watch service is open.
-
cancelled
public void cancelled(io.methvin.watchservice.AbstractWatchKey key)
Called when the given key is cancelled. Does nothing by default.
-
poll
public java.nio.file.WatchKey poll()
- Specified by:
poll
in interfacejava.nio.file.WatchService
-
poll
public java.nio.file.WatchKey poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
poll
in interfacejava.nio.file.WatchService
- Throws:
java.lang.InterruptedException
-
take
public java.nio.file.WatchKey take() throws java.lang.InterruptedException
- Specified by:
take
in interfacejava.nio.file.WatchService
- Throws:
java.lang.InterruptedException
-
checkOpen
protected final void checkOpen()
Checks that the watch service is open, throwingClosedWatchServiceException
if not.
-
-