IAsynchronousChannel 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 channel that supports asynchronous I/O operations.
[Android.Runtime.Register("java/nio/channels/AsynchronousChannel", "", "Java.Nio.Channels.IAsynchronousChannelInvoker", ApiSince=26)]
public interface IAsynchronousChannel : IDisposable, Java.Interop.IJavaPeerable, Java.Nio.Channels.IChannel
[<Android.Runtime.Register("java/nio/channels/AsynchronousChannel", "", "Java.Nio.Channels.IAsynchronousChannelInvoker", ApiSince=26)>]
type IAsynchronousChannel = interface
interface IChannel
interface ICloseable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Derived
- Attributes
- Implements
Remarks
A channel that supports asynchronous I/O operations. Asynchronous I/O operations will usually take one of two forms:
<ol> <li>
{@link Future}<V> <em>operation</em>(<em>...</em>)
</li> <li>
void <em>operation</em>(<em>...</em> A attachment, {@link
CompletionHandler}<V,? super A> handler)
</li> </ol>
where operation is the name of the I/O operation (read or write for example), V is the result type of the I/O operation, and A is the type of an object attached to the I/O operation to provide context when consuming the result. The attachment is important for cases where a <em>state-less</em> CompletionHandler
is used to consume the result of many I/O operations.
In the first form, the methods defined by the Future Future
interface may be used to check if the operation has completed, wait for its completion, and to retrieve the result. In the second form, a CompletionHandler
is invoked to consume the result of the I/O operation when it completes or fails.
A channel that implements this interface is <em>asynchronously closeable</em>: If an I/O operation is outstanding on the channel and the channel's #close close
method is invoked, then the I/O operation fails with the exception AsynchronousCloseException
.
Asynchronous channels are safe for use by multiple concurrent threads. Some channel implementations may support concurrent reading and writing, but may not allow more than one read and one write operation to be outstanding at any given time.
<h2>Cancellation</h2>
The Future
interface defines the Future#cancel cancel
method to cancel execution. This causes all threads waiting on the result of the I/O operation to throw java.util.concurrent.CancellationException
. Whether the underlying I/O operation can be cancelled is highly implementation specific and therefore not specified. Where cancellation leaves the channel, or the entity to which it is connected, in an inconsistent state, then the channel is put into an implementation specific <em>error state</em> that prevents further attempts to initiate I/O operations that are similar to the operation that was cancelled. For example, if a read operation is cancelled but the implementation cannot guarantee that bytes have not been read from the channel then it puts the channel into an error state; further attempts to initiate a read
operation cause an unspecified runtime exception to be thrown. Similarly, if a write operation is cancelled but the implementation cannot guarantee that bytes have not been written to the channel then subsequent attempts to initiate a write
will fail with an unspecified runtime exception.
Where the Future#cancel cancel
method is invoked with the mayInterruptIfRunning
parameter set to true
then the I/O operation may be interrupted by closing the channel. In that case all threads waiting on the result of the I/O operation throw CancellationException
and any other I/O operations outstanding on the channel complete with the exception AsynchronousCloseException
.
Where the cancel
method is invoked to cancel read or write operations then it is recommended that all buffers used in the I/O operations be discarded or care taken to ensure that the buffers are not accessed while the channel remains open.
Added in 1.7.
Java documentation for java.nio.channels.AsynchronousChannel
.
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) |
IsOpen |
Returns true if this channel is open. (Inherited from IChannel) |
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
Close() |
Closes this channel. |
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) |
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) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |