Package org.xnio
Class XnioIoThread
java.lang.Object
java.lang.Thread
org.xnio.XnioIoThread
- All Implemented Interfaces:
Runnable
,Executor
,XnioExecutor
,XnioIoFactory
An XNIO thread.
- Author:
- David M. Lloyd
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
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
ConstructorsModifierConstructorDescriptionprotected
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 TypeMethodDescriptionprotected 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.acceptMessageConnection
(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) Accept a message connection at a destination address.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.Create a two-way stream pipe.Create a two-way stream pipe.Create a two-way stream pipe.Create a one-way stream pipe.Create a one-way stream pipe.static XnioIoThread
Get the current XNIO thread.int
Get the number of this thread.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.openMessageConnection
(SocketAddress destination, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap) Connect to a remote message server.openStreamConnection
(SocketAddress bindAddress, SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) Connect to a remote stream server.openStreamConnection
(SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) Connect to a remote stream server.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
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, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, 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
Construct a new instance.- Parameters:
worker
- the XNIO worker to associate withnumber
- the thread number
-
XnioIoThread
Construct a new instance.- Parameters:
worker
- the XNIO worker to associate withnumber
- the thread numbername
- the thread name
-
XnioIoThread
Construct a new instance.- Parameters:
worker
- the XNIO worker to associate withnumber
- the thread numbergroup
- the thread groupname
- 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 withnumber
- the thread numbergroup
- the thread groupname
- the thread namestackSize
- the thread stack size
-
-
Method Details
-
currentThread
Get the current XNIO thread. If the current thread is not an XNIO thread,null
is returned.- Returns:
- the current XNIO thread
-
requireCurrentThread
Get the current XNIO thread. If the current thread is not an XNIO thread, anIllegalStateException
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
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 interfaceXnioIoFactory
- Parameters:
destination
- the destination (bind) addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the acceptor is bound, ornull
for noneoptionMap
- 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) addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the acceptor is bound, ornull
for noneoptionMap
- 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) addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the acceptor is bound, ornull
for noneoptionMap
- 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 returnedIoFuture
, and vice-versa.- Specified by:
openMessageConnection
in interfaceXnioIoFactory
- Parameters:
destination
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for noneoptionMap
- 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 returnedIoFuture
, and vice-versa.- Specified by:
acceptMessageConnection
in interfaceXnioIoFactory
- Parameters:
destination
- the destination (bind) addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the acceptor is bound, ornull
for noneoptionMap
- 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) addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the acceptor is bound, ornull
for noneoptionMap
- 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 returnedIoFuture
, and vice-versa.- Specified by:
openStreamConnection
in interfaceXnioIoFactory
- Parameters:
destination
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for noneoptionMap
- 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 returnedIoFuture
, and vice-versa.- Specified by:
openStreamConnection
in interfaceXnioIoFactory
- Parameters:
destination
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the channel is bound, ornull
for noneoptionMap
- 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 returnedIoFuture
, and vice-versa.- Specified by:
openStreamConnection
in interfaceXnioIoFactory
- Parameters:
bindAddress
- the local address to bind todestination
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the channel is bound, ornull
for noneoptionMap
- 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 addressdestinationAddress
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the channel is bound, ornull
for noneoptionMap
- 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 addressdestinationAddress
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for nonebindListener
- the listener which will be notified when the channel is bound, ornull
for noneoptionMap
- 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 addressdestinationAddress
- the destination addressopenListener
- the listener which will be notified when the channel is open, ornull
for noneoptionMap
- the option map- Returns:
- the future result of this operation
-
createFullDuplexPipe
Description copied from interface:XnioIoFactory
Create a two-way stream pipe.- Specified by:
createFullDuplexPipe
in interfaceXnioIoFactory
- Returns:
- the created pipe
- Throws:
IOException
- if the pipe could not be created
-
createFullDuplexPipeConnection
public ChannelPipe<StreamConnection,StreamConnection> createFullDuplexPipeConnection() throws IOExceptionDescription copied from interface:XnioIoFactory
Create a two-way stream pipe.- Specified by:
createFullDuplexPipeConnection
in interfaceXnioIoFactory
- Returns:
- the created pipe
- Throws:
IOException
- if the pipe could not be created
-
createHalfDuplexPipe
Description copied from interface:XnioIoFactory
Create a one-way stream pipe.- Specified by:
createHalfDuplexPipe
in interfaceXnioIoFactory
- 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 interfaceXnioIoFactory
- 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 interfaceXnioIoFactory
- Parameters:
peer
- the peer to use for the sink (right) side- Returns:
- the created pipe
- Throws:
IOException
- if the pipe could not be created
-