org.apache.ignite.internal.util.nio

## Class GridNioServer<T>

- java.lang.Object
- - org.apache.ignite.internal.util.nio.GridNioServer<T>

Type Parameters:
  `T` - Message type.

    public class GridNioServer<T>
    extends Object

TCP NIO server. Due to asynchronous nature of connections processing network events such as client connection, disconnection and message receiving are passed to the server listener. Once client connected, an associated `GridNioSession` object is created and can be used in communication.

This implementation supports several selectors and several reading threads.

### Nested Class Summary

Nested Classes
`static class` `GridNioServer.Builder<T>` Constructs a new instance of `GridNioServer`.

### Field Summary

Fields
`static int` `DFLT_SEND_QUEUE_LIMIT` Default send queue limit.
`static int` `DFLT_SES_WRITE_TIMEOUT` Default session write timeout.

### Method Summary

Methods
`static <T> GridNioServer.Builder<T>` `builder()` Creates and returns a builder for a new instance of this class.
`GridNioFuture<Boolean>` `close(GridNioSession ses)`
`GridNioFuture<GridNioSession>` `createSession(SocketChannel ch, Map<Integer,?> meta)` Establishes a session.
`long` `idleTimeout()` Gets configurable idle timeout for this session.
`void` `idleTimeout(long idleTimeout)` Sets configurable idle timeout for session.
`InetSocketAddress` `localAddress()` Gets the address server is bound to.
`int` `outboundMessagesQueueSize()` Gets outbound messages queue size.
`void` `resend(GridNioSession ses)`
`GridNioFuture<?>` `sendSystem(GridNioSession ses, Message msg)` Adds message at the front of the queue without acquiring back pressure semaphore.
`GridNioFuture<?>` `sendSystem(GridNioSession ses, Message msg, IgniteInClosure<? super IgniteInternalFuture<?>> lsnr)` Adds message at the front of the queue without acquiring back pressure semaphore.
`void` `start()` Starts all associated threads to perform accept and read activities.
`void` `stop()` Stops all threads and releases all resources.
`String` `toString()`
`long` `writeTimeout()` Gets configurable write timeout for this session.
`void` `writeTimeout(long writeTimeout)` Sets configurable write timeout for session.

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

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

### Field Detail

#### DFLT_SES_WRITE_TIMEOUT

    public static final int DFLT_SES_WRITE_TIMEOUT

Default session write timeout.

See Also:
  Constant Field Values

#### DFLT_SEND_QUEUE_LIMIT

    public static final int DFLT_SEND_QUEUE_LIMIT

Default send queue limit.

See Also:
  Constant Field Values

### Method Detail

#### builder

    public static <T> GridNioServer.Builder<T> builder()

Creates and returns a builder for a new instance of this class.

Returns:
  Builder for new instance.

#### start

    public void start()

Starts all associated threads to perform accept and read activities.

#### stop

    public void stop()

Stops all threads and releases all resources.

#### localAddress

    public InetSocketAddress localAddress()

Gets the address server is bound to.

Returns:
  Address server is bound to.

#### close

    public GridNioFuture<Boolean> close(GridNioSession ses)

Parameters:
  `ses` - Session to close.
Returns:
  Future for operation.

#### sendSystem

    public GridNioFuture<?> sendSystem(GridNioSession ses,
                              Message msg)

Adds message at the front of the queue without acquiring back pressure semaphore.

Parameters:
  `ses` - Session.
  `msg` - Message.
Returns:
  Future.

#### sendSystem

    public GridNioFuture<?> sendSystem(GridNioSession ses,
                              Message msg,
                              @Nullable
                              IgniteInClosure<? super IgniteInternalFuture<?>> lsnr)

Adds message at the front of the queue without acquiring back pressure semaphore.

Parameters:
  `ses` - Session.
  `msg` - Message.
  `lsnr` - Future listener notified from the session thread.
Returns:
  Future.

#### resend

    public void resend(GridNioSession ses)

Parameters:
  `ses` - Session.

#### createSession

    public GridNioFuture<GridNioSession> createSession(SocketChannel ch,
                                              @Nullable
                                              Map<Integer,?> meta)

Establishes a session.

Parameters:
  `ch` - Channel to register within the server and create session for.
  `meta` - Optional meta for new session.
Returns:
  Future to get session.

#### writeTimeout

    public long writeTimeout()

Gets configurable write timeout for this session. If not set, default value is `DFLT_SES_WRITE_TIMEOUT`.

Returns:
  Write timeout in milliseconds.

#### writeTimeout

    public void writeTimeout(long writeTimeout)

Sets configurable write timeout for session.

Parameters:
  `writeTimeout` - Write timeout in milliseconds.

#### idleTimeout

    public long idleTimeout()

Gets configurable idle timeout for this session. If not set, default value is `ConnectorConfiguration.DFLT_IDLE_TIMEOUT`.

Returns:
  Idle timeout in milliseconds.

#### idleTimeout

    public void idleTimeout(long idleTimeout)

Sets configurable idle timeout for session.

Parameters:
  `idleTimeout` - Idle timeout in milliseconds.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### outboundMessagesQueueSize

    public int outboundMessagesQueueSize()

Gets outbound messages queue size.

Returns:
  Write queue size.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0-b1
Release Date | : December 1 2015