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 ofWatchService
that polls for changes to directories at registered paths.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PollingWatchService.Snapshot
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
Fields Modifier and Type Field Description private FileSystemState
fileSystemState
(package private) long
interval
private PathService
pathService
private java.util.concurrent.ScheduledFuture<?>
pollingFuture
private java.util.concurrent.ScheduledExecutorService
pollingService
private java.lang.Runnable
pollingTask
private java.util.concurrent.ConcurrentMap<AbstractWatchService.Key,PollingWatchService.Snapshot>
snapshots
Map of keys to the most recent directory snapshot for each key.private static 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.(package private) java.util.concurrent.TimeUnit
timeUnit
private FileSystemView
view
-
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 void
cancelled(AbstractWatchService.Key key)
Called when the given key is cancelled.private JimfsPath
checkWatchable(java.nio.file.Watchable watchable)
void
close()
(package private) boolean
isPolling()
private boolean
isSameFileSystem(java.nio.file.Path path)
AbstractWatchService.Key
register(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 void
startPolling()
private void
stopPolling()
private PollingWatchService.Snapshot
takeSnapshot(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: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:
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:AbstractWatchService
Called when the given key is cancelled. Does nothing by default.- Overrides:
cancelled
in classAbstractWatchService
-
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
- Overrides:
close
in classAbstractWatchService
-
startPolling
private void startPolling()
-
stopPolling
private void stopPolling()
-
takeSnapshot
private PollingWatchService.Snapshot takeSnapshot(JimfsPath path) throws java.io.IOException
- Throws:
java.io.IOException
-
-