Methods Summary |
---|
protected final void | begin()Indicates the beginning of a code section that includes an I/O operation
that is potentially blocking. After this operation, the application
should invoke the corresponding {@code end(boolean)} method.
// FIXME: be accommodate before VM actually provides
// setInterruptAction method
if (setInterruptAction != null) {
try {
setInterruptAction.invoke(Thread.currentThread(),
new Object[] { new Runnable() {
public void run() {
try {
interrupted = true;
AbstractInterruptibleChannel.this.close();
} catch (IOException e) {
// ignore
}
}
} });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
public final void | close()Closes an open channel. If the channel is already closed then this method
has no effect, otherwise it closes the receiver via the
{@code implCloseChannel} method.
If an attempt is made to perform an operation on a closed channel then a
{@link java.nio.channels.ClosedChannelException} is thrown.
If multiple threads attempt to simultaneously close a channel, then only
one thread will run the closure code and the others will be blocked until
the first one completes.
if (!closed) {
synchronized (this) {
if (!closed) {
closed = true;
implCloseChannel();
}
}
}
|
protected final void | end(boolean success)Indicates the end of a code section that has been started with
{@code begin()} and that includes a potentially blocking I/O operation.
// FIXME: be accommodate before VM actually provides
// setInterruptAction method
if (setInterruptAction != null) {
try {
setInterruptAction.invoke(Thread.currentThread(),
new Object[] { null });
} catch (Exception e) {
throw new RuntimeException(e);
}
if (interrupted) {
interrupted = false;
throw new ClosedByInterruptException();
}
}
if (!success && closed) {
throw new AsynchronousCloseException();
}
|
protected abstract void | implCloseChannel()Implements the channel closing behavior.
Closes the channel with a guarantee that the channel is not currently
closed through another invocation of {@code close()} and that the method
is thread-safe.
Any outstanding threads blocked on I/O operations on this channel must be
released with either a normal return code, or by throwing an
{@code AsynchronousCloseException}.
|
public final synchronized boolean | isOpen()Indicates whether this channel is open.
return !closed;
|