Package com.google.common.jimfs
Class PollingWatchService
java.lang.Object
com.google.common.jimfs.AbstractWatchService
com.google.common.jimfs.PollingWatchService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,WatchService
Implementation of
WatchService
that polls for changes to directories at registered paths.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Snapshot of the state of a directory at a particular moment.Nested classes/interfaces inherited from class com.google.common.jimfs.AbstractWatchService
AbstractWatchService.Event<T>, AbstractWatchService.Key
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileSystemState
(package private) final long
private final PathService
private ScheduledFuture
<?> private final ScheduledExecutorService
private final Runnable
private final ConcurrentMap
<AbstractWatchService.Key, PollingWatchService.Snapshot> Map of keys to the most recent directory snapshot for each key.private static final ThreadFactory
Thread factory for polling threads, which should be daemon threads so as not to keep the VM running if the user doesn't close the watch service or the file system.(package private) final TimeUnit
private final FileSystemView
-
Constructor Summary
ConstructorsConstructorDescriptionPollingWatchService
(FileSystemView view, PathService pathService, FileSystemState fileSystemState, long interval, TimeUnit timeUnit) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called when the given key is cancelled.private JimfsPath
checkWatchable
(Watchable watchable) void
close()
(package private) boolean
private boolean
isSameFileSystem
(Path path) register
(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) Registers the given watchable with this service, returning a new watch key for it.private void
private void
private PollingWatchService.Snapshot
takeSnapshot
(JimfsPath path) Methods inherited from class com.google.common.jimfs.AbstractWatchService
checkOpen, enqueue, isOpen, poll, poll, queuedKeys, take
-
Field Details
-
THREAD_FACTORY
Thread factory for polling threads, which should be daemon threads so as not to keep the VM running if the user doesn't close the watch service or the file system. -
pollingService
-
snapshots
Map of keys to the most recent directory snapshot for each key. -
view
-
pathService
-
fileSystemState
-
interval
final long interval -
timeUnit
-
pollingFuture
-
pollingTask
-
-
Constructor Details
-
PollingWatchService
PollingWatchService(FileSystemView view, PathService pathService, FileSystemState fileSystemState, long interval, TimeUnit timeUnit)
-
-
Method Details
-
register
@CanIgnoreReturnValue public AbstractWatchService.Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws IOException Description copied from class:AbstractWatchService
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.- Overrides:
register
in classAbstractWatchService
- Throws:
IOException
-
checkWatchable
-
isSameFileSystem
-
isPolling
boolean isPolling() -
cancelled
Description copied from class:AbstractWatchService
Called when the given key is cancelled. Does nothing by default.- Overrides:
cancelled
in classAbstractWatchService
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceWatchService
- Overrides:
close
in classAbstractWatchService
-
startPolling
private void startPolling() -
stopPolling
private void stopPolling() -
takeSnapshot
- Throws:
IOException
-