Package com.google.common.jimfs
Class AbstractWatchService
java.lang.Object
com.google.common.jimfs.AbstractWatchService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,WatchService
- Direct Known Subclasses:
PollingWatchService
Abstract implementation of
WatchService
. 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 ClassesModifier and TypeClassDescription(package private) static final class
A basic implementation ofWatchEvent
.(package private) static final class
Implementation ofWatchKey
for anAbstractWatchService
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBoolean
private final WatchKey
private final BlockingQueue
<WatchKey> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called when the given key is cancelled.private @Nullable WatchKey
Returns the given key, throwing an exception if it's the poison.protected final void
Checks that the watch service is open, throwingClosedWatchServiceException
if not.void
close()
(package private) final void
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 WatchKey
poll()
@Nullable WatchKey
(package private) com.google.common.collect.ImmutableList
<WatchKey> register
(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) Registers the given watchable with this service, returning a new watch key for it.take()
-
Field Details
-
queue
-
poison
-
open
-
-
Constructor Details
-
AbstractWatchService
AbstractWatchService()
-
-
Method Details
-
register
public AbstractWatchService.Key register(Watchable watchable, Iterable<? extends WatchEvent.Kind<?>> eventTypes) throws 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:
IOException
-
isOpen
public boolean isOpen()Returns whether or not this watch service is open. -
enqueue
Enqueues the given key if the watch service is open; does nothing otherwise. -
cancelled
Called when the given key is cancelled. Does nothing by default. -
queuedKeys
com.google.common.collect.ImmutableList<WatchKey> queuedKeys() -
poll
- Specified by:
poll
in interfaceWatchService
-
poll
- Specified by:
poll
in interfaceWatchService
- Throws:
InterruptedException
-
take
- Specified by:
take
in interfaceWatchService
- Throws:
InterruptedException
-
check
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceWatchService
-