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 classA basic implementation ofWatchEvent.(package private) static final classImplementation ofWatchKeyfor anAbstractWatchService. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final WatchKeyprivate final BlockingQueue<WatchKey> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when the given key is cancelled.private @Nullable WatchKeyReturns the given key, throwing an exception if it's the poison.protected final voidChecks that the watch service is open, throwingClosedWatchServiceExceptionif not.voidclose()(package private) final voidEnqueues the given key if the watch service is open; does nothing otherwise.booleanisOpen()Returns whether or not this watch service is open.@Nullable WatchKeypoll()@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:
pollin interfaceWatchService
-
poll
- Specified by:
pollin interfaceWatchService- Throws:
InterruptedException
-
take
- Specified by:
takein interfaceWatchService- Throws:
InterruptedException
-
check
-
checkOpen
protected final void checkOpen()Checks that the watch service is open, throwingClosedWatchServiceExceptionif not. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceWatchService
-