XNIO version 1.2.0.GA

org.jboss.xnio.nio
Class NioXnio

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

public final class NioXnio
extends Xnio

An NIO-based XNIO provider for a standalone application.


Method Summary
 void awaken(Thread targetThread)
          Wake up any blocking I/O operation being carried out on a given thread.
 void close()
          Close this XNIO provider.
static Xnio create()
          Create an NIO-based XNIO provider.
static Xnio create(Executor handlerExecutor, int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Create an NIO-based XNIO provider.
static Xnio create(Executor handlerExecutor, ThreadFactory selectorThreadFactory, int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Create an NIO-based XNIO provider.
static Xnio create(int readSelectorThreads, int writeSelectorThreads, int connectSelectorThreads)
          Create an NIO-based XNIO provider.
static Xnio create(NioXnioConfiguration configuration)
          Create an NIO-based XNIO provider.
 IoFuture<Closeable> createOneWayPipeConnection(Executor executor, IoHandler<? super StreamSourceChannel> sourceHandler, IoHandler<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<Closeable> createOneWayPipeConnection(IoHandler<? super StreamSourceChannel> sourceHandler, IoHandler<? super StreamSinkChannel> sinkHandler)
          Create a single one-way pipe connection.
 IoFuture<Closeable> createPipeConnection(Executor executor, IoHandler<? super StreamChannel> leftHandler, IoHandler<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 IoFuture<Closeable> createPipeConnection(IoHandler<? super StreamChannel> leftHandler, IoHandler<? super StreamChannel> rightHandler)
          Create a single pipe connection.
 ChannelSource<StreamChannel> createPipeServer(Executor executor, IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a pipe "server".
 ChannelSource<StreamChannel> createPipeServer(IoHandlerFactory<? super StreamChannel> handlerFactory)
          Create a pipe "server".
 ChannelSource<StreamSinkChannel> createPipeSinkServer(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(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(Executor executor)
          Create a TCP acceptor.
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector()
          Create a configurable TCP connector.
 ConfigurableFactory<CloseableTcpConnector> createTcpConnector(Executor executor)
          Create a configurable TCP connector.
 ConfigurableFactory<BoundServer<SocketAddress,BoundChannel<SocketAddress>>> createTcpServer(Executor executor, IoHandlerFactory<? super TcpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<BoundServer<SocketAddress,BoundChannel<SocketAddress>>> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a TCP server.
 ConfigurableFactory<BoundServer<SocketAddress,UdpChannel>> createUdpServer(boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a UDP server.
 ConfigurableFactory<BoundServer<SocketAddress,UdpChannel>> createUdpServer(Executor executor, boolean multicast, IoHandlerFactory<? super UdpChannel> handlerFactory, SocketAddress... bindAddresses)
          Create a UDP server.
protected  Closeable registerMBean(OneWayPipeConnectionMBean mBean)
          Register a one-way pipe connection MBean.
protected  Closeable registerMBean(PipeConnectionMBean mBean)
          Register a pipe connection MBean.
protected  Closeable registerMBean(PipeServerMBean mBean)
          Register a pipe server MBean.
protected  Closeable registerMBean(PipeSinkServerMBean mBean)
          Register a pipe sink server MBean.
protected  Closeable registerMBean(PipeSourceServerMBean mBean)
          Register a pipe source server MBean.
protected  Closeable registerMBean(TcpConnectionMBean mBean)
          Register a TCP connection MBean.
protected  Closeable registerMBean(TcpServerMBean mBean)
          Register a TCP server MBean.
protected  Closeable registerMBean(UdpServerMBean mBean)
          Register a UDP server MBean.
 String toString()
          Get a string representation of this XNIO instance.
 
Methods inherited from class org.jboss.xnio.Xnio
createLocalDatagramConnector, createLocalDatagramConnector, createLocalDatagramServer, createLocalDatagramServer, createLocalStreamConnector, createLocalStreamConnector, createLocalStreamServer, createLocalStreamServer, getName, getProperty, getProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static Xnio create(NioXnioConfiguration configuration)
                   throws IOException
Create an NIO-based XNIO provider. The provided configuration is used to set up the provider.

Parameters:
configuration - the configuration
Returns:
a new XNIO instance
Throws:
IOException - if an I/O error occurs while starting the service
Since:
1.2

create

public static Xnio create()
                   throws IOException
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 XNIO instance
Throws:
IOException - if an I/O error occurs while starting the service

create

public static Xnio create(int readSelectorThreads,
                          int writeSelectorThreads,
                          int connectSelectorThreads)
                   throws IOException,
                          IllegalArgumentException
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 XNIO instance
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

create

public static Xnio create(Executor handlerExecutor,
                          int readSelectorThreads,
                          int writeSelectorThreads,
                          int connectSelectorThreads)
                   throws IOException,
                          IllegalArgumentException
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 XNIO instance
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

create

public static Xnio create(Executor handlerExecutor,
                          ThreadFactory selectorThreadFactory,
                          int readSelectorThreads,
                          int writeSelectorThreads,
                          int connectSelectorThreads)
                   throws IOException,
                          IllegalArgumentException
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 XNIO instance
Throws:
IOException - if an I/O error occurs while starting the service
IllegalArgumentException - if a given argument is not valid

createTcpServer

public ConfigurableFactory<BoundServer<SocketAddress,BoundChannel<SocketAddress>>> createTcpServer(Executor executor,
                                                                                                   IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                                                                   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.

Overrides:
createTcpServer in class Xnio
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<SocketAddress,BoundChannel<SocketAddress>>> createTcpServer(IoHandlerFactory<? super TcpChannel> handlerFactory,
                                                                                                   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.

Overrides:
createTcpServer in class Xnio
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.

Overrides:
createTcpConnector in class Xnio
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.

Overrides:
createTcpConnector in class Xnio
Returns:
a factory that can be used to configure the new TCP connector

createUdpServer

public ConfigurableFactory<BoundServer<SocketAddress,UdpChannel>> 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.

Overrides:
createUdpServer in class Xnio
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<SocketAddress,UdpChannel>> createUdpServer(boolean multicast,
                                                                                  IoHandlerFactory<? super UdpChannel> handlerFactory,
                                                                                  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.

Overrides:
createUdpServer in class Xnio
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(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.

Overrides:
createPipeServer in class Xnio
Parameters:
executor - the executor to use to execute the handlers
handlerFactory - the server handler factory
Returns:
the client channel source

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.

Overrides:
createPipeServer in class Xnio
Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source

createPipeSourceServer

public ChannelSource<StreamSourceChannel> createPipeSourceServer(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.

Overrides:
createPipeSourceServer in class Xnio
Parameters:
executor - the executor to use to execute the handlers
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. The provider's default executor will be used to execute handler methods.

Overrides:
createPipeSourceServer in class Xnio
Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source

createPipeSinkServer

public ChannelSource<StreamSinkChannel> createPipeSinkServer(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.

Overrides:
createPipeSinkServer in class Xnio
Parameters:
executor - the executor to use to execute the handlers
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. The provider's default executor will be used to execute handler methods.

Overrides:
createPipeSinkServer in class Xnio
Parameters:
handlerFactory - the server handler factory
Returns:
the client channel source

createPipeConnection

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

Overrides:
createPipeConnection in class Xnio
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

createPipeConnection

public IoFuture<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.

Overrides:
createPipeConnection in class Xnio
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(Executor executor,
                                                      IoHandler<? super StreamSourceChannel> sourceHandler,
                                                      IoHandler<? super StreamSinkChannel> sinkHandler)
Create a single one-way pipe connection.

Overrides:
createOneWayPipeConnection in class Xnio
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

createOneWayPipeConnection

public IoFuture<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.

Overrides:
createOneWayPipeConnection in class Xnio
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

createTcpAcceptor

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

Overrides:
createTcpAcceptor in class Xnio
Parameters:
executor - the executor to use to execute the handlers
Returns:
a factory that can be used to configure a TCP acceptor

createTcpAcceptor

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

Overrides:
createTcpAcceptor in class Xnio
Returns:
a factory that can be used to configure a TCP acceptor

awaken

public void awaken(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. This implementation relies on NIO mechanisms to awaken interrupted threads.

Overrides:
awaken in class Xnio
Parameters:
targetThread - the thread to awaken

close

public 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
Specified by:
close in class Xnio
Throws:
IOException

toString

public String toString()
Description copied from class: Xnio
Get a string representation of this XNIO instance.

Overrides:
toString in class Xnio
Returns:
the string representation

registerMBean

protected Closeable registerMBean(TcpServerMBean mBean)
Description copied from class: Xnio
Register a TCP server MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(TcpConnectionMBean mBean)
Description copied from class: Xnio
Register a TCP connection MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(UdpServerMBean mBean)
Description copied from class: Xnio
Register a UDP server MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(OneWayPipeConnectionMBean mBean)
Description copied from class: Xnio
Register a one-way pipe connection MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(PipeConnectionMBean mBean)
Description copied from class: Xnio
Register a pipe connection MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(PipeServerMBean mBean)
Description copied from class: Xnio
Register a pipe server MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(PipeSourceServerMBean mBean)
Description copied from class: Xnio
Register a pipe source server MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

registerMBean

protected Closeable registerMBean(PipeSinkServerMBean mBean)
Description copied from class: Xnio
Register a pipe sink server MBean.

Overrides:
registerMBean in class Xnio
Parameters:
mBean - the MBean
Returns:
a handle which may be used to unregister the MBean

XNIO version 1.2.0.GA

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