|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface AsynchronousChannel
A channel that supports asynchronous I/O operations. Asynchronous I/O operations will usually take one of two forms:
Future
<V> operation(...)
Future<V> operation(... A attachment, CompletionHandler
<V,? super A> handler)
CompletionHandler
is used to consume the result
of many I/O operations.
In the first form, the methods defined by the 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, fails, or is cancelled.
A channel that implements this interface is asynchronously
closeable: If an I/O operation is outstanding on the channel and the
channel's 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.
The Future
interface defines the cancel
method to cancel execution of a task.
Where the cancel
method is invoked with the mayInterruptIfRunning
parameter set to true
then the I/O operation
may be interrupted by closing the channel. This will cause any other I/O
operations outstanding on the channel to complete with the exception AsynchronousCloseException
.
If a CompletionHandler
is specified when initiating an I/O
operation, and the cancel
method is invoked to cancel the I/O
operation before it completes, then the CompletionHandler
's cancelled
method is invoked.
If an implementation of this interface supports a means to cancel I/O
operations, and where cancellation may leave the channel, or the entity to
which it is connected, in an inconsistent state, then the channel is put into
an implementation specific error state that prevents further
attempts to initiate I/O operations on the channel. 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 error state
state; further attempts to initiate a read
operation causes an
unspecified runtime exception to be thrown.
Where the cancel
method is invoked to cancel read or write
operations then it 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.
Method Summary | |
---|---|
void |
close()
Closes this channel. |
Methods inherited from interface java.nio.channels.Channel |
---|
isOpen |
Method Detail |
---|
void close() throws java.io.IOException
Any outstanding asynchronous operations upon this channel will
complete with the exception AsynchronousCloseException
. After a
channel is closed then further attempts to initiate asynchronous I/O
operations complete immediately with cause ClosedChannelException
.
This method otherwise behaves exactly as specified by the Channel
interface.
close
in interface java.nio.channels.Channel
close
in interface java.io.Closeable
java.io.IOException
- If an I/O error occurs
|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2010 Sun Microsystems, Inc. All rights reserved. Use is subject to the terms of the GNU General Public License.