XNIO version 1.1.1.GA

org.jboss.xnio
Class Xnio

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

public abstract class Xnio
extends Object
implements Closeable

The XNIO entry point class.


Constructor Summary
protected Xnio()
          Construct an XNIO provider instance.
 
Method Summary
abstract  void close()
          Close this XNIO provider.
static Xnio create()
          Create an instance of the default XNIO provider.
static Xnio createNio()
          Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.
static Xnio createNio(Executor handlerExecutor, int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.
static Xnio createNio(Executor handlerExecutor, ThreadFactory selectorThreadFactory, int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.
static Xnio createNio(int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.
 IoFuture<Closeable> createOneWayPipeConnection(IoHandler<? super StreamSourceChannel> sourceHandler, IoHandler<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<Closeable> createPipeConnection(IoHandler<? super StreamChannel> leftHandler, IoHandler<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 ChannelSource<StreamChannel> createPipeServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a pipe "server".
 ChannelSource<StreamSinkChannel> createPipeSinkServer(IoHandlerFactory<? super StreamSourceChannel> handlerFactory)
          Create a one-way pipe "server".
 ChannelSource<StreamSourceChannel> createPipeSourceServer(IoHandlerFactory<? super StreamSinkChannel> handlerFactory)
          Create a one-way pipe "server".
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector()
          Create a configurable TCP connector.
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector(Executor executor)
          Create a configurable TCP connector.
 ConfigurableFactory<Closeable> createTcpServer(Executor executor, IoHandlerFactory<? super TcpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<Closeable> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<Closeable> createUdpServer(boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a UDP server.
 ConfigurableFactory<Closeable> createUdpServer(Executor executor, boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a UDP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Xnio

protected Xnio()
Construct an XNIO provider instance.

Method Detail

create

public static Xnio create()
                   throws 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:
IOException - the the XNIO provider could not be created

createNio

@Deprecated
public static Xnio createNio()
                      throws IOException
Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.

Create an NIO-based XNIO provider. A direct executor is used for the handlers; the provider will create its own selector threads, of which there will be one reader thread, one writer thread, and one connect/accept thread.

Returns:
a new provider
Throws:
IOException - if an I/O error occurs while starting the service

createNio

@Deprecated
public static Xnio createNio(int readSelectorThreads,
                                        int writeSelectorThreads,
                                        int connectSelectorThreads)
                      throws IOException,
                             IllegalArgumentException
Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.

Create an NIO-based XNIO provider. A direct executor is used for the handlers; the provider will create its own selector threads.

Parameters:
readSelectorThreads - the number of threads to assign for readable events
writeSelectorThreads - the number of threads to assign for writable events
connectSelectorThreads - the number of threads to assign for connect/accept events
Returns:
a new provider
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

createNio

@Deprecated
public static Xnio createNio(Executor handlerExecutor,
                                        int readSelectorThreads,
                                        int writeSelectorThreads,
                                        int connectSelectorThreads)
                      throws IOException,
                             IllegalArgumentException
Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.

Create an NIO-based XNIO provider. The given handler executor is used for the handlers; the provider will create its own selector threads.

Parameters:
handlerExecutor - the executor to use to handle events
readSelectorThreads - the number of threads to assign for readable events
writeSelectorThreads - the number of threads to assign for writable events
connectSelectorThreads - the number of threads to assign for connect/accept events
Returns:
a new provider
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

createNio

@Deprecated
public static Xnio createNio(Executor handlerExecutor,
                                        ThreadFactory selectorThreadFactory,
                                        int readSelectorThreads,
                                        int writeSelectorThreads,
                                        int connectSelectorThreads)
                      throws IOException,
                             IllegalArgumentException
Deprecated. Will be removed in 1.2. Please use create() instead, or use the constructor of your desired implementation.

Create an NIO-based XNIO provider. The given handler executor is used for the handlers; the given thread factory is used to create selector threads.

Parameters:
handlerExecutor - the executor to use to handle events
selectorThreadFactory - the selector thread factory to use
readSelectorThreads - the number of threads to assign for readable events
writeSelectorThreads - the number of threads to assign for writable events
connectSelectorThreads - the number of threads to assign for connect/accept events
Returns:
a new provider
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

createTcpServer

public ConfigurableFactory<Closeable> createTcpServer(Executor executor,
                                                      IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                      SocketAddress... bindAddresses)
Create a TCP server. The server will bind to the given addresses. If none are specified, then the server will attempt to bind to all addresses.

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<Closeable> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                      SocketAddress... bindAddresses)
Create a TCP server. The server will bind to the given addresses. If none are specified, then the server will attempt to bind to all addresses. The provider's 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(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 executor will be used to execute handler methods.

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

createUdpServer

public ConfigurableFactory<Closeable> createUdpServer(Executor executor,
                                                      boolean multicast,
                                                      IoHandlerFactory<? super UdpChannel> handlerFactory,
                                                      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:
multicast - true if the UDP server should be multicast-capable
executor - the executor to use to execute the handlers
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<Closeable> createUdpServer(boolean multicast,
                                                      IoHandlerFactory<? super UdpChannel> handlerFactory,
                                                      SocketAddress... bindAddresses)
Create a UDP server. The server will bind to the given addresses. The provider's 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(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:
handlerFactory - the server handler factory
Returns:
the client channel source

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.

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

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.

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

createPipeConnection

public IoFuture<Closeable> createPipeConnection(IoHandler<? super StreamChannel> leftHandler,
                                                IoHandler<? super StreamChannel> rightHandler)
Create a single pipe connection.

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

createOneWayPipeConnection

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

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

close

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

Specified by:
close in interface Closeable
Throws:
IOException

XNIO version 1.1.1.GA

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