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 classSnapshot of the state of a directory at a particular moment.Nested classes/interfaces inherited from class AbstractWatchService
AbstractWatchService.Event<T>, AbstractWatchService.Key -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileSystemState(package private) final longprivate final PathServiceprivate ScheduledFuture<?> private final ScheduledExecutorServiceprivate final Runnableprivate final ConcurrentMap<AbstractWatchService.Key, PollingWatchService.Snapshot> Map of keys to the most recent directory snapshot for each key.private static final ThreadFactoryThread 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 TimeUnitprivate final FileSystemView -
Constructor Summary
ConstructorsConstructorDescriptionPollingWatchService(FileSystemView view, PathService pathService, FileSystemState fileSystemState, long interval, TimeUnit timeUnit) -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when the given key is cancelled.private JimfsPathcheckWatchable(Watchable watchable) voidclose()(package private) booleanprivate booleanisSameFileSystem(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 voidprivate voidprivate PollingWatchService.SnapshottakeSnapshot(JimfsPath path) Methods inherited from class 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:AbstractWatchServiceRegisters 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:
registerin classAbstractWatchService- Throws:
IOException
-
checkWatchable
-
isSameFileSystem
-
isPolling
boolean isPolling() -
cancelled
Description copied from class:AbstractWatchServiceCalled when the given key is cancelled. Does nothing by default.- Overrides:
cancelledin classAbstractWatchService
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceWatchService- Overrides:
closein classAbstractWatchService
-
startPolling
private void startPolling() -
stopPolling
private void stopPolling() -
takeSnapshot
- Throws:
IOException
-