IWatchKey Interface
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A token representing the registration of a Watchable watchable
object
with a WatchService
.
[Android.Runtime.Register("java/nio/file/WatchKey", "", "Java.Nio.FileNio.IWatchKeyInvoker", ApiSince=26)]
public interface IWatchKey : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("java/nio/file/WatchKey", "", "Java.Nio.FileNio.IWatchKeyInvoker", ApiSince=26)>]
type IWatchKey = interface
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Attributes
- Implements
Remarks
A token representing the registration of a Watchable watchable
object with a WatchService
.
A watch key is created when a watchable object is registered with a watch service. The key remains #isValid valid
until: <ol> <li> It is cancelled, explicitly, by invoking its #cancel cancel
method, or</li> <li> Cancelled implicitly, because the object is no longer accessible, or </li> <li> By WatchService#close closing
the watch service. </li> </ol>
A watch key has a state. When initially created the key is said to be <em>ready</em>. When an event is detected then the key is <em>signalled</em> and queued so that it can be retrieved by invoking the watch service's WatchService#poll() poll
or WatchService#take() take
methods. Once signalled, a key remains in this state until its #reset reset
method is invoked to return the key to the ready state. Events detected while the key is in the signalled state are queued but do not cause the key to be re-queued for retrieval from the watch service. Events are retrieved by invoking the key's #pollEvents pollEvents
method. This method retrieves and removes all events accumulated for the object. When initially created, a watch key has no pending events. Typically events are retrieved when the key is in the signalled state leading to the following idiom:
for (;;) {
// retrieve key
WatchKey key = watcher.take();
// process events
for (WatchEvent<?> event: key.pollEvents()) {
:
}
// reset the key
boolean valid = key.reset();
if (!valid) {
// object no longer registered
}
}
Watch keys are safe for use by multiple concurrent threads. Where there are several threads retrieving signalled keys from a watch service then care should be taken to ensure that the reset
method is only invoked after the events for the object have been processed. This ensures that one thread is processing the events for an object at any time.
Added in 1.7.
Java documentation for java.nio.file.WatchKey
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Properties
Handle |
Gets the JNI value of the underlying Android object. (Inherited from IJavaObject) |
IsValid | |
JniIdentityHashCode |
Returns the value of |
JniManagedPeerState |
State of the managed peer. (Inherited from IJavaPeerable) |
JniPeerMembers |
Member access and invocation support. (Inherited from IJavaPeerable) |
PeerReference |
Returns a JniObjectReference of the wrapped Java object instance. (Inherited from IJavaPeerable) |
Methods
Cancel() |
Cancels the registration with the watch service. |
Disposed() |
Called when the instance has been disposed. (Inherited from IJavaPeerable) |
DisposeUnlessReferenced() |
If there are no outstanding references to this instance, then
calls |
Finalized() |
Called when the instance has been finalized. (Inherited from IJavaPeerable) |
PollEvents() |
Retrieves and removes all pending events for this watch key, returning
a |
Reset() |
Resets this watch key. |
SetJniIdentityHashCode(Int32) |
Set the value returned by |
SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from IJavaPeerable) |
SetPeerReference(JniObjectReference) |
Set the value returned by |
UnregisterFromRuntime() |
Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations. (Inherited from IJavaPeerable) |
Watchable() |
Returns the object for which this watch key was created. |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |