Package com.google.common.jimfs
Class AbstractWatchService
- java.lang.Object
-
- com.google.common.jimfs.AbstractWatchService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.file.WatchService
- Direct Known Subclasses:
PollingWatchService
abstract class AbstractWatchService extends java.lang.Object implements java.nio.file.WatchService
Abstract implementation ofWatchService
. Provides the means for registering and managing keys but does not handle actually watching. Subclasses should implement the means of watching watchables, posting events to registered keys and queueing keys with the service by signalling them.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AbstractWatchService.Event<T>
A basic implementation ofWatchEvent
.(package private) static class
AbstractWatchService.Key
Implementation ofWatchKey
for anAbstractWatchService
.
-
Constructor Summary
Constructors Constructor Description AbstractWatchService()
-
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 @Nullable java.nio.file.WatchKey
check(@Nullable java.nio.file.WatchKey key)
Returns the given key, throwing an exception if it's the poison.protected void
checkOpen()
Checks that the watch service is open, throwingClosedWatchServiceException
if not.void
close()
(package private) void
enqueue(AbstractWatchService.Key key)
Enqueues the given key if the watch service is open; does nothing otherwise.boolean
isOpen()
Returns whether or not this watch service is open.@Nullable java.nio.file.WatchKey
poll()
@Nullable java.nio.file.WatchKey
poll(long timeout, java.util.concurrent.TimeUnit unit)
(package private) com.google.common.collect.ImmutableList<java.nio.file.WatchKey>
queuedKeys()
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.java.nio.file.WatchKey
take()
-
-
-
Method Detail
-
register
public AbstractWatchService.Key register(java.nio.file.Watchable watchable, java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> eventTypes) 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
-
isOpen
public boolean isOpen()
Returns whether or not this watch service is open.
-
enqueue
final void enqueue(AbstractWatchService.Key key)
Enqueues the given key if the watch service is open; does nothing otherwise.
-
cancelled
public void cancelled(AbstractWatchService.Key key)
Called when the given key is cancelled. Does nothing by default.
-
queuedKeys
com.google.common.collect.ImmutableList<java.nio.file.WatchKey> queuedKeys()
-
poll
public @Nullable java.nio.file.WatchKey poll()
- Specified by:
poll
in interfacejava.nio.file.WatchService
-
poll
public @Nullable 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
-
check
private @Nullable java.nio.file.WatchKey check(@Nullable java.nio.file.WatchKey key)
Returns the given key, throwing an exception if it's the poison.
-
checkOpen
protected final void checkOpen()
Checks that the watch service is open, throwingClosedWatchServiceException
if not.
-
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
-
-