Udostępnij za pośrednictwem


IWatchKey Interface

Definition

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&lt;?&gt; 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 java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
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 Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
PollEvents()

Retrieves and removes all pending events for this watch key, returning a List of the events that were retrieved.

Reset()

Resets this watch key.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
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)

Applies to