AbstractInterruptibleChannel (Java Platform SE 6)
boolean completed = false;
try {
begin();
completed = ...; // Perform blocking I/O operation
return ...; // Return result
} finally {
end(completed);
}
The completed argument to the end method tells
whether or not the I/O operation actually completed, that is, whether it had
any effect that would be visible to the invoker. In the case of an
operation that reads bytes, for example, this argument should be
true if, and only if, some bytes were actually transferred into the
invoker's target buffer.
A concrete channel class must also implement the implCloseChannel method in such a way that if it is
invoked while another thread is blocked in a native I/O operation upon the
channel then that operation will immediately return, either by throwing an
exception or by returning normally. If a thread is interrupted or the
channel upon which it is blocked is asynchronously closed then the channel's
end method will throw the appropriate exception.
This class performs the synchronization required to implement the Channel specification. Implementations of the implCloseChannel method need not synchronize against
other threads that might be attempting to close the channel.
- Since:
- 1.4
| Constructor Summary | |
|---|---|
protected |
AbstractInterruptibleChannel()
Initializes a new instance of this class. |
| Method Summary | |
|---|---|
protected void |
begin()
Marks the beginning of an I/O operation that might block indefinitely. |
void |
close()
Closes this channel. |
protected void |
end(boolean completed)
Marks the end of an I/O operation that might block indefinitely. |
protected abstract void |
implCloseChannel()
Closes this channel. |
boolean |
isOpen()
Tells whether or not this channel is open. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
AbstractInterruptibleChannel
protected AbstractInterruptibleChannel()
- Initializes a new instance of this class.
| Method Detail |
|---|
close
public final void close()
throws IOException
- Closes this channel.
If the channel has already been closed then this method returns immediately. Otherwise it marks the channel as closed and then invokes the
implCloseChannelmethod in order to complete the close operation. - Throws:
IOException- If an I/O error occurs
implCloseChannel
protected abstract void implCloseChannel()
throws IOException
- Closes this channel.
This method is invoked by the
closemethod in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once.An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon this channel to return immediately, either by throwing an exception or by returning normally.
- Throws:
IOException- If an I/O error occurs while closing the channel
isOpen
public final boolean isOpen()
- Description copied from interface:
Channel - Tells whether or not this channel is open.