Package org.xnio

# Class XnioIoThread

java.lang.Object
java.lang.Thread
org.xnio.XnioIoThread

All Implemented Interfaces:
  `Runnable`, `Executor`, `XnioExecutor`, `XnioIoFactory`

public abstract class XnioIoThread extends Thread implements XnioExecutor, XnioIoFactory
An XNIO thread.

Author:
  David M. Lloyd

## Nested Class Summary

## Nested classes/interfaces inherited from class java.lang.Thread

`Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler`

## Nested classes/interfaces inherited from interface org.xnio.XnioExecutor

`XnioExecutor.Key`

## Field Summary

### Fields inherited from class java.lang.Thread

`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`XnioIoThread(XnioWorker worker, int number)`
Construct a new instance.
`protected`
`XnioIoThread(XnioWorker worker, int number, String name)`
Construct a new instance.
`protected`
`XnioIoThread(XnioWorker worker, int number, ThreadGroup group, String name)`
Construct a new instance.
`protected`
`XnioIoThread(XnioWorker worker, int number, ThreadGroup group, String name, long stackSize)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`protected IoFuture<MessageConnection>`
`acceptLocalMessageConnection(LocalSocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Implementation helper method to accept a local (UNIX domain) datagram connection.
`protected IoFuture<StreamConnection>`
`acceptLocalStreamConnection(LocalSocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Implementation helper method to accept a local (UNIX domain) stream connection.
`IoFuture<MessageConnection>`
`acceptMessageConnection(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Accept a message connection at a destination address.
`IoFuture<StreamConnection>`
`acceptStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Accept a stream connection at a destination address.
`protected IoFuture<StreamConnection>`
`acceptTcpStreamConnection(InetSocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Implementation helper method to accept a TCP connection.
`ChannelPipe<StreamChannel,StreamChannel>`
`createFullDuplexPipe()`
Create a two-way stream pipe.
`ChannelPipe<StreamConnection,StreamConnection>`
`createFullDuplexPipeConnection()`
Create a two-way stream pipe.
`ChannelPipe<StreamConnection,StreamConnection>`
`createFullDuplexPipeConnection(XnioIoFactory peer)`
Create a two-way stream pipe.
`ChannelPipe<StreamSourceChannel,StreamSinkChannel>`
`createHalfDuplexPipe()`
Create a one-way stream pipe.
`ChannelPipe<StreamSourceChannel,StreamSinkChannel>`
`createHalfDuplexPipe(XnioIoFactory peer)`
Create a one-way stream pipe.
`static XnioIoThread`
`currentThread()`
Get the current XNIO thread.
`int`
`getNumber()`
Get the number of this thread.
`XnioWorker`
`getWorker()`
Get the XNIO worker associated with this thread.
`protected IoFuture<MessageConnection>`
`openLocalMessageConnection(LocalSocketAddress bindAddress, LocalSocketAddress destinationAddress, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap)`
Implementation helper method to connect to a local (UNIX domain) server.
`protected IoFuture<StreamConnection>`
`openLocalStreamConnection(LocalSocketAddress bindAddress, LocalSocketAddress destinationAddress, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Implementation helper method to connect to a local (UNIX domain) server.
`IoFuture<MessageConnection>`
`openMessageConnection(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap)`
Connect to a remote message server.
`IoFuture<StreamConnection>`
`openStreamConnection(SocketAddress bindAddress, SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Connect to a remote stream server.
`IoFuture<StreamConnection>`
`openStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Connect to a remote stream server.
`IoFuture<StreamConnection>`
`openStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, OptionMap optionMap)`
Connect to a remote stream server.
`protected IoFuture<StreamConnection>`
`openTcpStreamConnection(InetSocketAddress bindAddress, InetSocketAddress destinationAddress, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)`
Implementation helper method to connect to a TCP server.
`static XnioIoThread`
`requireCurrentThread()`
Get the current XNIO thread.

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

`activeCount, checkAccess, clone, countStackFrames, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield`

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

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

### Methods inherited from interface org.xnio.XnioExecutor

`execute, executeAfter, executeAtInterval`

## Constructor Details

### XnioIoThread

protected XnioIoThread(XnioWorker worker, int number)
Construct a new instance.

Parameters:
  `worker` - the XNIO worker to associate with
  `number` - the thread number

### XnioIoThread

protected XnioIoThread(XnioWorker worker, int number, String name)
Construct a new instance.

Parameters:
  `worker` - the XNIO worker to associate with
  `number` - the thread number
  `name` - the thread name

### XnioIoThread

protected XnioIoThread(XnioWorker worker, int number, ThreadGroup group, String name)
Construct a new instance.

Parameters:
  `worker` - the XNIO worker to associate with
  `number` - the thread number
  `group` - the thread group
  `name` - the thread name

### XnioIoThread

protected XnioIoThread(XnioWorker worker, int number, ThreadGroup group, String name, long stackSize)
Construct a new instance.

Parameters:
  `worker` - the XNIO worker to associate with
  `number` - the thread number
  `group` - the thread group
  `name` - the thread name
  `stackSize` - the thread stack size

## Method Details

### currentThread

public static XnioIoThread currentThread()
Get the current XNIO thread. If the current thread is not an XNIO thread, `null` is returned.

Returns:
  the current XNIO thread

### requireCurrentThread

public static XnioIoThread requireCurrentThread() throws IllegalStateException
Get the current XNIO thread. If the current thread is not an XNIO thread, an `IllegalStateException` is thrown.

Returns:
  the current XNIO thread
Throws:
  `IllegalStateException` - if the current thread is not an XNIO thread

### getNumber

public int getNumber()
Get the number of this thread. In each XNIO worker, every IO thread is given a unique, sequential number.

Returns:
  the number of this thread

### getWorker

public XnioWorker getWorker()
Get the XNIO worker associated with this thread.

Returns:
  the XNIO worker

### acceptStreamConnection

public IoFuture<StreamConnection> acceptStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Accept a stream connection at a destination address. If a wildcard address is specified, then a destination address is chosen in a manner specific to the OS and/or channel type.

Specified by:
  `acceptStreamConnection` in interface `XnioIoFactory`
Parameters:
  `destination` - the destination (bind) address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the acceptor is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future connection

### acceptLocalStreamConnection

protected IoFuture<StreamConnection> acceptLocalStreamConnection(LocalSocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Implementation helper method to accept a local (UNIX domain) stream connection.

Parameters:
  `destination` - the destination (bind) address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the acceptor is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future connection

### acceptTcpStreamConnection

protected IoFuture<StreamConnection> acceptTcpStreamConnection(InetSocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Implementation helper method to accept a TCP connection.

Parameters:
  `destination` - the destination (bind) address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the acceptor is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future connection

### openMessageConnection

public IoFuture<MessageConnection> openMessageConnection(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Connect to a remote message server. The protocol family is determined by the type of the socket address given. If an open listener is used, the channel should not be accessed via the returned `IoFuture`, and vice-versa.

Specified by:
  `openMessageConnection` in interface `XnioIoFactory`
Parameters:
  `destination` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### acceptMessageConnection

public IoFuture<MessageConnection> acceptMessageConnection(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Accept a message connection at a destination address. If a wildcard address is specified, then a destination address is chosen in a manner specific to the OS and/or channel type. If an open listener is used, the channel should not be accessed via the returned `IoFuture`, and vice-versa.

Specified by:
  `acceptMessageConnection` in interface `XnioIoFactory`
Parameters:
  `destination` - the destination (bind) address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the acceptor is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future connection

### acceptLocalMessageConnection

protected IoFuture<MessageConnection> acceptLocalMessageConnection(LocalSocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Implementation helper method to accept a local (UNIX domain) datagram connection.

Parameters:
  `destination` - the destination (bind) address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the acceptor is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future connection

### openStreamConnection

public IoFuture<StreamConnection> openStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Connect to a remote stream server. The protocol family is determined by the type of the socket address given. If an open listener is used, the channel should not be accessed via the returned `IoFuture`, and vice-versa.

Specified by:
  `openStreamConnection` in interface `XnioIoFactory`
Parameters:
  `destination` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### openStreamConnection

public IoFuture<StreamConnection> openStreamConnection(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Connect to a remote stream server. The protocol family is determined by the type of the socket address given. If an open listener is used, the channel should not be accessed via the returned `IoFuture`, and vice-versa.

Specified by:
  `openStreamConnection` in interface `XnioIoFactory`
Parameters:
  `destination` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the channel is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### openStreamConnection

public IoFuture<StreamConnection> openStreamConnection(SocketAddress bindAddress, SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Description copied from interface: `XnioIoFactory`
Connect to a remote stream server. The protocol family is determined by the type of the socket addresses given (which must match). If an open listener is used, the channel should not be accessed via the returned `IoFuture`, and vice-versa.

Specified by:
  `openStreamConnection` in interface `XnioIoFactory`
Parameters:
  `bindAddress` - the local address to bind to
  `destination` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the channel is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### openTcpStreamConnection

protected IoFuture<StreamConnection> openTcpStreamConnection(InetSocketAddress bindAddress, InetSocketAddress destinationAddress, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Implementation helper method to connect to a TCP server.

Parameters:
  `bindAddress` - the bind address
  `destinationAddress` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the channel is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### openLocalStreamConnection

protected IoFuture<StreamConnection> openLocalStreamConnection(LocalSocketAddress bindAddress, LocalSocketAddress destinationAddress, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Implementation helper method to connect to a local (UNIX domain) server.

Parameters:
  `bindAddress` - the bind address
  `destinationAddress` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `bindListener` - the listener which will be notified when the channel is bound, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### openLocalMessageConnection

protected IoFuture<MessageConnection> openLocalMessageConnection(LocalSocketAddress bindAddress, LocalSocketAddress destinationAddress, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap)
Implementation helper method to connect to a local (UNIX domain) server.

Parameters:
  `bindAddress` - the bind address
  `destinationAddress` - the destination address
  `openListener` - the listener which will be notified when the channel is open, or `null` for none
  `optionMap` - the option map
Returns:
  the future result of this operation

### createFullDuplexPipe

public ChannelPipe<StreamChannel,StreamChannel> createFullDuplexPipe() throws IOException
Description copied from interface: `XnioIoFactory`
Create a two-way stream pipe.

Specified by:
  `createFullDuplexPipe` in interface `XnioIoFactory`
Returns:
  the created pipe
Throws:
  `IOException` - if the pipe could not be created

### createFullDuplexPipeConnection

public ChannelPipe<StreamConnection,StreamConnection> createFullDuplexPipeConnection() throws IOException
Description copied from interface: `XnioIoFactory`
Create a two-way stream pipe.

Specified by:
  `createFullDuplexPipeConnection` in interface `XnioIoFactory`
Returns:
  the created pipe
Throws:
  `IOException` - if the pipe could not be created

### createHalfDuplexPipe

public ChannelPipe<StreamSourceChannel,StreamSinkChannel> createHalfDuplexPipe() throws IOException
Description copied from interface: `XnioIoFactory`
Create a one-way stream pipe.

Specified by:
  `createHalfDuplexPipe` in interface `XnioIoFactory`
Returns:
  the created pipe
Throws:
  `IOException` - if the pipe could not be created

### createFullDuplexPipeConnection

public ChannelPipe<StreamConnection,StreamConnection> createFullDuplexPipeConnection(XnioIoFactory peer) throws IOException
Description copied from interface: `XnioIoFactory`
Create a two-way stream pipe. The left side will be associated with this factory, and the right side will be associated with the given peer.

Specified by:
  `createFullDuplexPipeConnection` in interface `XnioIoFactory`
Parameters:
  `peer` - the peer to use for controlling the remote (right) side
Returns:
  the created pipe
Throws:
  `IOException` - if the pipe could not be created

### createHalfDuplexPipe

public ChannelPipe<StreamSourceChannel,StreamSinkChannel> createHalfDuplexPipe(XnioIoFactory peer) throws IOException
Description copied from interface: `XnioIoFactory`
Create a one-way stream pipe. The left (source) side will be associated with this factory, and the right (sink) side will be associated with the given peer.

Specified by:
  `createHalfDuplexPipe` in interface `XnioIoFactory`
Parameters:
  `peer` - the peer to use for the sink (right) side
Returns:
  the created pipe
Throws:
  `IOException` - if the pipe could not be created