org.apache.mina.transport.nio

## Class NioTcpServer

- java.lang.Object
- - org.apache.mina.service.AbstractIoService
  - - org.apache.mina.service.server.AbstractIoServer
    - - org.apache.mina.transport.tcp.AbstractTcpServer
      - - org.apache.mina.transport.nio.NioTcpServer

All Implemented Interfaces:
  IoServer, IoService, SelectorListener

    public class NioTcpServer
    extends AbstractTcpServer
    implements SelectorListener

This class implements a TCP NIO based server.

Author:
  Apache MINA Project

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.mina.service.AbstractIoService

`AbstractIoService.ServiceState`

### Field Summary

### Fields inherited from class org.apache.mina.service.AbstractIoService

`config, ioHandlerExecutor`

### Constructor Summary

Constructors
Constructor and Description
`NioTcpServer()` Create a TCP server with new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)
`NioTcpServer(SelectorLoopPool selectorLoopPool, IoHandlerExecutor handlerExecutor)` Create a TCP server with provided selector loops pool.
`NioTcpServer(SelectorLoop acceptSelectorLoop, SelectorLoopPool readWriteSelectorLoop, IoHandlerExecutor handlerExecutor)` Create a TCP server with provided selector loops pool
`NioTcpServer(TcpSessionConfig config)` Create a TCP server with new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)
`NioTcpServer(TcpSessionConfig config, SelectorLoopPool selectorLoopPool, IoHandlerExecutor handlerExecutor)` Create a TCP server with provided selector loops pool.
`NioTcpServer(TcpSessionConfig config, SelectorLoop acceptSelectorLoop, SelectorLoopPool readWriteSelectorLoop, IoHandlerExecutor handlerExecutor)` Create a TCP server with provided selector loops pool

### Method Summary

Methods
`void` `bind(int port)` Binds the server to the specified port.
`void` `bind(SocketAddress localAddress)` Binds to the specified local addresses and start to accept incoming connections.
`SelectionKey` `getAcceptKey()`
`SocketAddress` `getBoundAddress()` Returns the local addresses which are bound currently.
`ServerSocketChannel` `getServerSocketChannel()` Get the inner Server socket for accepting new client connections
`void` `ready(boolean accept, boolean connect, boolean read, ByteBuffer readBuffer, boolean write)`
`void` `setAcceptKey(SelectionKey acceptKey)`
`void` `setServerSocketChannel(ServerSocketChannel serverChannel)`
`void` `unbind()` Unbinds from the local addresses that this service is bound to and stops to accept incoming connections.

### Methods inherited from class org.apache.mina.transport.tcp.AbstractTcpServer

`getSessionConfig, setSessionConfig`

### Methods inherited from class org.apache.mina.service.server.AbstractIoServer

`isReuseAddress, setReuseAddress, setSessionConfig`

### Methods inherited from class org.apache.mina.service.AbstractIoService

`fireServiceActivated, fireServiceInactivated, getFilters, getIoHandler, getIoHandlerExecutor, getManagedSessions, initState, isActive, isCreated, isDisposed, isDisposing, isSuspended, setActive, setCreated, setDisposed, setDisposing, setFilters, setIoHandler, setSuspended`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### NioTcpServer

    public NioTcpServer()

Create a TCP server with new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)

#### NioTcpServer

    public NioTcpServer(TcpSessionConfig config)

Create a TCP server with new selector pool of default size and a `IoHandlerExecutor` of default type ( `OrderedHandlerExecutor`)

Parameters:
  `config` - The specific configuration to use

#### NioTcpServer

    public NioTcpServer(SelectorLoopPool selectorLoopPool,
                IoHandlerExecutor handlerExecutor)

Create a TCP server with provided selector loops pool. We will use one SelectorLoop get from the pool to manage the OP_ACCEPT events. If the pool contains only one SelectorLoop, then all the events will be managed by the same Selector.

Parameters:
  `selectorLoopPool` - the selector loop pool for handling all I/O events (accept, read, write)
  `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

#### NioTcpServer

    public NioTcpServer(TcpSessionConfig config,
                SelectorLoopPool selectorLoopPool,
                IoHandlerExecutor handlerExecutor)

Create a TCP server with provided selector loops pool. We will use one SelectorLoop get from the pool to manage the OP_ACCEPT events. If the pool contains only one SelectorLoop, then all the events will be managed by the same Selector.

Parameters:
  `config` - The specific configuration to use
  `selectorLoopPool` - the selector loop pool for handling all I/O events (accept, read, write)
  `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

#### NioTcpServer

    public NioTcpServer(SelectorLoop acceptSelectorLoop,
                SelectorLoopPool readWriteSelectorLoop,
                IoHandlerExecutor handlerExecutor)

Create a TCP server with provided selector loops pool

Parameters:
  `acceptSelectorLoop` - the selector loop for handling accept events (connection of new session)
  `readWriteSelectorLoop` - the pool of selector loop for handling read/write events of connected sessions
  `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

#### NioTcpServer

    public NioTcpServer(TcpSessionConfig config,
                SelectorLoop acceptSelectorLoop,
                SelectorLoopPool readWriteSelectorLoop,
                IoHandlerExecutor handlerExecutor)

Create a TCP server with provided selector loops pool

Parameters:
  `config` - The specific configuration to use
  `acceptSelectorLoop` - the selector loop for handling accept events (connection of new session)
  `readWriteSelectorLoop` - the pool of selector loop for handling read/write events of connected sessions
  `ioHandlerExecutor` - used for executing IoHandler event in another pool of thread (not in the low level I/O one). Use `null` if you don't want one. Be careful, the IoHandler processing will block the I/O operations.

### Method Detail

#### getServerSocketChannel

    public ServerSocketChannel getServerSocketChannel()

Get the inner Server socket for accepting new client connections

Returns:

#### setServerSocketChannel

    public void setServerSocketChannel(ServerSocketChannel serverChannel)

#### bind

    public void bind(int port)

Binds the server to the specified port.

Specified by:
  `bind` in interface `IoServer`
Parameters:
  `port` - the local TCP port to bind.

#### bind

    public void bind(SocketAddress localAddress)

Binds to the specified local addresses and start to accept incoming connections.

Specified by:
  `bind` in interface `IoServer`

#### getBoundAddress

    public SocketAddress getBoundAddress()

Returns the local addresses which are bound currently.

Specified by:
  `getBoundAddress` in interface `IoServer`

#### unbind

    public void unbind()

Unbinds from the local addresses that this service is bound to and stops to accept incoming connections. This method returns silently if no local address is bound yet.

Specified by:
  `unbind` in interface `IoServer`

#### getAcceptKey

    public SelectionKey getAcceptKey()

Returns:
  the acceptKey

#### setAcceptKey

    public void setAcceptKey(SelectionKey acceptKey)

Parameters:
  `acceptKey` - the acceptKey to set

#### ready

    public void ready(boolean accept,
             boolean connect,
             boolean read,
             ByteBuffer readBuffer,
             boolean write)

Specified by:
  `ready` in interface `SelectorListener`