XNIO API 2.0.2.GA

org.jboss.xnio
Class Xnio

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

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.
static Xnio create(java.lang.String implName, XnioConfiguration configuration)
          Create an instance of the named XNIO provider.
static Xnio create(XnioConfiguration configuration)
          Create an instance of the default XNIO provider.
 LocalDatagramConnector createLocalDatagramConnector(java.util.concurrent.Executor executor, OptionMap optionMap)
          Create a local datagram connector.
 LocalDatagramConnector createLocalDatagramConnector(OptionMap optionMap)
          Create a local datagram connector.
 LocalServer createLocalDatagramServer(ChannelListener<? super DatagramChannel<java.lang.String>> openHandler, OptionMap optionMap)
          Create a local datagram server.
 LocalServer createLocalDatagramServer(java.util.concurrent.Executor executor, ChannelListener<? super DatagramChannel<java.lang.String>> openHandler, OptionMap optionMap)
          Create a local datagram server.
 LocalStreamConnector createLocalStreamConnector(java.util.concurrent.Executor executor, OptionMap optionMap)
          Create a local stream connector.
 LocalStreamConnector createLocalStreamConnector(OptionMap optionMap)
          Create a local stream connector.
 LocalServer createLocalStreamServer(ChannelListener<? super ConnectedStreamChannel<java.lang.String>> openListener, OptionMap optionMap)
          Create a local stream server.
 LocalServer createLocalStreamServer(java.util.concurrent.Executor executor, ChannelListener<? super ConnectedStreamChannel<java.lang.String>> openListener, OptionMap optionMap)
          Create a local stream server.
 javax.net.SocketFactory createManagedSocketFactory(OptionMap optionMap)
          Create a managed socket factory which uses this provider's MBean configuration to track management information.
 IoFuture<? extends java.io.Closeable> createOneWayPipeConnection(ChannelListener<? super StreamSourceChannel> sourceHandler, ChannelListener<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<? extends java.io.Closeable> createOneWayPipeConnection(java.util.concurrent.Executor executor, ChannelListener<? super StreamSourceChannel> sourceHandler, ChannelListener<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<? extends java.io.Closeable> createPipeConnection(ChannelListener<? super StreamChannel> leftHandler, ChannelListener<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 IoFuture<? extends java.io.Closeable> createPipeConnection(java.util.concurrent.Executor executor, ChannelListener<? super StreamChannel> leftHandler, ChannelListener<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 ChannelSource<? extends StreamChannel> createPipeServer(ChannelListener<? super StreamChannel> openHandler)
          Create a pipe "server".
 ChannelSource<? extends StreamChannel> createPipeServer(java.util.concurrent.Executor executor, ChannelListener<? super StreamChannel> openHandler)
          Create a pipe "server".
 ChannelSource<? extends StreamSinkChannel> createPipeSinkServer(ChannelListener<? super StreamSourceChannel> openHandler)
          Create a one-way pipe "server".
 ChannelSource<? extends StreamSinkChannel> createPipeSinkServer(java.util.concurrent.Executor executor, ChannelListener<? super StreamSourceChannel> openHandler)
          Create a one-way pipe "server".
 ChannelSource<? extends StreamSourceChannel> createPipeSourceServer(ChannelListener<? super StreamSinkChannel> openHandler)
          Create a one-way pipe "server".
 ChannelSource<? extends StreamSourceChannel> createPipeSourceServer(java.util.concurrent.Executor executor, ChannelListener<? super StreamSinkChannel> openHandler)
          Create a one-way pipe "server".
 javax.net.ServerSocketFactory createServerSocketFactory(OptionMap optionMap)
          Create a managed server socket factory which uses this provider's MBean configuration to track management information.
 TcpAcceptor createTcpAcceptor(java.util.concurrent.Executor executor, OptionMap optionMap)
          Create a TCP acceptor.
 TcpAcceptor createTcpAcceptor(OptionMap optionMap)
          Create a TCP acceptor.
 TcpConnector createTcpConnector(java.util.concurrent.Executor executor, java.net.InetSocketAddress src, OptionMap optionMap)
          Create a TCP connector.
 TcpConnector createTcpConnector(java.util.concurrent.Executor executor, OptionMap optionMap)
          Create a TCP connector.
 TcpConnector createTcpConnector(java.net.InetSocketAddress src, OptionMap optionMap)
          Create a TCP connector.
 TcpConnector createTcpConnector(OptionMap optionMap)
          Create a TCP connector.
 TcpServer createTcpServer(ChannelListener<? super TcpChannel> openHandler, OptionMap optionMap)
          Create an unbound TCP server.
 TcpServer createTcpServer(java.util.concurrent.Executor executor, ChannelListener<? super TcpChannel> openHandler, OptionMap optionMap)
          Create an unbound TCP server.
 UdpServer createUdpServer(ChannelListener<? super UdpChannel> openHandler, OptionMap optionMap)
          Create an unbound UDP server.
 UdpServer createUdpServer(java.util.concurrent.Executor executor, ChannelListener<? super UdpChannel> openHandler, OptionMap optionMap)
          Create an unbound UDP server.
 UdpServer createUdpServer(OptionMap optionMap)
          Create an unbound UDP server.
protected  java.util.concurrent.Executor getExecutor()
          Get the default handler executor.
 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

getExecutor

protected java.util.concurrent.Executor getExecutor()
Get the default handler executor.

Returns:
the executor

create

public static Xnio create()
                   throws java.io.IOException
Create an instance of the default XNIO provider. The provider name can be specified through the xnio.provider.name 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 - if the XNIO provider could not be created

create

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

Parameters:
configuration - the configuration parameters for the implementation
Returns:
an XNIO instance
Throws:
java.io.IOException - if the XNIO provider could not be created

create

public static Xnio create(java.lang.String implName,
                          XnioConfiguration configuration)
                   throws java.io.IOException
Create an instance of the named XNIO provider. Any failure to create the XNIO provider will cause an java.io.IOException to be thrown.

Parameters:
implName - the name of the implementation
configuration - the configuration parameters for the implementation
Returns:
an XNIO instance
Throws:
java.io.IOException - if the XNIO provider could not be created

createManagedSocketFactory

public javax.net.SocketFactory createManagedSocketFactory(OptionMap optionMap)
Create a managed socket factory which uses this provider's MBean configuration to track management information.

Parameters:
optionMap - the option map
Returns:
the managed socket factory
Since:
2.0

createServerSocketFactory

public javax.net.ServerSocketFactory createServerSocketFactory(OptionMap optionMap)
Create a managed server socket factory which uses this provider's MBean configuration to track management information.

Parameters:
optionMap - the option map
Returns:
the managed server socket factory
Since:
2.0

createTcpServer

public TcpServer createTcpServer(java.util.concurrent.Executor executor,
                                 ChannelListener<? super TcpChannel> openHandler,
                                 OptionMap optionMap)
Create an unbound TCP server. The given executor will be used to execute handler methods.

Parameters:
executor - the executor to use to execute the handlers
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
the unbound TCP server
Since:
2.0

createTcpServer

public TcpServer createTcpServer(ChannelListener<? super TcpChannel> openHandler,
                                 OptionMap optionMap)
Create an unbound TCP server. The provider's default executor will be used to execute handler methods.

Parameters:
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
the unbound TCP server
Since:
2.0

createTcpConnector

public TcpConnector createTcpConnector(java.util.concurrent.Executor executor,
                                       OptionMap optionMap)
Create a TCP connector. The given executor will be used to execute handler methods.

Parameters:
executor - the executor to use to execute the handlers
optionMap - the initial configuration for the connector
Returns:
the TCP connector
Since:
2.0

createTcpConnector

public TcpConnector createTcpConnector(OptionMap optionMap)
Create a TCP connector. The provider's default executor will be used to execute handler methods.

Parameters:
optionMap - the initial configuration for the connector
Returns:
the TCP connector
Since:
2.0

createTcpConnector

public TcpConnector createTcpConnector(java.util.concurrent.Executor executor,
                                       java.net.InetSocketAddress src,
                                       OptionMap optionMap)
Create a TCP connector. The given executor will be used to execute handler methods.

Parameters:
executor - the executor to use to execute the handlers
src - the source address for connections
optionMap - the initial configuration for the connector
Returns:
the TCP connector
Since:
2.0

createTcpConnector

public TcpConnector createTcpConnector(java.net.InetSocketAddress src,
                                       OptionMap optionMap)
Create a TCP connector. The provider's default executor will be used to execute handler methods.

Parameters:
src - the source address for connections
optionMap - the initial configuration for the connector
Returns:
the TCP connector
Since:
2.0

createUdpServer

public UdpServer createUdpServer(java.util.concurrent.Executor executor,
                                 ChannelListener<? super UdpChannel> openHandler,
                                 OptionMap optionMap)
Create an unbound 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 given executor will be used to execute handler methods.

Parameters:
executor - the executor to use to execute the handlers
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
a factory that can be used to configure the new UDP server
Since:
2.0

createUdpServer

public UdpServer createUdpServer(ChannelListener<? super UdpChannel> openHandler,
                                 OptionMap optionMap)
Create an unbound 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 handler methods.

Parameters:
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
a factory that can be used to configure the new UDP server
Since:
2.0

createUdpServer

public UdpServer createUdpServer(OptionMap optionMap)
Create an unbound 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 handler methods.

Parameters:
optionMap - the initial configuration for the server
Returns:
a factory that can be used to configure the new UDP server
Since:
2.0

createPipeServer

public ChannelSource<? extends StreamChannel> createPipeServer(java.util.concurrent.Executor executor,
                                                               ChannelListener<? super StreamChannel> openHandler)
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
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeServer

public ChannelSource<? extends StreamChannel> createPipeServer(ChannelListener<? super StreamChannel> openHandler)
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:
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeSourceServer

public ChannelSource<? extends StreamSourceChannel> createPipeSourceServer(java.util.concurrent.Executor executor,
                                                                           ChannelListener<? super StreamSinkChannel> openHandler)
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
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeSourceServer

public ChannelSource<? extends StreamSourceChannel> createPipeSourceServer(ChannelListener<? super StreamSinkChannel> openHandler)
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:
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeSinkServer

public ChannelSource<? extends StreamSinkChannel> createPipeSinkServer(java.util.concurrent.Executor executor,
                                                                       ChannelListener<? super StreamSourceChannel> openHandler)
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
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeSinkServer

public ChannelSource<? extends StreamSinkChannel> createPipeSinkServer(ChannelListener<? super StreamSourceChannel> openHandler)
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:
openHandler - the initial open-connection handler
Returns:
the client channel source
Since:
2.0

createPipeConnection

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

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

createPipeConnection

public IoFuture<? extends java.io.Closeable> createPipeConnection(ChannelListener<? super StreamChannel> leftHandler,
                                                                  ChannelListener<? 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:
2.0

createOneWayPipeConnection

public IoFuture<? extends java.io.Closeable> createOneWayPipeConnection(java.util.concurrent.Executor executor,
                                                                        ChannelListener<? super StreamSourceChannel> sourceHandler,
                                                                        ChannelListener<? 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:
2.0

createOneWayPipeConnection

public IoFuture<? extends java.io.Closeable> createOneWayPipeConnection(ChannelListener<? super StreamSourceChannel> sourceHandler,
                                                                        ChannelListener<? 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:
2.0

createTcpAcceptor

public TcpAcceptor createTcpAcceptor(java.util.concurrent.Executor executor,
                                     OptionMap optionMap)
Create a TCP acceptor.

Parameters:
executor - the executor to use to execute the handlers
optionMap - the initial configuration for the acceptor
Returns:
the TCP acceptor
Since:
2.0

createTcpAcceptor

public TcpAcceptor createTcpAcceptor(OptionMap optionMap)
Create a TCP acceptor.

Parameters:
optionMap - the initial configuration for the acceptor
Returns:
the TCP acceptor
Since:
2.0

createLocalStreamServer

public LocalServer createLocalStreamServer(java.util.concurrent.Executor executor,
                                           ChannelListener<? super ConnectedStreamChannel<java.lang.String>> openListener,
                                           OptionMap optionMap)
Create a local stream server. The stream server can be bound to one or more files in the filesystem.

Parameters:
executor - the executor to use to execute the handlers
openListener - a listener which is notified on channel open
optionMap - the initial configuration for the server
Returns:
a factory that can be used to configure the new stream server
Since:
2.0

createLocalStreamServer

public LocalServer createLocalStreamServer(ChannelListener<? super ConnectedStreamChannel<java.lang.String>> openListener,
                                           OptionMap optionMap)
Create a local stream server. The stream server can be bound to one or more files in the filesystem.

Parameters:
openListener - a listener which is notified on channel open
optionMap - the initial configuration for the server
Returns:
a factory that can be used to configure the new stream server
Since:
2.0

createLocalStreamConnector

public LocalStreamConnector createLocalStreamConnector(java.util.concurrent.Executor executor,
                                                       OptionMap optionMap)
Create a local stream connector.

Parameters:
executor - the executor to use to execute the handlers
optionMap - the initial configuration for the connector
Returns:
the stream connector
Since:
2.0

createLocalStreamConnector

public LocalStreamConnector createLocalStreamConnector(OptionMap optionMap)
Create a local stream connector.

Parameters:
optionMap - the initial configuration for the connector
Returns:
the stream connector
Since:
2.0

createLocalDatagramServer

public LocalServer createLocalDatagramServer(java.util.concurrent.Executor executor,
                                             ChannelListener<? super DatagramChannel<java.lang.String>> openHandler,
                                             OptionMap optionMap)
Create a local datagram server. The datagram server is bound to one or more files in the filesystem.

Parameters:
executor - the executor to use to execute the handlers
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
the new datagram server
Since:
2.0

createLocalDatagramServer

public LocalServer createLocalDatagramServer(ChannelListener<? super DatagramChannel<java.lang.String>> openHandler,
                                             OptionMap optionMap)
Create a local datagram server. The datagram server is bound to one or more files in the filesystem.

Parameters:
openHandler - the initial open-connection handler
optionMap - the initial configuration for the server
Returns:
the new datagram server
Since:
2.0

createLocalDatagramConnector

public LocalDatagramConnector createLocalDatagramConnector(java.util.concurrent.Executor executor,
                                                           OptionMap optionMap)
Create a local datagram connector.

Parameters:
executor - the executor to use to execute the handlers
optionMap - the initial configuration for the connector
Returns:
the new datagram connector
Since:
2.0

createLocalDatagramConnector

public LocalDatagramConnector createLocalDatagramConnector(OptionMap optionMap)
Create a local datagram connector.

Parameters:
optionMap - the initial configuration for the connector
Returns:
the new datagram connector
Since:
2.0

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

XNIO API 2.0.2.GA

Copyright © 2009 JBoss, a division of Red Hat, Inc.