org.jboss.xnio
Class Xnio

java.lang.Object
  extended by org.jboss.xnio.Xnio
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
NioXnio

public abstract class Xnio
extends java.lang.Object
implements java.io.Closeable

The XNIO entry point class.


Constructor Summary
protected Xnio(XnioConfiguration configuration)
          Construct an XNIO provider instance.
 
Method Summary
 void awaken(java.lang.Thread targetThread)
          Wake up any blocking I/O operation being carried out on a given thread.
abstract  void close()
          Close this XNIO provider.
static Xnio create()
          Create an instance of the default XNIO provider.
 ConfigurableFactory<CloseableConnector<java.lang.String,DatagramChannel<java.lang.String>>> createLocalDatagramConnector()
          Create a configurable local datagram connector.
 ConfigurableFactory<CloseableConnector<java.lang.String,DatagramChannel<java.lang.String>>> createLocalDatagramConnector(java.util.concurrent.Executor executor)
          Create a configurable local datagram connector.
 ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalDatagramServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super DatagramChannel<java.lang.String>> handlerFactory)
          Create a local datagram server.
 ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalDatagramServer(IoHandlerFactory<? super DatagramChannel<java.lang.String>> handlerFactory)
          Create a local datagram server.
 ConfigurableFactory<CloseableConnector<java.lang.String,ConnectedStreamChannel<java.lang.String>>> createLocalStreamConnector()
          Create a configurable local stream connector.
 ConfigurableFactory<CloseableConnector<java.lang.String,ConnectedStreamChannel<java.lang.String>>> createLocalStreamConnector(java.util.concurrent.Executor executor)
          Create a configurable local stream connector.
 ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalStreamServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super ConnectedStreamChannel<java.lang.String>> handlerFactory)
          Create a local stream server.
 ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalStreamServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a local stream server.
 IoFuture<java.io.Closeable> createOneWayPipeConnection(java.util.concurrent.Executor executor, IoHandler<? super StreamSourceChannel> sourceHandler, IoHandler<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<java.io.Closeable> createOneWayPipeConnection(IoHandler<? super StreamSourceChannel> sourceHandler, IoHandler<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<java.io.Closeable> createPipeConnection(java.util.concurrent.Executor executor, IoHandler<? super StreamChannel> leftHandler, IoHandler<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 IoFuture<java.io.Closeable> createPipeConnection(IoHandler<? super StreamChannel> leftHandler, IoHandler<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 ChannelSource<StreamChannel> createPipeServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a pipe "server".
 ChannelSource<StreamChannel> createPipeServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a pipe "server".
 ChannelSource<StreamSinkChannel> createPipeSinkServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super StreamSourceChannel> handlerFactory)
          Create a one-way pipe "server".
 ChannelSource<StreamSinkChannel> createPipeSinkServer(IoHandlerFactory<? super StreamSourceChannel> handlerFactory)
          Create a one-way pipe "server".
 ChannelSource<StreamSourceChannel> createPipeSourceServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super StreamSinkChannel> handlerFactory)
          Create a one-way pipe "server".
 ChannelSource<StreamSourceChannel> createPipeSourceServer(IoHandlerFactory<? super StreamSinkChannel> handlerFactory)
          Create a one-way pipe "server".
 ConfigurableFactory<CloseableTcpAcceptor> createTcpAcceptor()
          Create a TCP acceptor.
 ConfigurableFactory<CloseableTcpAcceptor> createTcpAcceptor(java.util.concurrent.Executor executor)
          Create a TCP acceptor.
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector()
          Create a configurable TCP connector.
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector(java.util.concurrent.Executor executor)
          Create a configurable TCP connector.
 ConfigurableFactory<BoundServer<java.net.SocketAddress,BoundChannel<java.net.SocketAddress>>> createTcpServer(java.util.concurrent.Executor executor, IoHandlerFactory<? super TcpChannel> handlerFactory, java.net.SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<BoundServer<java.net.SocketAddress,BoundChannel<java.net.SocketAddress>>> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory, java.net.SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<BoundServer<java.net.SocketAddress,UdpChannel>> createUdpServer(boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, java.net.SocketAddress... bindAddresses)
          Create a UDP server.
 ConfigurableFactory<BoundServer<java.net.SocketAddress,UdpChannel>> createUdpServer(java.util.concurrent.Executor executor, boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, java.net.SocketAddress... bindAddresses)
          Create a UDP server.
 java.lang.String getName()
          Get the name of this XNIO instance.
protected  java.lang.String getProperty(java.lang.String name)
          Get an XNIO property.
protected  java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
          Get an XNIO property.
protected  java.io.Closeable registerMBean(OneWayPipeConnectionMBean mBean)
          Register a one-way pipe connection MBean.
protected  java.io.Closeable registerMBean(PipeConnectionMBean mBean)
          Register a pipe connection MBean.
protected  java.io.Closeable registerMBean(PipeServerMBean mBean)
          Register a pipe server MBean.
protected  java.io.Closeable registerMBean(PipeSinkServerMBean mBean)
          Register a pipe sink server MBean.
protected  java.io.Closeable registerMBean(PipeSourceServerMBean mBean)
          Register a pipe source server MBean.
protected  java.io.Closeable registerMBean(TcpConnectionMBean mBean)
          Register a TCP connection MBean.
protected  java.io.Closeable registerMBean(TcpServerMBean mBean)
          Register a TCP server MBean.
protected  java.io.Closeable registerMBean(UdpServerMBean mBean)
          Register a UDP server MBean.
 java.lang.String toString()
          Get a string representation of this XNIO instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Xnio

protected Xnio(XnioConfiguration configuration)
Construct an XNIO provider instance.

Method Detail

create

public static Xnio create()
                   throws java.io.IOException
Create an instance of the default XNIO provider. The class name of this provider can be specified through the xnio.provider system property. Any failure to create the XNIO provider will cause an java.io.IOException to be thrown.

Returns:
an XNIO instance
Throws:
java.io.IOException - the the XNIO provider could not be created

createTcpServer

public ConfigurableFactory<BoundServer<java.net.SocketAddress,BoundChannel<java.net.SocketAddress>>> createTcpServer(java.util.concurrent.Executor executor,
                                                                                                                     IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                                                                                     java.net.SocketAddress... bindAddresses)
Create a TCP server. The server will bind to the given addresses. The provider's executor will be used to execute handler methods.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the factory which will produce handlers for inbound connections
bindAddresses - the addresses to bind to
Returns:
a factory that can be used to configure the new TCP server

createTcpServer

public ConfigurableFactory<BoundServer<java.net.SocketAddress,BoundChannel<java.net.SocketAddress>>> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                                                                                     java.net.SocketAddress... bindAddresses)
Create a TCP server. The server will bind to the given addresses. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the factory which will produce handlers for inbound connections
bindAddresses - the addresses to bind to
Returns:
a factory that can be used to configure the new TCP server

createTcpConnector

public ConfigurableFactory<CloseableTcpConnector> createTcpConnector(java.util.concurrent.Executor executor)
Create a configurable TCP connector. The connector can be configured before it is actually created.

Parameters:
executor - the executor to use to execute the handlers
Returns:
a factory that can be used to configure the new TCP connector

createTcpConnector

public ConfigurableFactory<CloseableTcpConnector> createTcpConnector()
Create a configurable TCP connector. The connector can be configured before it is actually created. The provider's default executor will be used to execute handler methods.

Returns:
a factory that can be used to configure the new TCP connector

createUdpServer

public ConfigurableFactory<BoundServer<java.net.SocketAddress,UdpChannel>> createUdpServer(java.util.concurrent.Executor executor,
                                                                                           boolean multicast,
                                                                                           IoHandlerFactory<? super UdpChannel> handlerFactory,
                                                                                           java.net.SocketAddress... bindAddresses)
Create a UDP server. The server will bind to the given addresses. 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.

Parameters:
executor - the executor to use to execute the handlers
multicast - true if the UDP server should be multicast-capable
handlerFactory - the factory which will produce handlers for each channel
bindAddresses - the addresses to bind
Returns:
a factory that can be used to configure the new UDP server

createUdpServer

public ConfigurableFactory<BoundServer<java.net.SocketAddress,UdpChannel>> createUdpServer(boolean multicast,
                                                                                           IoHandlerFactory<? super UdpChannel> handlerFactory,
                                                                                           java.net.SocketAddress... bindAddresses)
Create a UDP server. The server will bind to the given addresses. The provider's default executor will be used to execute handler methods.

Parameters:
multicast - true if the UDP server should be multicast-capable
handlerFactory - the factory which will produce handlers for each channel
bindAddresses - the addresses to bind
Returns:
a factory that can be used to configure the new UDP server

createPipeServer

public ChannelSource<StreamChannel> createPipeServer(java.util.concurrent.Executor executor,
                                                     IoHandlerFactory<? super StreamChannel> handlerFactory)
Create a pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.2

createPipeServer

public ChannelSource<StreamChannel> createPipeServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
Create a pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.1

createPipeSourceServer

public ChannelSource<StreamSourceChannel> createPipeSourceServer(java.util.concurrent.Executor executor,
                                                                 IoHandlerFactory<? super StreamSinkChannel> handlerFactory)
Create a one-way pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server. The data flows from the server to the client.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.2

createPipeSourceServer

public ChannelSource<StreamSourceChannel> createPipeSourceServer(IoHandlerFactory<? super StreamSinkChannel> handlerFactory)
Create a one-way pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server. The data flows from the server to the client. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.1

createPipeSinkServer

public ChannelSource<StreamSinkChannel> createPipeSinkServer(java.util.concurrent.Executor executor,
                                                             IoHandlerFactory<? super StreamSourceChannel> handlerFactory)
Create a one-way pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server. The data flows from the client to the server.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.2

createPipeSinkServer

public ChannelSource<StreamSinkChannel> createPipeSinkServer(IoHandlerFactory<? super StreamSourceChannel> handlerFactory)
Create a one-way pipe "server". The provided handler factory is used to supply handlers for the server "end" of the pipe. The returned channel source is used to establish connections to the server. The data flows from the client to the server. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source
Since:
1.1

createPipeConnection

public IoFuture<java.io.Closeable> createPipeConnection(java.util.concurrent.Executor executor,
                                                        IoHandler<? super StreamChannel> leftHandler,
                                                        IoHandler<? super StreamChannel> rightHandler)
Create a single pipe connection.

Parameters:
executor - the executor to use to execute the handlers
leftHandler - the handler for the "left" side of the pipe
rightHandler - the handler for the "right" side of the pipe
Returns:
the future connection
Since:
1.2

createPipeConnection

public IoFuture<java.io.Closeable> createPipeConnection(IoHandler<? super StreamChannel> leftHandler,
                                                        IoHandler<? super StreamChannel> rightHandler)
Create a single pipe connection. The provider's default executor will be used to execute handler methods.

Parameters:
leftHandler - the handler for the "left" side of the pipe
rightHandler - the handler for the "right" side of the pipe
Returns:
the future connection
Since:
1.1

createOneWayPipeConnection

public IoFuture<java.io.Closeable> createOneWayPipeConnection(java.util.concurrent.Executor executor,
                                                              IoHandler<? super StreamSourceChannel> sourceHandler,
                                                              IoHandler<? super StreamSinkChannel> sinkHandler)
Create a single one-way pipe connection.

Parameters:
executor - the executor to use to execute the handlers
sourceHandler - the handler for the "source" side of the pipe
sinkHandler - the handler for the "sink" side of the pipe
Returns:
the future connection
Since:
1.2

createOneWayPipeConnection

public IoFuture<java.io.Closeable> createOneWayPipeConnection(IoHandler<? super StreamSourceChannel> sourceHandler,
                                                              IoHandler<? super StreamSinkChannel> sinkHandler)
Create a single one-way pipe connection. The provider's default executor will be used to execute handler methods.

Parameters:
sourceHandler - the handler for the "source" side of the pipe
sinkHandler - the handler for the "sink" side of the pipe
Returns:
the future connection
Since:
1.1

createTcpAcceptor

public ConfigurableFactory<CloseableTcpAcceptor> createTcpAcceptor(java.util.concurrent.Executor executor)
Create a TCP acceptor.

Parameters:
executor - the executor to use to execute the handlers
Returns:
a factory that can be used to configure a TCP acceptor
Since:
1.2

createTcpAcceptor

public ConfigurableFactory<CloseableTcpAcceptor> createTcpAcceptor()
Create a TCP acceptor. The provider's default executor will be used to execute handler methods.

Returns:
a factory that can be used to configure a TCP acceptor
Since:
1.2

createLocalStreamServer

public ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalStreamServer(java.util.concurrent.Executor executor,
                                                                                                                 IoHandlerFactory<? super ConnectedStreamChannel<java.lang.String>> handlerFactory)
Create a local stream server. The stream server is bound to one or more files in the filesystem. If no bind addresses are specified, one is created.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the factory which will produce handlers for inbound connections
Returns:
a factory that can be used to configure the new stream server
Since:
1.2

createLocalStreamServer

public ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalStreamServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
Create a local stream server. The stream server is bound to one or more files in the filesystem. If no bind addresses are specified, one is created. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the factory which will produce handlers for inbound connections
Returns:
a factory that can be used to configure the new stream server
Since:
1.2

createLocalStreamConnector

public ConfigurableFactory<CloseableConnector<java.lang.String,ConnectedStreamChannel<java.lang.String>>> createLocalStreamConnector(java.util.concurrent.Executor executor)
Create a configurable local stream connector. The connector can be configured before it is actually created.

Parameters:
executor - the executor to use to execute the handlers
Returns:
a factory that can be used to configure the new local stream connector
Since:
1.2

createLocalStreamConnector

public ConfigurableFactory<CloseableConnector<java.lang.String,ConnectedStreamChannel<java.lang.String>>> createLocalStreamConnector()
Create a configurable local stream connector. The connector can be configured before it is actually created. The provider's default executor will be used to execute handler methods.

Returns:
a factory that can be used to configure the new local stream connector
Since:
1.2

createLocalDatagramServer

public ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalDatagramServer(java.util.concurrent.Executor executor,
                                                                                                                   IoHandlerFactory<? super DatagramChannel<java.lang.String>> handlerFactory)
Create a local datagram server. The datagram server is bound to one or more files in the filesystem. If no bind addresses are specified, one is created.

Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the factory which will produce handlers for inbound connections
Returns:
a factory that can be used to configure the new datagram server
Since:
1.2

createLocalDatagramServer

public ConfigurableFactory<BoundServer<java.lang.String,BoundChannel<java.lang.String>>> createLocalDatagramServer(IoHandlerFactory<? super DatagramChannel<java.lang.String>> handlerFactory)
Create a local datagram server. The datagram server is bound to one or more files in the filesystem. If no bind addresses are specified, one is created. The provider's default executor will be used to execute handler methods.

Parameters:
handlerFactory - the factory which will produce handlers for inbound connections
Returns:
a factory that can be used to configure the new datagram server
Since:
1.2

createLocalDatagramConnector

public ConfigurableFactory<CloseableConnector<java.lang.String,DatagramChannel<java.lang.String>>> createLocalDatagramConnector(java.util.concurrent.Executor executor)
Create a configurable local datagram connector. The connector can be configured before it is actually created.

Parameters:
executor - the executor to use to execute the handlers
Returns:
a factory that can be used to configure the new local datagram connector
Since:
1.2

createLocalDatagramConnector

public ConfigurableFactory<CloseableConnector<java.lang.String,DatagramChannel<java.lang.String>>> createLocalDatagramConnector()
Create a configurable local datagram connector. The connector can be configured before it is actually created. The provider's default executor will be used to execute handler methods.

Returns:
a factory that can be used to configure the new local datagram connector
Since:
1.2

awaken

public void awaken(java.lang.Thread targetThread)
Wake up any blocking I/O operation being carried out on a given thread. Custom implementors of Thread may call this method from their implementation of Thread.interrupt() after the default implementation to ensure that any thread waiting in a blocking operation is woken up in a timely manner. Some implementations may not implement this method, relying instead on the interruption mechanism built in to the JVM; as such this method should not be relied upon as a guaranteed way to awaken a blocking thread independently of thread interruption.

Parameters:
targetThread - the thread to awaken
Since:
1.2

getName

public java.lang.String getName()
Get the name of this XNIO instance.

Returns:
the name

toString

public java.lang.String toString()
Get a string representation of this XNIO instance.

Overrides:
toString in class java.lang.Object
Returns:
the string representation

close

public abstract void close()
                    throws java.io.IOException
Close this XNIO provider. Calling this method more than one time has no additional effect.

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

getProperty

protected java.lang.String getProperty(java.lang.String name)
Get an XNIO property. The property name must start with "xnio.".

Parameters:
name - the property name
Returns:
the property value, or null if it wasn't found
Since:
1.2

getProperty

protected java.lang.String getProperty(java.lang.String name,
                                       java.lang.String defaultValue)
Get an XNIO property. The property name must start with "xnio.".

Parameters:
name - the property name
defaultValue - the default value
Returns:
the property value, or defaultValue if it wasn't found
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(TcpServerMBean mBean)
Register a TCP server MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(TcpConnectionMBean mBean)
Register a TCP connection MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(UdpServerMBean mBean)
Register a UDP server MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(OneWayPipeConnectionMBean mBean)
Register a one-way pipe connection MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(PipeConnectionMBean mBean)
Register a pipe connection MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(PipeServerMBean mBean)
Register a pipe server MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(PipeSourceServerMBean mBean)
Register a pipe source server MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2

registerMBean

protected java.io.Closeable registerMBean(PipeSinkServerMBean mBean)
Register a pipe sink server MBean.

Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean
Since:
1.2