Package org.xnio

# Class Connection

java.lang.Object
org.xnio.Connection

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `Channel`, `InterruptibleChannel`, `BoundChannel`, `CloseableChannel`, `Configurable`, `ConnectedChannel`

Direct Known Subclasses:
  `MessageConnection`, `StreamConnection`

public abstract class Connection extends Object implements CloseableChannel, ConnectedChannel
The base for all connections.

Author:
  David M. Lloyd

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final XnioIoThread`
`thread`

### Fields inherited from interface org.xnio.channels.Configurable

`EMPTY`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Connection(XnioIoThread thread)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`final void`
`close()`
Close this channel.
`protected void`
`closeAction()`
The close action to perform on this connection.
`XnioIoThread`
`getIoThread()`
Get the I/O thread associated with this channel.
`final <A extends SocketAddress>
A`
`getLocalAddress(Class<A> type)`
Get the local address of a given type, or `null` if the address is not of that type.
`<T> T`
`getOption(Option<T> option)`
Get the value of a channel option.
`final <A extends SocketAddress>
A`
`getPeerAddress(Class<A> type)`
Get the peer address of a given type, or `null` if the address is not of that type.
`final XnioWorker`
`getWorker()`
Get the worker for this channel.
`boolean`
`isOpen()`
`boolean`
`isReadShutdown()`
Determine whether reads have been shut down on this connection.
`boolean`
`isWriteShutdown()`
Determine whether writes have been shut down on this connection.
`protected abstract void`
`notifyReadClosed()`
Indicate to conduit handlers that reads have been closed.
`protected abstract void`
`notifyWriteClosed()`
Indicate to conduit handlers that writes have been closed.
`protected boolean`
`readClosed()`
Indicate that reads have been closed on this connection.
`<T> T`
`setOption(Option<T> option, T value)`
Set an option for this channel.
`boolean`
`supportsOption(Option<?> option)`
Determine whether an option is supported on this channel.
`protected boolean`
`writeClosed()`
Indicate that writes have been closed on this connection.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.xnio.channels.BoundChannel

`getLocalAddress`

### Methods inherited from interface org.xnio.channels.ConnectedChannel

`getCloseSetter, getPeerAddress`

## Field Details

### thread

protected final XnioIoThread thread

## Constructor Details

### Connection

protected Connection(XnioIoThread thread)
Construct a new instance.

Parameters:
  `thread` - the I/O thread of this connection

## Method Details

### getPeerAddress

public final <A extends SocketAddress> A getPeerAddress(Class<A> type)
Description copied from interface: `ConnectedChannel`
Get the peer address of a given type, or `null` if the address is not of that type.

Specified by:
  `getPeerAddress` in interface `ConnectedChannel`
Parameters:
  `type` - the address type class
Returns:
  the peer address, or `null` if unknown

### getLocalAddress

public final <A extends SocketAddress> A getLocalAddress(Class<A> type)
Description copied from interface: `BoundChannel`
Get the local address of a given type, or `null` if the address is not of that type.

Specified by:
  `getLocalAddress` in interface `BoundChannel`
Type Parameters:
  `A` - the address type
Parameters:
  `type` - the address type class
Returns:
  the local address, or `null` if unknown

### getWorker

public final XnioWorker getWorker()
Description copied from interface: `CloseableChannel`
Get the worker for this channel.

Specified by:
  `getWorker` in interface `CloseableChannel`
Returns:
  the worker

### getIoThread

public XnioIoThread getIoThread()
Description copied from interface: `CloseableChannel`
Get the I/O thread associated with this channel.

Specified by:
  `getIoThread` in interface `CloseableChannel`
Returns:
  the I/O thread associated with this channel

### readClosed

protected boolean readClosed()
Indicate that reads have been closed on this connection.

Returns:
  `true` if read closure was successfully indicated; `false` if this method has already been called

### writeClosed

protected boolean writeClosed()
Indicate that writes have been closed on this connection.

Returns:
  `true` if write closure was successfully indicated; `false` if this method has already been called

### close

public final void close() throws IOException
Description copied from interface: `CloseableChannel`
Close this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableChannel`
Specified by:
  `close` in interface `InterruptibleChannel`
Throws:
  `IOException` - if the close failed

### isReadShutdown

public boolean isReadShutdown()
Determine whether reads have been shut down on this connection.

Returns:
  `true` if reads were shut down

### isWriteShutdown

public boolean isWriteShutdown()
Determine whether writes have been shut down on this connection.

Returns:
  `true` if writes were shut down

### isOpen

public boolean isOpen()

Specified by:
  `isOpen` in interface `Channel`

### notifyWriteClosed

protected abstract void notifyWriteClosed()
Indicate to conduit handlers that writes have been closed.

### notifyReadClosed

protected abstract void notifyReadClosed()
Indicate to conduit handlers that reads have been closed.

### closeAction

protected void closeAction() throws IOException
The close action to perform on this connection.

Throws:
  `IOException` - if close fails

### supportsOption

public boolean supportsOption(Option<?> option)
Description copied from interface: `Configurable`
Determine whether an option is supported on this channel.

Specified by:
  `supportsOption` in interface `Configurable`
Parameters:
  `option` - the option
Returns:
  `true` if it is supported

### getOption

public <T> T getOption(Option<T> option) throws IOException
Description copied from interface: `Configurable`
Get the value of a channel option.

Specified by:
  `getOption` in interface `Configurable`
Type Parameters:
  `T` - the type of the option value
Parameters:
  `option` - the option to get
Returns:
  the value of the option, or `null` if it is not set
Throws:
  `IOException` - if an I/O error occurred when reading the option

### setOption

public <T> T setOption(Option<T> option, T value) throws IllegalArgumentException, IOException
Description copied from interface: `Configurable`
Set an option for this channel. Unsupported options are ignored.

Specified by:
  `setOption` in interface `Configurable`
Type Parameters:
  `T` - the type of the option value
Parameters:
  `option` - the option to set
  `value` - the value of the option to set
Returns:
  the previous option value, if any
Throws:
  `IllegalArgumentException` - if the value is not acceptable for this option
  `IOException` - if an I/O error occurred when modifying the option