# AbstractInterruptibleChannel

public abstract class **AbstractInterruptibleChannel** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html) [InterruptibleChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptibleChannel.html)

|---|---|---|
| Known Direct Subclasses [FileChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/FileChannel.html), [SelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html) |---|---| | [FileChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/FileChannel.html) | A channel for reading, writing, mapping, and manipulating a file. | | [SelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SelectableChannel.html) | A channel that can be multiplexed via a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Selector.html`. | |||

|---|---|---|
| Known Indirect Subclasses [AbstractSelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html), [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html), [Pipe.SinkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.SinkChannel.html), [Pipe.SourceChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.SourceChannel.html), [ServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ServerSocketChannel.html), [SocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SocketChannel.html) |---|---| | [AbstractSelectableChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractSelectableChannel.html) | Base implementation class for selectable channels. | | [DatagramChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/DatagramChannel.html) | A selectable channel for datagram-oriented sockets. | | [Pipe.SinkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.SinkChannel.html) | A channel representing the writable end of a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.html`. | | [Pipe.SourceChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.SourceChannel.html) | A channel representing the readable end of a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Pipe.html`. | | [ServerSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ServerSocketChannel.html) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/SocketChannel.html) | A selectable channel for stream-oriented connecting sockets. | |||

Base implementation class for interruptible channels.

This class encapsulates the low-level machinery required to implement
the asynchronous closing and interruption of channels. A concrete channel
class must invoke the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#begin()` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean)` methods
before and after, respectively, invoking an I/O operation that might block
indefinitely. In order to ensure that the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean)` method is always
invoked, these methods should be used within a
try ... finally block:

> ```
>  boolean completed = false;
>  try {
>      begin();
>      completed = ...;    // Perform blocking I/O operation
>      return ...;         // Return result
>  } finally {
>      end(completed);
>  }
> ```

The completed argument to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean)` 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#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
`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean)` method will throw the appropriate exception.

This class performs the synchronization required to implement the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html` specification. Implementations of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#implCloseChannel()` method need not synchronize against
other threads that might be attempting to close the channel.

<br />

### Protected Constructor Summary

|---|---|
|   | [AbstractInterruptibleChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#AbstractInterruptibleChannel())() Initializes a new instance of this class. |

### Public Method Summary

|---|---|
| final void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#close())() Closes this channel. |
| final boolean | [isOpen](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#isOpen())() Tells whether or not this channel is open. |

### Protected Method Summary

|---|---|
| final void | [begin](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#begin())() Marks the beginning of an I/O operation that might block indefinitely. |
| final void | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean))(boolean completed) Marks the end of an I/O operation that might block indefinitely. |
| abstract void | [implCloseChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#implCloseChannel())() Closes this channel. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.nio.channels.Channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#close())() Closes this channel. |
| abstract boolean | [isOpen](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#isOpen())() Tells whether or not this channel is open. |

From interface [java.nio.channels.InterruptibleChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptibleChannel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptibleChannel.html#close())() Closes this channel. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Protected Constructors

#### protected
**AbstractInterruptibleChannel**
()

Initializes a new instance of this class.

## Public Methods

#### public final void
**close**
()

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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#implCloseChannel()` method in order to
complete the close operation.

<br />

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public final boolean
**isOpen**
()

Tells whether or not this channel is open.

##### Returns

- true if, and only if, this channel is open

## Protected Methods

#### protected final void
**begin**
()

Marks the beginning of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#end(boolean)`
method, using a try ... finally block as
shown [above](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel#be), in order to implement asynchronous
closing and interruption for this channel.

<br />

#### protected final void
**end**
(boolean completed)

Marks the end of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#begin()` method, using a try ... finally block
as shown [above](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel#be), in order to implement asynchronous
closing and interruption for this channel.

<br />

##### Parameters

| completed | true if, and only if, the I/O operation completed successfully, that is, had some effect that would be visible to the operation's invoker |
|---|---|

##### Throws

| [AsynchronousCloseException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousCloseException.html) | If the channel was asynchronously closed |
| [ClosedByInterruptException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedByInterruptException.html) | If the thread blocked in the I/O operation was interrupted |
|---|---|

#### protected abstract void
**implCloseChannel**
()

Closes this channel.

This method is invoked by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AbstractInterruptibleChannel.html#close()` method 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.

<br />

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs while closing the channel |
|---|---|