- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- org.xnio.XnioWorker
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,org.wildfly.common.context.Contextual<XnioWorker>
,Configurable
,XnioIoFactory
public abstract class XnioWorker extends java.util.concurrent.AbstractExecutorService implements Configurable, java.util.concurrent.ExecutorService, XnioIoFactory, org.wildfly.common.context.Contextual<XnioWorker>
A worker for I/O channel notification.- Since:
- 3.0
- Author:
- David M. Lloyd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XnioWorker.Builder
A builder which allows workers to be programmatically configured.
-
Field Summary
-
Fields inherited from interface org.xnio.channels.Configurable
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
XnioWorker(XnioWorker.Builder builder)
Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description IoFuture<ConnectedMessageChannel>
acceptDatagram(java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.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<ConnectedStreamChannel>
acceptStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.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.abstract void
awaitTermination()
Wait for termination.abstract boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
Wait for termination.protected abstract XnioIoThread
chooseThread()
Choose a thread randomly from this worker.IoFuture<ConnectedMessageChannel>
connectDatagram(java.net.SocketAddress bindAddress, java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.IoFuture<ConnectedMessageChannel>
connectDatagram(java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.IoFuture<ConnectedStreamChannel>
connectStream(java.net.SocketAddress bindAddress, java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.IoFuture<ConnectedStreamChannel>
connectStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.IoFuture<ConnectedStreamChannel>
connectStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, OptionMap optionMap)
Deprecated.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.protected AcceptingChannel<StreamConnection>
createLocalStreamConnectionServer(LocalSocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap)
Implementation helper method to create a UNIX domain stream server.void
createOneWayPipe(ChannelListener<? super StreamSourceChannel> sourceListener, ChannelListener<? super StreamSinkChannel> sinkListener, OptionMap optionMap)
Deprecated.Users should prefer the simplercreateHalfDuplexPipe()
instead.void
createPipe(ChannelListener<? super StreamChannel> leftOpenListener, ChannelListener<? super StreamChannel> rightOpenListener, OptionMap optionMap)
Deprecated.Users should prefer the simplercreateFullDuplexPipe()
instead.AcceptingChannel<StreamConnection>
createStreamConnectionServer(java.net.SocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap)
Create a stream server, for TCP or UNIX domain servers.AcceptingChannel<? extends ConnectedStreamChannel>
createStreamServer(java.net.SocketAddress bindAddress, ChannelListener<? super AcceptingChannel<ConnectedStreamChannel>> acceptListener, OptionMap optionMap)
Deprecated.protected AcceptingChannel<StreamConnection>
createTcpConnectionServer(java.net.InetSocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap)
Implementation helper method to create a TCP stream server.MulticastMessageChannel
createUdpServer(java.net.InetSocketAddress bindAddress, ChannelListener<? super MulticastMessageChannel> bindListener, OptionMap optionMap)
Create a UDP server.MulticastMessageChannel
createUdpServer(java.net.InetSocketAddress bindAddress, OptionMap optionMap)
Create a UDP server.void
execute(java.lang.Runnable command)
Execute a command in the task pool.java.net.InetSocketAddress
getBindAddress(java.net.InetAddress destination)
Get the expected bind address for the given destination, if any.protected org.wildfly.common.net.CidrAddressTable<java.net.InetSocketAddress>
getBindAddressTable()
Get the bind address table.protected int
getBusyWorkerThreadCount()
Get an estimate of the number of busy threads in the worker pool.static org.wildfly.common.context.ContextManager<XnioWorker>
getContextManager()
Get the context manager for XNIO workers.protected int
getCoreWorkerPoolSize()
Get the core worker pool size.protected StreamSinkChannel
getDeflatingChannel(StreamSinkChannel delegate, java.util.zip.Deflater deflater)
Create a stream channel that compresses to the destination according to the configuration in the given inflater.StreamSinkChannel
getDeflatingChannel(StreamSinkChannel delegate, OptionMap options)
Create a stream channel that compresses to the destination according to the configuration in the given option map.protected StreamSourceChannel
getInflatingChannel(StreamSourceChannel delegate, java.util.zip.Inflater inflater)
Create a stream channel that decompresses the source data according to the configuration in the given inflater.StreamSourceChannel
getInflatingChannel(StreamSourceChannel delegate, OptionMap options)
Create a stream channel that decompresses the source data according to the configuration in the given option map.org.wildfly.common.context.ContextManager<XnioWorker>
getInstanceContextManager()
Get the instance context manager for XNIO workers by delegating togetContextManager()
.XnioIoThread
getIoThread()
Get an I/O thread from this worker.abstract XnioIoThread
getIoThread(int hashCode)
Get an I/O thread from this worker.abstract int
getIoThreadCount()
Get the number of I/O threads configured on this worker.protected int
getMaxWorkerPoolSize()
Get the maximum worker pool size.abstract XnioWorkerMXBean
getMXBean()
java.lang.String
getName()
Get the name of this worker.<T> T
getOption(Option<T> option)
Get the value of a channel option.protected java.lang.Runnable
getTerminationTask()
Get the user task to run once termination is complete.protected int
getWorkerPoolSize()
Get an estimate of the number of threads in the worker pool.protected int
getWorkerQueueSize()
Get an estimate of the number of tasks in the worker queue.Xnio
getXnio()
Get the XNIO provider which produced this worker.abstract boolean
isShutdown()
Determine whether the worker has been shut down.protected boolean
isTaskPoolExternal()
Determine whether the worker task pool is managed externally.abstract boolean
isTerminated()
Determine whether the worker has terminated.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 abstract ManagementRegistration
registerServerMXBean(XnioServerMXBean metrics)
<T> T
setOption(Option<T> option, T value)
Set an option for this channel.abstract void
shutdown()
Shut down this worker.abstract java.util.List<java.lang.Runnable>
shutdownNow()
Immediately terminate the worker.protected void
shutDownTaskPool()
Initiate shutdown of the task thread pool.protected java.util.List<java.lang.Runnable>
shutDownTaskPoolNow()
Shut down the task thread pool immediately and return its pending tasks.boolean
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.protected void
taskPoolTerminated()
Callback to indicate that the task thread pool has terminated.-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.common.context.Contextual
run, runAction, runBiConsumer, runBiFunction, runBiPredicate, runCallable, runConsumer, runExBiConsumer, runExBiFunction, runExBiPredicate, runExceptionAction, runExConsumer, runExFunction, runExIntFunction, runExLongFunction, runExPredicate, runFunction, runIntFunction, runLongFunction, runPredicate
-
-
-
-
Constructor Detail
-
XnioWorker
protected XnioWorker(XnioWorker.Builder builder)
Construct a new instance. Intended to be called only from implementations.- Parameters:
builder
- the worker builder
-
-
Method Detail
-
getContextManager
public static org.wildfly.common.context.ContextManager<XnioWorker> getContextManager()
Get the context manager for XNIO workers.- Returns:
- the context manager (not
null
)
-
getInstanceContextManager
public org.wildfly.common.context.ContextManager<XnioWorker> getInstanceContextManager()
Get the instance context manager for XNIO workers by delegating togetContextManager()
.- Specified by:
getInstanceContextManager
in interfaceorg.wildfly.common.context.Contextual<XnioWorker>
- Returns:
- the context manager (not
null
)
-
createStreamServer
@Deprecated public AcceptingChannel<? extends ConnectedStreamChannel> createStreamServer(java.net.SocketAddress bindAddress, ChannelListener<? super AcceptingChannel<ConnectedStreamChannel>> acceptListener, OptionMap optionMap) throws java.io.IOException
Deprecated.Create a stream server, for TCP or UNIX domain servers. The type of server is determined by the bind address.- Parameters:
bindAddress
- the address to bind toacceptListener
- the initial accept listeneroptionMap
- the initial configuration for the server- Returns:
- the acceptor
- Throws:
java.io.IOException
- if the server could not be created
-
createStreamConnectionServer
public AcceptingChannel<StreamConnection> createStreamConnectionServer(java.net.SocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap) throws java.io.IOException
Create a stream server, for TCP or UNIX domain servers. The type of server is determined by the bind address.- Parameters:
bindAddress
- the address to bind toacceptListener
- the initial accept listeneroptionMap
- the initial configuration for the server- Returns:
- the acceptor
- Throws:
java.io.IOException
- if the server could not be created
-
createTcpConnectionServer
protected AcceptingChannel<StreamConnection> createTcpConnectionServer(java.net.InetSocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap) throws java.io.IOException
Implementation helper method to create a TCP stream server.- Parameters:
bindAddress
- the address to bind toacceptListener
- the initial accept listeneroptionMap
- the initial configuration for the server- Returns:
- the acceptor
- Throws:
java.io.IOException
- if the server could not be created
-
createLocalStreamConnectionServer
protected AcceptingChannel<StreamConnection> createLocalStreamConnectionServer(LocalSocketAddress bindAddress, ChannelListener<? super AcceptingChannel<StreamConnection>> acceptListener, OptionMap optionMap) throws java.io.IOException
Implementation helper method to create a UNIX domain stream server.- Parameters:
bindAddress
- the address to bind toacceptListener
- the initial accept listeneroptionMap
- the initial configuration for the server- Returns:
- the acceptor
- Throws:
java.io.IOException
- if the server could not be created
-
connectStream
@Deprecated public IoFuture<ConnectedStreamChannel> connectStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, OptionMap optionMap)
Deprecated.Connect to a remote stream server. The protocol family is determined by the type of the socket address given.- 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
-
connectStream
@Deprecated public IoFuture<ConnectedStreamChannel> connectStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.Connect to a remote stream server. The protocol family is determined by the type of the socket address given.- 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
-
connectStream
@Deprecated public IoFuture<ConnectedStreamChannel> connectStream(java.net.SocketAddress bindAddress, java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.Connect to a remote stream server. The protocol family is determined by the type of the socket addresses given (which must match).- 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
-
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
-
acceptStream
@Deprecated public IoFuture<ConnectedStreamChannel> acceptStream(java.net.SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.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.- 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
-
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
-
connectDatagram
@Deprecated public IoFuture<ConnectedMessageChannel> connectDatagram(java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.Connect to a remote datagram server. The protocol family is determined by the type of the socket address given.- 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
-
connectDatagram
@Deprecated public IoFuture<ConnectedMessageChannel> connectDatagram(java.net.SocketAddress bindAddress, java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.Connect to a remote datagram server. The protocol family is determined by the type of the socket addresses given (which must match).- 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
-
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
-
acceptDatagram
@Deprecated public IoFuture<ConnectedMessageChannel> acceptDatagram(java.net.SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap)
Deprecated.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.- 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
-
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
-
createUdpServer
public MulticastMessageChannel createUdpServer(java.net.InetSocketAddress bindAddress, ChannelListener<? super MulticastMessageChannel> bindListener, OptionMap optionMap) throws java.io.IOException
Create a UDP server. The UDP server can be configured to be multicast-capable; this should only be done if multicast is needed, since some providers have a performance penalty associated with multicast. The provider's default executor will be used to execute listener methods.- Parameters:
bindAddress
- the bind addressbindListener
- the initial open-connection listeneroptionMap
- the initial configuration for the server- Returns:
- the UDP server channel
- Throws:
java.io.IOException
- if the server could not be created- Since:
- 3.0
-
createUdpServer
public MulticastMessageChannel createUdpServer(java.net.InetSocketAddress bindAddress, OptionMap optionMap) throws java.io.IOException
Create a UDP server. The UDP server can be configured to be multicast-capable; this should only be done if multicast is needed, since some providers have a performance penalty associated with multicast. The provider's default executor will be used to execute listener methods.- Parameters:
bindAddress
- the bind addressoptionMap
- the initial configuration for the server- Returns:
- the UDP server channel
- Throws:
java.io.IOException
- if the server could not be created- Since:
- 3.0
-
createPipe
@Deprecated public void createPipe(ChannelListener<? super StreamChannel> leftOpenListener, ChannelListener<? super StreamChannel> rightOpenListener, OptionMap optionMap) throws java.io.IOException
Deprecated.Users should prefer the simplercreateFullDuplexPipe()
instead.Open a bidirectional stream pipe.- Parameters:
leftOpenListener
- the left-hand open listenerrightOpenListener
- the right-hand open listeneroptionMap
- the pipe channel configuration- Throws:
java.io.IOException
- if the pipe could not be created
-
createOneWayPipe
@Deprecated public void createOneWayPipe(ChannelListener<? super StreamSourceChannel> sourceListener, ChannelListener<? super StreamSinkChannel> sinkListener, OptionMap optionMap) throws java.io.IOException
Deprecated.Users should prefer the simplercreateHalfDuplexPipe()
instead.Open a unidirectional stream pipe.- Parameters:
sourceListener
- the source open listenersinkListener
- the sink open listeneroptionMap
- the pipe channel configuration- Throws:
java.io.IOException
- if the pipe could not be created
-
getInflatingChannel
public StreamSourceChannel getInflatingChannel(StreamSourceChannel delegate, OptionMap options) throws java.io.IOException
Create a stream channel that decompresses the source data according to the configuration in the given option map.- Parameters:
delegate
- the compressed channeloptions
- the configuration options for the channel- Returns:
- a decompressed channel
- Throws:
java.io.IOException
- if the channel could not be constructed
-
getInflatingChannel
protected StreamSourceChannel getInflatingChannel(StreamSourceChannel delegate, java.util.zip.Inflater inflater) throws java.io.IOException
Create a stream channel that decompresses the source data according to the configuration in the given inflater.- Parameters:
delegate
- the compressed channelinflater
- the inflater to use- Returns:
- a decompressed channel
- Throws:
java.io.IOException
- if the channel could not be constructed
-
getDeflatingChannel
public StreamSinkChannel getDeflatingChannel(StreamSinkChannel delegate, OptionMap options) throws java.io.IOException
Create a stream channel that compresses to the destination according to the configuration in the given option map.- Parameters:
delegate
- the channel to compress tooptions
- the configuration options for the channel- Returns:
- a compressed channel
- Throws:
java.io.IOException
- if the channel could not be constructed
-
getDeflatingChannel
protected StreamSinkChannel getDeflatingChannel(StreamSinkChannel delegate, java.util.zip.Deflater deflater) throws java.io.IOException
Create a stream channel that compresses to the destination according to the configuration in the given inflater.- Parameters:
delegate
- the channel to compress todeflater
- the deflater to use- Returns:
- a compressed channel
- Throws:
java.io.IOException
- if the channel could not be constructed
-
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
-
shutdown
public abstract void shutdown()
Shut down this worker. This method returns immediately. Upon return worker shutdown will have commenced but not necessarily completed. When worker shutdown is complete, the termination task (if one was defined) will be executed.- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public abstract java.util.List<java.lang.Runnable> shutdownNow()
Immediately terminate the worker. Any outstanding tasks are collected and returned in a list. Upon return worker shutdown will have commenced but not necessarily completed; however the worker will only complete its current tasks instead of completing all tasks.- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
- Returns:
- the list of outstanding tasks
-
isShutdown
public abstract boolean isShutdown()
Determine whether the worker has been shut down. Will returntrue
once either shutdown method has been called.- Specified by:
isShutdown
in interfacejava.util.concurrent.ExecutorService
- Returns:
true
the worker has been shut down
-
isTerminated
public abstract boolean isTerminated()
Determine whether the worker has terminated. Will returntrue
once all worker threads are exited (with the possible exception of the thread running the termination task, if any).- Specified by:
isTerminated
in interfacejava.util.concurrent.ExecutorService
- Returns:
true
if the worker is terminated
-
awaitTermination
public abstract boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Wait for termination.- Specified by:
awaitTermination
in interfacejava.util.concurrent.ExecutorService
- Parameters:
timeout
- the amount of time to waitunit
- the unit of time- Returns:
true
if termination completed before the timeout expired- Throws:
java.lang.InterruptedException
- if the operation was interrupted
-
awaitTermination
public abstract void awaitTermination() throws java.lang.InterruptedException
Wait for termination.- Throws:
java.lang.InterruptedException
- if the operation was interrupted
-
getIoThread
public final XnioIoThread getIoThread()
Get an I/O thread from this worker. The thread may be chosen based on arbitrary rules.- Returns:
- the I/O thread
-
getIoThread
public abstract XnioIoThread getIoThread(int hashCode)
Get an I/O thread from this worker. The thread is chosen based on the given hash code.- Parameters:
hashCode
- the hash code- Returns:
- the thread
-
getTerminationTask
protected java.lang.Runnable getTerminationTask()
Get the user task to run once termination is complete.- Returns:
- the termination task
-
taskPoolTerminated
protected void taskPoolTerminated()
Callback to indicate that the task thread pool has terminated. Not called if the task pool is external.
-
shutDownTaskPool
protected void shutDownTaskPool()
Initiate shutdown of the task thread pool. When all the tasks and threads have completed, thetaskPoolTerminated()
method is called.
-
shutDownTaskPoolNow
protected java.util.List<java.lang.Runnable> shutDownTaskPoolNow()
Shut down the task thread pool immediately and return its pending tasks.- Returns:
- the pending task list
-
isTaskPoolExternal
protected boolean isTaskPoolExternal()
Determine whether the worker task pool is managed externally. Externally managed task pools will never respond to shut down requests.- Returns:
true
if the task pool is externally managed,false
otherwise
-
execute
public void execute(java.lang.Runnable command)
Execute a command in the task pool.- Specified by:
execute
in interfacejava.util.concurrent.Executor
- Parameters:
command
- the command to run
-
getIoThreadCount
public abstract int getIoThreadCount()
Get the number of I/O threads configured on this worker.- Returns:
- the number of I/O threads configured on this worker
-
supportsOption
public boolean supportsOption(Option<?> option)
Description copied from interface:Configurable
Determine whether an option is supported on this channel.- Specified by:
supportsOption
in interfaceConfigurable
- Parameters:
option
- the option- Returns:
true
if it is supported
-
getOption
public <T> T getOption(Option<T> option) throws java.io.IOException
Description copied from interface:Configurable
Get the value of a channel option.- Specified by:
getOption
in interfaceConfigurable
- 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:
java.io.IOException
- if an I/O error occurred when reading the option
-
setOption
public <T> T setOption(Option<T> option, T value) throws java.lang.IllegalArgumentException, java.io.IOException
Description copied from interface:Configurable
Set an option for this channel. Unsupported options are ignored.- Specified by:
setOption
in interfaceConfigurable
- Type Parameters:
T
- the type of the option value- Parameters:
option
- the option to setvalue
- the value of the option to set- Returns:
- the previous option value, if any
- Throws:
java.lang.IllegalArgumentException
- if the value is not acceptable for this optionjava.io.IOException
- if an I/O error occurred when modifying the option
-
getXnio
public Xnio getXnio()
Get the XNIO provider which produced this worker.- Returns:
- the XNIO provider
-
getName
public java.lang.String getName()
Get the name of this worker.- Returns:
- the name of the worker
-
chooseThread
protected abstract XnioIoThread chooseThread()
Choose a thread randomly from this worker.- Returns:
- the thread
-
getCoreWorkerPoolSize
protected final int getCoreWorkerPoolSize()
Get the core worker pool size.- Returns:
- the core worker pool size
-
getBusyWorkerThreadCount
protected final int getBusyWorkerThreadCount()
Get an estimate of the number of busy threads in the worker pool.- Returns:
- the estimated number of busy threads in the worker pool
-
getWorkerPoolSize
protected final int getWorkerPoolSize()
Get an estimate of the number of threads in the worker pool.- Returns:
- the estimated number of threads in the worker pool
-
getMaxWorkerPoolSize
protected final int getMaxWorkerPoolSize()
Get the maximum worker pool size.- Returns:
- the maximum worker pool size
-
getWorkerQueueSize
protected final int getWorkerQueueSize()
Get an estimate of the number of tasks in the worker queue.- Returns:
- the estimated number of tasks
-
getBindAddressTable
protected org.wildfly.common.net.CidrAddressTable<java.net.InetSocketAddress> getBindAddressTable()
Get the bind address table.- Returns:
- the bind address table
-
getBindAddress
public java.net.InetSocketAddress getBindAddress(java.net.InetAddress destination)
Get the expected bind address for the given destination, if any.- Returns:
- the expected bind address for the given destination, or
null
if no explicit bind will be done
-
getMXBean
public abstract XnioWorkerMXBean getMXBean()
-
registerServerMXBean
protected abstract ManagementRegistration registerServerMXBean(XnioServerMXBean metrics)
-
-