- java.lang.Object
-
- java.lang.Thread
-
- org.xnio.XnioIoThread
-
- All Implemented Interfaces:
java.lang.Runnable
,java.util.concurrent.Executor
,XnioExecutor
,XnioIoFactory
public abstract class XnioIoThread extends java.lang.Thread implements XnioExecutor, XnioIoFactory
An XNIO thread.- Author:
- David M. Lloyd
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
-
Nested classes/interfaces inherited from interface org.xnio.XnioExecutor
XnioExecutor.Key
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
XnioIoThread(XnioWorker worker, int number)
Construct a new instance.protected
XnioIoThread(XnioWorker worker, int number, java.lang.String name)
Construct a new instance.protected
XnioIoThread(XnioWorker worker, int number, java.lang.ThreadGroup group, java.lang.String name)
Construct a new instance.protected
XnioIoThread(XnioWorker worker, int number, java.lang.ThreadGroup group, java.lang.String name, long stackSize)
Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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(java.net.SocketAddress destination, ChannelListener<? super MessageConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Accept a message connection at a destination address.IoFuture<StreamConnection>
acceptStreamConnection(java.net.SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Accept a stream connection at a destination address.protected IoFuture<StreamConnection>
acceptTcpStreamConnection(java.net.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(java.net.SocketAddress destination, ChannelListener<? super MessageConnection> openListener, OptionMap optionMap)
Connect to a remote message server.IoFuture<StreamConnection>
openStreamConnection(java.net.SocketAddress bindAddress, java.net.SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Connect to a remote stream server.IoFuture<StreamConnection>
openStreamConnection(java.net.SocketAddress destination, ChannelListener<? super StreamConnection> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Connect to a remote stream server.IoFuture<StreamConnection>
openStreamConnection(java.net.SocketAddress destination, ChannelListener<? super StreamConnection> openListener, OptionMap optionMap)
Connect to a remote stream server.protected IoFuture<StreamConnection>
openTcpStreamConnection(java.net.InetSocketAddress bindAddress, java.net.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, 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 Detail
-
XnioIoThread
protected XnioIoThread(XnioWorker worker, int number)
Construct a new instance.- Parameters:
worker
- the XNIO worker to associate withnumber
- the thread number
-
XnioIoThread
protected XnioIoThread(XnioWorker worker, int number, java.lang.String name)
Construct a new instance.- Parameters:
worker
- the XNIO worker to associate withnumber
- the thread numbername
- the thread name
-
XnioIoThread
protected XnioIoThread(XnioWorker worker, int number, java.lang.ThreadGroup group, java.lang.String name)
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, java.lang.ThreadGroup group, java.lang.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 Detail
-
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 java.lang.IllegalStateException
Get the current XNIO thread. If the current thread is not an XNIO thread, anIllegalStateException
is thrown.- Returns:
- the current XNIO thread
- Throws:
java.lang.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(java.net.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(java.net.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(java.net.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(java.net.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(java.net.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(java.net.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(java.net.SocketAddress bindAddress, java.net.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(java.net.InetSocketAddress bindAddress, java.net.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
public ChannelPipe<StreamChannel,StreamChannel> createFullDuplexPipe() throws java.io.IOException
Description copied from interface:XnioIoFactory
Create a two-way stream pipe.- Specified by:
createFullDuplexPipe
in interfaceXnioIoFactory
- Returns:
- the created pipe
- Throws:
java.io.IOException
- if the pipe could not be created
-
createFullDuplexPipeConnection
public ChannelPipe<StreamConnection,StreamConnection> createFullDuplexPipeConnection() throws java.io.IOException
Description copied from interface:XnioIoFactory
Create a two-way stream pipe.- Specified by:
createFullDuplexPipeConnection
in interfaceXnioIoFactory
- Returns:
- the created pipe
- Throws:
java.io.IOException
- if the pipe could not be created
-
createHalfDuplexPipe
public ChannelPipe<StreamSourceChannel,StreamSinkChannel> createHalfDuplexPipe() throws java.io.IOException
Description copied from interface:XnioIoFactory
Create a one-way stream pipe.- Specified by:
createHalfDuplexPipe
in interfaceXnioIoFactory
- Returns:
- the created pipe
- Throws:
java.io.IOException
- if the pipe could not be created
-
createFullDuplexPipeConnection
public ChannelPipe<StreamConnection,StreamConnection> createFullDuplexPipeConnection(XnioIoFactory peer) throws java.io.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:
java.io.IOException
- if the pipe could not be created
-
createHalfDuplexPipe
public ChannelPipe<StreamSourceChannel,StreamSinkChannel> createHalfDuplexPipe(XnioIoFactory peer) throws java.io.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:
java.io.IOException
- if the pipe could not be created
-
-