Package com.google.common.jimfs
Class PollingWatchService
- java.lang.Object
-
- com.google.common.jimfs.AbstractWatchService
-
- com.google.common.jimfs.PollingWatchService
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.file.WatchService
final class PollingWatchService extends AbstractWatchService
Implementation ofWatchServicethat polls for changes to directories at registered paths.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPollingWatchService.SnapshotSnapshot 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
Fields Modifier and Type Field Description private FileSystemStatefileSystemState(package private) longintervalprivate PathServicepathServiceprivate java.util.concurrent.ScheduledFuture<?>pollingFutureprivate java.util.concurrent.ScheduledExecutorServicepollingServiceprivate java.lang.RunnablepollingTaskprivate java.util.concurrent.ConcurrentMap<AbstractWatchService.Key,PollingWatchService.Snapshot>snapshotsMap of keys to the most recent directory snapshot for each key.private static java.util.concurrent.ThreadFactoryTHREAD_FACTORYThread 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) java.util.concurrent.TimeUnittimeUnitprivate FileSystemViewview
-
Constructor Summary
Constructors Constructor Description PollingWatchService(FileSystemView view, PathService pathService, FileSystemState fileSystemState, long interval, java.util.concurrent.TimeUnit timeUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelled(AbstractWatchService.Key key)Called when the given key is cancelled.private JimfsPathcheckWatchable(java.nio.file.Watchable watchable)voidclose()(package private) booleanisPolling()private booleanisSameFileSystem(java.nio.file.Path path)AbstractWatchService.Keyregister(java.nio.file.Watchable watchable, java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> eventTypes)Registers the given watchable with this service, returning a new watch key for it.private voidstartPolling()private voidstopPolling()private PollingWatchService.SnapshottakeSnapshot(JimfsPath path)-
Methods inherited from class com.google.common.jimfs.AbstractWatchService
checkOpen, enqueue, isOpen, poll, poll, queuedKeys, take
-
-
-
-
Field Detail
-
THREAD_FACTORY
private static final java.util.concurrent.ThreadFactory 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
private final java.util.concurrent.ScheduledExecutorService pollingService
-
snapshots
private final java.util.concurrent.ConcurrentMap<AbstractWatchService.Key,PollingWatchService.Snapshot> snapshots
Map of keys to the most recent directory snapshot for each key.
-
view
private final FileSystemView view
-
pathService
private final PathService pathService
-
fileSystemState
private final FileSystemState fileSystemState
-
interval
final long interval
-
timeUnit
final java.util.concurrent.TimeUnit timeUnit
-
pollingFuture
private java.util.concurrent.ScheduledFuture<?> pollingFuture
-
pollingTask
private final java.lang.Runnable pollingTask
-
-
Constructor Detail
-
PollingWatchService
PollingWatchService(FileSystemView view, PathService pathService, FileSystemState fileSystemState, long interval, java.util.concurrent.TimeUnit timeUnit)
-
-
Method Detail
-
register
@CanIgnoreReturnValue public AbstractWatchService.Key register(java.nio.file.Watchable watchable, java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> eventTypes) throws java.io.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:
java.io.IOException
-
checkWatchable
private JimfsPath checkWatchable(java.nio.file.Watchable watchable)
-
isSameFileSystem
private boolean isSameFileSystem(java.nio.file.Path path)
-
isPolling
boolean isPolling()
-
cancelled
public void cancelled(AbstractWatchService.Key key)
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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.nio.file.WatchService- Overrides:
closein classAbstractWatchService
-
startPolling
private void startPolling()
-
stopPolling
private void stopPolling()
-
takeSnapshot
private PollingWatchService.Snapshot takeSnapshot(JimfsPath path) throws java.io.IOException
- Throws:
java.io.IOException
-
-