org.apache.ignite.spi.communication.tcp

## Class TcpCommunicationSpi

- java.lang.Object
- - org.apache.ignite.spi.IgniteSpiAdapter
  - - org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi

All Implemented Interfaces:
  CommunicationSpi<MessageAdapter>, TcpCommunicationSpiMBean, IgniteSpi, IgniteSpiManagementMBean

    @IgniteSpiMultipleInstancesSupport(value=true)
    @IgniteSpiConsistencyChecked(optional=false)
    public class TcpCommunicationSpi
    extends IgniteSpiAdapter
    implements CommunicationSpi<MessageAdapter>, TcpCommunicationSpiMBean

`GridTcpCommunicationSpi` is default communication SPI which uses TCP/IP protocol and Java NIO to communicate with other nodes.

To enable communication with other nodes, this SPI adds `ATTR_ADDRS` and `ATTR_PORT` local node attributes (see `ClusterNode.attributes()`.

At startup, this SPI tries to start listening to local port specified by `setLocalPort(int)` method. If local port is occupied, then SPI will automatically increment the port number until it can successfully bind for listening. `setLocalPortRange(int)` configuration parameter controls maximum number of ports that SPI will try before it fails. Port range comes very handy when starting multiple grid nodes on the same machine or even in the same VM. In this case all nodes can be brought up without a single change in configuration.

This SPI caches connections to remote nodes so it does not have to reconnect every time a message is sent. By default, idle connections are kept active for `DFLT_IDLE_CONN_TIMEOUT` period and then are closed. Use `setIdleConnectionTimeout(long)` configuration parameter to configure you own idle connection timeout.

# Configuration

## Mandatory

This SPI has no mandatory configuration parameters.

## Optional

The following configuration parameters are optional:

- Node local IP address (see `setLocalAddress(String)`)
- Node local port number (see `setLocalPort(int)`)
- Local port range (see `setLocalPortRange(int)`
- Connection buffer flush frequency (see `setConnectionBufferFlushFrequency(long)`)
- Connection buffer size (see `setConnectionBufferSize(int)`)
- Idle connection timeout (see `setIdleConnectionTimeout(long)`)
- Direct or heap buffer allocation (see `setDirectBuffer(boolean)`)
- Direct or heap buffer allocation for sending (see `setDirectSendBuffer(boolean)`)
- Count of selectors and selector threads for NIO server (see `setSelectorsCount(int)`)
- `TCP_NODELAY` socket option for sockets (see `setTcpNoDelay(boolean)`)
- Message queue limit (see `setMessageQueueLimit(int)`)
- Minimum buffered message count (see `setMinimumBufferedMessageCount(int)`)
- Buffer size ratio (see `setBufferSizeRatio(double)`)
- Connect timeout (see `setConnectTimeout(long)`)
- Maximum connect timeout (see `setMaxConnectTimeout(long)`)
- Reconnect attempts count (see `setReconnectCount(int)`)
- Local port to accept shared memory connections (see `setSharedMemoryPort(int)`)
- Socket receive buffer size (see `setSocketReceiveBuffer(int)`)
- Socket send buffer size (see `setSocketSendBuffer(int)`)
- Socket write timeout (see `setSocketWriteTimeout(long)`)
- Number of received messages after which acknowledgment is sent (see `setAckSendThreshold(int)`)
- Maximum number of unacknowledged messages (see `setUnacknowledgedMessagesBufferSize(int)`)

## Java Example

GridTcpCommunicationSpi is used by default and should be explicitly configured only if some SPI configuration parameters need to be overridden.

     GridTcpCommunicationSpi commSpi = new GridTcpCommunicationSpi();

     // Override local port.
     commSpi.setLocalPort(4321);

     GridConfiguration cfg = new GridConfiguration();

     // Override default communication SPI.
     cfg.setCommunicationSpi(commSpi);

     // Start grid.
     Ignition.start(cfg);

## Spring Example

GridTcpCommunicationSpi can be configured from Spring XML configuration file:

     <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
             ...
             <property name="communicationSpi">
                 <bean class="org.apache.ignite.spi.communication.tcp.GridTcpCommunicationSpi">
                     <!-- Override local port. -->
                     <property name="localPort" value="4321"/>
                 </bean>
             </property>
             ...
     </bean>

For information about Spring framework visit www.springframework.org

See Also:
  `CommunicationSpi`

### Nested Class Summary

Nested Classes
`static class` `TcpCommunicationSpi.HandshakeMessage` Handshake message.
`static class` `TcpCommunicationSpi.NodeIdMessage` Node ID message.
`static class` `TcpCommunicationSpi.RecoveryLastReceivedMessage` Recovery acknowledgment message.

### Field Summary

Fields
`static String` `ATTR_ADDRS` Node attribute that is mapped to node IP addresses (value is `comm.tcp.addrs`).
`static String` `ATTR_EXT_ADDRS` Node attribute that is mapped to node's external addresses (value is `comm.tcp.ext-addrs`).
`static String` `ATTR_HOST_NAMES` Node attribute that is mapped to node host names (value is `comm.tcp.host.names`).
`static String` `ATTR_PORT` Node attribute that is mapped to node port number (value is `comm.tcp.port`).
`static String` `ATTR_SHMEM_PORT` Node attribute that is mapped to node port number (value is `comm.shmem.tcp.port`).
`static int` `DFLT_ACK_SND_THRESHOLD` Default received messages threshold for sending ack.
`static long` `DFLT_CONN_BUF_FLUSH_FREQ` Default value for connection buffer flush frequency (value is `100` ms).
`static int` `DFLT_CONN_BUF_SIZE` Default value for connection buffer size (value is `0`).
`static long` `DFLT_CONN_TIMEOUT` Default connection timeout (value is `1000`ms).
`static long` `DFLT_IDLE_CONN_TIMEOUT` Default idle connection timeout (value is `30000`ms).
`static long` `DFLT_MAX_CONN_TIMEOUT` Default Maximum connection timeout (value is `600,000`ms).
`static int` `DFLT_MSG_QUEUE_LIMIT` Default message queue limit per connection (for incoming and outgoing .
`static int` `DFLT_PORT` Default port which node sets listener to (value is `47100`).
`static int` `DFLT_PORT_RANGE` Default local port range (value is `100`).
`static int` `DFLT_RECONNECT_CNT` Default reconnect attempts count (value is `10`).
`static int` `DFLT_SELECTORS_CNT` Default count of selectors for TCP server equals to `"Math.min(4, Runtime.getRuntime().availableProcessors())"`.
`static int` `DFLT_SHMEM_PORT` Default port which node sets listener for shared memory connections (value is `48100`).
`static int` `DFLT_SOCK_BUF_SIZE` Default socket send and receive buffer size.
`static long` `DFLT_SOCK_WRITE_TIMEOUT` Default socket write timeout.
`static boolean` `DFLT_TCP_NODELAY` Default value for `TCP_NODELAY` socket option (value is `true`).
`static byte` `HANDSHAKE_MSG_TYPE`
`static byte` `NODE_ID_MSG_TYPE` Node ID message type.
`static String` `OUT_OF_RESOURCES_TCP_MSG` IPC error message.
`static byte` `RECOVERY_LAST_ID_MSG_TYPE`

### Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter

`ignite`

### Constructor Summary

Constructors
Constructor and Description
`TcpCommunicationSpi()`

### Method Summary

Methods
`protected void` `checkConfigurationConsistency0(IgniteSpiContext spiCtx, ClusterNode node, boolean starting)` Method which is called in the end of checkConfigurationConsistency() method.
`protected GridCommunicationClient` `createNioClient(ClusterNode node)`
`protected GridCommunicationClient` `createShmemClient(ClusterNode node, Integer port)`
`protected GridCommunicationClient` `createTcpClient(ClusterNode node)` Establish TCP connection to remote node and returns client.
`int` `getAckSendThreshold()` Gets number of received messages per connection to node after which acknowledgment message is sent.
`AddressResolver` `getAddressResolver()` Gets address resolver.
`double` `getBufferSizeRatio()` Gets the buffer size ratio for this SPI.
`long` `getConnectionBufferFlushFrequency()` Gets connection buffer flush frequency.
`int` `getConnectionBufferSize()` Gets connection buffer size.
`long` `getConnectTimeout()` Gets connect timeout used when establishing connection with remote nodes.
`long` `getIdleConnectionTimeout()` Gets maximum idle connection time upon which idle connections will be closed.
`CommunicationListener` `getListener()`
`String` `getLocalAddress()` Gets local host address for socket binding.
`int` `getLocalPort()` Gets local port for socket binding.
`int` `getLocalPortRange()` Gets maximum number of local ports tried if all previously tried ports are occupied.
`long` `getMaxConnectTimeout()` Gets maximum connect timeout.
`int` `getMessageQueueLimit()` Gets message queue limit for incoming and outgoing messages.
`int` `getMinimumBufferedMessageCount()` Gets the minimum number of messages for this SPI, that are buffered prior to sending.
`Map<String,Object>` `getNodeAttributes()` This method is called before SPI starts (before method `IgniteSpi.spiStart(String)` is called).
`int` `getOutboundMessagesQueueSize()` Gets outbound messages queue size.
`long` `getReceivedBytesCount()` Gets received bytes count.
`int` `getReceivedMessagesCount()` Gets received messages count.
`int` `getReconnectCount()` Gets maximum number of reconnect attempts used when establishing connection with remote nodes.
`int` `getSelectorsCount()` Gets count of selectors used in TCP server.
`long` `getSentBytesCount()` Gets sent bytes count.
`int` `getSentMessagesCount()` Gets sent messages count.
`int` `getSharedMemoryPort()` Gets local port for shared memory communication.
`int` `getSocketReceiveBuffer()` Gets receive buffer size for sockets created or accepted by this SPI.
`int` `getSocketSendBuffer()` Gets send buffer size for sockets created or accepted by this SPI.
`long` `getSocketWriteTimeout()` Gets socket write timeout for TCP connections.
`IgniteSpiContext` `getSpiContext()` Gets SPI context.
`int` `getUnacknowledgedMessagesBufferSize()` Gets maximum number of stored unacknowledged messages per connection to node.
`protected void` `injectResources(Ignite ignite)` Injects resources.
`boolean` `isDirectBuffer()` Gets flag that indicates whether direct or heap allocated buffer is used.
`boolean` `isDirectSendBuffer()` Gets flag defining whether direct send buffer should be used.
`boolean` `isTcpNoDelay()` Gets value for `TCP_NODELAY` socket option.
`protected void` `notifyListener(UUID sndId, MessageAdapter msg, IgniteRunnable msgC)`
`protected void` `onContextDestroyed0()` Method to be called in the beginning of onContextDestroyed() method.
`void` `onContextInitialized0(IgniteSpiContext spiCtx)` Method to be called in the end of onContextInitialized method.
`void` `resetMetrics()` Resets metrics for this SPI instance.
`void` `sendMessage(ClusterNode node, MessageAdapter msg)` Sends given message to destination node.
`void` `setAckSendThreshold(int ackSndThreshold)` Sets number of received messages per connection to node after which acknowledgment message is sent.
`void` `setAddressResolver(AddressResolver addrRslvr)` Sets address resolver.
`void` `setBufferSizeRatio(double bufSizeRatio)` Sets the buffer size ratio for this SPI.
`void` `setConnectionBufferFlushFrequency(long connBufFlushFreq)` Sets connection buffer flush frequency.
`void` `setConnectionBufferSize(int connBufSize)` Sets connection buffer size.
`void` `setConnectTimeout(long connTimeout)` Sets connect timeout used when establishing connection with remote nodes.
`void` `setDirectBuffer(boolean directBuf)` Sets flag to allocate direct or heap buffer in SPI.
`void` `setDirectSendBuffer(boolean directSndBuf)` Sets whether to use direct buffer for sending.
`void` `setIdleConnectionTimeout(long idleConnTimeout)` Sets maximum idle connection timeout upon which a connection to client will be closed.
`void` `setListener(CommunicationListener<MessageAdapter> lsnr)` Set communication listener.
`void` `setLocalAddress(String locAddr)` Sets local host address for socket binding.
`void` `setLocalPort(int locPort)` Sets local port for socket binding.
`void` `setLocalPortRange(int locPortRange)` Sets local port range for local host ports (value must greater than or equal to `0`).
`void` `setMaxConnectTimeout(long maxConnTimeout)` Sets maximum connect timeout.
`void` `setMessageQueueLimit(int msgQueueLimit)` Sets message queue limit for incoming and outgoing messages.
`void` `setMinimumBufferedMessageCount(int minBufferedMsgCnt)` Sets the minimum number of messages for this SPI, that are buffered prior to sending.
`void` `setReconnectCount(int reconCnt)` Sets maximum number of reconnect attempts used when establishing connection with remote nodes.
`void` `setSelectorsCount(int selectorsCnt)` Sets the count of selectors te be used in TCP server.
`void` `setSharedMemoryPort(int shmemPort)` Sets local port to accept shared memory connections.
`void` `setSocketReceiveBuffer(int sockRcvBuf)` Sets receive buffer size for sockets created or accepted by this SPI.
`void` `setSocketSendBuffer(int sockSndBuf)` Sets send buffer size for sockets created or accepted by this SPI.
`void` `setSocketWriteTimeout(long sockWriteTimeout)` Sets socket write timeout for TCP connection.
`void` `setTcpNoDelay(boolean tcpNoDelay)` Sets value for `TCP_NODELAY` socket option.
`void` `setUnacknowledgedMessagesBufferSize(int unackedMsgsBufSize)` Sets maximum number of stored unacknowledged messages per connection to node.
`void` `spiStart(String gridName)` This method is called to start SPI.
`void` `spiStop()` This method is called to stop SPI.
`String` `toString()`

### Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter

`assertParameter, configInfo, createSpiAttributeName, getConsistentAttributeNames, getIgniteHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, injectables, onContextDestroyed, onContextInitialized, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBean`

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

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

### Methods inherited from interface org.apache.ignite.spi.IgniteSpi

`getName, onContextDestroyed, onContextInitialized`

### Methods inherited from interface org.apache.ignite.spi.IgniteSpiManagementMBean

`getIgniteHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted`

### Field Detail

#### OUT_OF_RESOURCES_TCP_MSG

    public static final String OUT_OF_RESOURCES_TCP_MSG

IPC error message.

See Also:
  Constant Field Values

#### ATTR_ADDRS

    public static final String ATTR_ADDRS

Node attribute that is mapped to node IP addresses (value is `comm.tcp.addrs`).

See Also:
  Constant Field Values

#### ATTR_HOST_NAMES

    public static final String ATTR_HOST_NAMES

Node attribute that is mapped to node host names (value is `comm.tcp.host.names`).

See Also:
  Constant Field Values

#### ATTR_PORT

    public static final String ATTR_PORT

Node attribute that is mapped to node port number (value is `comm.tcp.port`).

See Also:
  Constant Field Values

#### ATTR_SHMEM_PORT

    public static final String ATTR_SHMEM_PORT

Node attribute that is mapped to node port number (value is `comm.shmem.tcp.port`).

See Also:
  Constant Field Values

#### ATTR_EXT_ADDRS

    public static final String ATTR_EXT_ADDRS

Node attribute that is mapped to node's external addresses (value is `comm.tcp.ext-addrs`).

See Also:
  Constant Field Values

#### DFLT_PORT

    public static final int DFLT_PORT

Default port which node sets listener to (value is `47100`).

See Also:
  Constant Field Values

#### DFLT_SHMEM_PORT

    public static final int DFLT_SHMEM_PORT

Default port which node sets listener for shared memory connections (value is `48100`).

See Also:
  Constant Field Values

#### DFLT_IDLE_CONN_TIMEOUT

    public static final long DFLT_IDLE_CONN_TIMEOUT

Default idle connection timeout (value is `30000`ms).

See Also:
  Constant Field Values

#### DFLT_CONN_BUF_FLUSH_FREQ

    public static final long DFLT_CONN_BUF_FLUSH_FREQ

Default value for connection buffer flush frequency (value is `100` ms).

See Also:
  Constant Field Values

#### DFLT_CONN_BUF_SIZE

    public static final int DFLT_CONN_BUF_SIZE

Default value for connection buffer size (value is `0`).

See Also:
  Constant Field Values

#### DFLT_SOCK_BUF_SIZE

    public static final int DFLT_SOCK_BUF_SIZE

Default socket send and receive buffer size.

See Also:
  Constant Field Values

#### DFLT_CONN_TIMEOUT

    public static final long DFLT_CONN_TIMEOUT

Default connection timeout (value is `1000`ms).

See Also:
  Constant Field Values

#### DFLT_MAX_CONN_TIMEOUT

    public static final long DFLT_MAX_CONN_TIMEOUT

Default Maximum connection timeout (value is `600,000`ms).

See Also:
  Constant Field Values

#### DFLT_RECONNECT_CNT

    public static final int DFLT_RECONNECT_CNT

Default reconnect attempts count (value is `10`).

See Also:
  Constant Field Values

#### DFLT_MSG_QUEUE_LIMIT

    public static final int DFLT_MSG_QUEUE_LIMIT

Default message queue limit per connection (for incoming and outgoing .

See Also:
  Constant Field Values

#### DFLT_SELECTORS_CNT

    public static final int DFLT_SELECTORS_CNT

Default count of selectors for TCP server equals to `"Math.min(4, Runtime.getRuntime().availableProcessors())"`.

#### DFLT_PORT_RANGE

    public static final int DFLT_PORT_RANGE

Default local port range (value is `100`). See `setLocalPortRange(int)` for details.

See Also:
  Constant Field Values

#### DFLT_TCP_NODELAY

    public static final boolean DFLT_TCP_NODELAY

Default value for `TCP_NODELAY` socket option (value is `true`).

See Also:
  Constant Field Values

#### DFLT_ACK_SND_THRESHOLD

    public static final int DFLT_ACK_SND_THRESHOLD

Default received messages threshold for sending ack.

See Also:
  Constant Field Values

#### DFLT_SOCK_WRITE_TIMEOUT

    public static final long DFLT_SOCK_WRITE_TIMEOUT

Default socket write timeout.

See Also:
  Constant Field Values

#### NODE_ID_MSG_TYPE

    public static final byte NODE_ID_MSG_TYPE

Node ID message type.

See Also:
  Constant Field Values

#### RECOVERY_LAST_ID_MSG_TYPE

    public static final byte RECOVERY_LAST_ID_MSG_TYPE

See Also:
  Constant Field Values

#### HANDSHAKE_MSG_TYPE

    public static final byte HANDSHAKE_MSG_TYPE

See Also:
  Constant Field Values

### Constructor Detail

#### TcpCommunicationSpi

    public TcpCommunicationSpi()

### Method Detail

#### setAddressResolver

    @IgniteSpiConfiguration(optional=true)
    public void setAddressResolver(AddressResolver addrRslvr)

Sets address resolver.

Parameters:
  `addrRslvr` - Address resolver.

#### injectResources

    @IgniteInstanceResource
    protected void injectResources(Ignite ignite)

Injects resources.

Parameters:
  `ignite` - Ignite.

#### getAddressResolver

    public AddressResolver getAddressResolver()

Gets address resolver.

Returns:
  Address resolver.

#### setLocalAddress

    @IgniteSpiConfiguration(optional=true)
    public void setLocalAddress(String locAddr)

Sets local host address for socket binding. Note that one node could have additional addresses beside the loopback one. This configuration parameter is optional.

Parameters:
  `locAddr` - IP address. Default value is any available local IP address.

#### getLocalAddress

    public String getLocalAddress()

Gets local host address for socket binding. Beside loopback address physical node could have several other ones, but only one is assigned to grid node.

Specified by:
  `getLocalAddress` in interface `TcpCommunicationSpiMBean`
Returns:
  Grid node IP address.

#### setLocalPort

    @IgniteSpiConfiguration(optional=true)
    public void setLocalPort(int locPort)

Sets local port for socket binding.

If not provided, default value is `DFLT_PORT`.

Parameters:
  `locPort` - Port number.

#### getLocalPort

    public int getLocalPort()

Gets local port for socket binding.

Specified by:
  `getLocalPort` in interface `TcpCommunicationSpiMBean`
Returns:
  Port number.

#### setLocalPortRange

    @IgniteSpiConfiguration(optional=true)
    public void setLocalPortRange(int locPortRange)

Sets local port range for local host ports (value must greater than or equal to `0`). If provided local port (see `setLocalPort(int)`} is occupied, implementation will try to increment the port number for as long as it is less than initial value plus this range.

If port range value is `0`, then implementation will try bind only to the port provided by `setLocalPort(int)` method and fail if binding to this port did not succeed.

Local port range is very useful during development when more than one grid nodes need to run on the same physical machine.

If not provided, default value is `DFLT_PORT_RANGE`.

Parameters:
  `locPortRange` - New local port range.

#### getLocalPortRange

    public int getLocalPortRange()

Gets maximum number of local ports tried if all previously tried ports are occupied.

Specified by:
  `getLocalPortRange` in interface `TcpCommunicationSpiMBean`
Returns:
  Local port range.

#### setSharedMemoryPort

    @IgniteSpiConfiguration(optional=true)
    public void setSharedMemoryPort(int shmemPort)

Sets local port to accept shared memory connections.

If set to `-1` shared memory communication will be disabled.

If not provided, default value is `DFLT_SHMEM_PORT`.

Parameters:
  `shmemPort` - Port number.

#### getSharedMemoryPort

    public int getSharedMemoryPort()

Gets local port for shared memory communication.

Specified by:
  `getSharedMemoryPort` in interface `TcpCommunicationSpiMBean`
Returns:
  Port number.

#### setIdleConnectionTimeout

    @IgniteSpiConfiguration(optional=true)
    public void setIdleConnectionTimeout(long idleConnTimeout)

Sets maximum idle connection timeout upon which a connection to client will be closed.

If not provided, default value is `DFLT_IDLE_CONN_TIMEOUT`.

Parameters:
  `idleConnTimeout` - Maximum idle connection time.

#### getIdleConnectionTimeout

    public long getIdleConnectionTimeout()

Gets maximum idle connection time upon which idle connections will be closed.

Specified by:
  `getIdleConnectionTimeout` in interface `TcpCommunicationSpiMBean`
Returns:
  Maximum idle connection time.

#### getSocketWriteTimeout

    public long getSocketWriteTimeout()

Gets socket write timeout for TCP connections. If message can not be written to socket within this time then connection is closed and reconnect is attempted.

Specified by:
  `getSocketWriteTimeout` in interface `TcpCommunicationSpiMBean`
Returns:
  Socket write timeout for TCP connections.

#### setSocketWriteTimeout

    @IgniteSpiConfiguration(optional=true)
    public void setSocketWriteTimeout(long sockWriteTimeout)

Sets socket write timeout for TCP connection. If message can not be written to socket within this time then connection is closed and reconnect is attempted.

Default to `DFLT_SOCK_WRITE_TIMEOUT`.

Parameters:
  `sockWriteTimeout` - Socket write timeout for TCP connection.

#### getAckSendThreshold

    public int getAckSendThreshold()

Gets number of received messages per connection to node after which acknowledgment message is sent.

Specified by:
  `getAckSendThreshold` in interface `TcpCommunicationSpiMBean`
Returns:
  Number of received messages after which acknowledgment is sent.

#### setAckSendThreshold

    @IgniteSpiConfiguration(optional=true)
    public void setAckSendThreshold(int ackSndThreshold)

Sets number of received messages per connection to node after which acknowledgment message is sent.

Default to `DFLT_ACK_SND_THRESHOLD`.

Parameters:
  `ackSndThreshold` - Number of received messages after which acknowledgment is sent.

#### getUnacknowledgedMessagesBufferSize

    public int getUnacknowledgedMessagesBufferSize()

Gets maximum number of stored unacknowledged messages per connection to node. If number of unacknowledged messages exceeds this number then connection to node is closed and reconnect is attempted.

Specified by:
  `getUnacknowledgedMessagesBufferSize` in interface `TcpCommunicationSpiMBean`
Returns:
  Maximum number of unacknowledged messages.

#### setUnacknowledgedMessagesBufferSize

    @IgniteSpiConfiguration(optional=true)
    public void setUnacknowledgedMessagesBufferSize(int unackedMsgsBufSize)

Sets maximum number of stored unacknowledged messages per connection to node. If number of unacknowledged messages exceeds this number then connection to node is closed and reconnect is attempted.

Parameters:
  `unackedMsgsBufSize` - Maximum number of unacknowledged messages.

#### setConnectionBufferSize

    @IgniteSpiConfiguration(optional=true)
    public void setConnectionBufferSize(int connBufSize)

Sets connection buffer size. If set to `0` connection buffer is disabled.

If not provided, default value is `DFLT_CONN_BUF_SIZE`.

Parameters:
  `connBufSize` - Connection buffer size.
See Also:
  `setConnectionBufferFlushFrequency(long)`

#### getConnectionBufferSize

    public int getConnectionBufferSize()

Gets connection buffer size.

If set to `0` connection buffer is disabled.

Specified by:
  `getConnectionBufferSize` in interface `TcpCommunicationSpiMBean`
Returns:
  Connection buffer size.

#### setConnectionBufferFlushFrequency

    @IgniteSpiConfiguration(optional=true)
    public void setConnectionBufferFlushFrequency(long connBufFlushFreq)

Sets connection buffer flush frequency.

Client connections to other nodes in topology use buffered output. This frequency defines how often system will advice to flush connection buffer.

If not provided, default value is `DFLT_CONN_BUF_FLUSH_FREQ`.

This property is used only if `TcpCommunicationSpiMBean.getConnectionBufferSize()` is greater than `0`.

Specified by:
  `setConnectionBufferFlushFrequency` in interface `TcpCommunicationSpiMBean`
Parameters:
  `connBufFlushFreq` - Flush frequency.
See Also:
  `TcpCommunicationSpiMBean.getConnectionBufferSize()`

#### getConnectionBufferFlushFrequency

    public long getConnectionBufferFlushFrequency()

Gets connection buffer flush frequency.

Client connections to other nodes in topology use buffered output. This frequency defines how often system will advice to flush connection buffer.

Specified by:
  `getConnectionBufferFlushFrequency` in interface `TcpCommunicationSpiMBean`
Returns:
  Flush frequency.

#### setConnectTimeout

    @IgniteSpiConfiguration(optional=true)
    public void setConnectTimeout(long connTimeout)

Sets connect timeout used when establishing connection with remote nodes.

`0` is interpreted as infinite timeout.

If not provided, default value is `DFLT_CONN_TIMEOUT`.

Parameters:
  `connTimeout` - Connect timeout.

#### getConnectTimeout

    public long getConnectTimeout()

Gets connect timeout used when establishing connection with remote nodes.

Specified by:
  `getConnectTimeout` in interface `TcpCommunicationSpiMBean`
Returns:
  Connect timeout.

#### setMaxConnectTimeout

    @IgniteSpiConfiguration(optional=true)
    public void setMaxConnectTimeout(long maxConnTimeout)

Sets maximum connect timeout. If handshake is not established within connect timeout, then SPI tries to repeat handshake procedure with increased connect timeout. Connect timeout can grow till maximum timeout value, if maximum timeout value is reached then the handshake is considered as failed.

`0` is interpreted as infinite timeout.

If not provided, default value is `DFLT_MAX_CONN_TIMEOUT`.

Parameters:
  `maxConnTimeout` - Maximum connect timeout.

#### getMaxConnectTimeout

    public long getMaxConnectTimeout()

Gets maximum connect timeout.

Specified by:
  `getMaxConnectTimeout` in interface `TcpCommunicationSpiMBean`
Returns:
  Maximum connect timeout.

#### setReconnectCount

    @IgniteSpiConfiguration(optional=true)
    public void setReconnectCount(int reconCnt)

Sets maximum number of reconnect attempts used when establishing connection with remote nodes.

If not provided, default value is `DFLT_RECONNECT_CNT`.

Parameters:
  `reconCnt` - Maximum number of reconnection attempts.

#### getReconnectCount

    public int getReconnectCount()

Gets maximum number of reconnect attempts used when establishing connection with remote nodes.

Specified by:
  `getReconnectCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Reconnects count.

#### setDirectBuffer

    @IgniteSpiConfiguration(optional=true)
    public void setDirectBuffer(boolean directBuf)

Sets flag to allocate direct or heap buffer in SPI. If value is `true`, then SPI will use `ByteBuffer.allocateDirect(int)` call. Otherwise, SPI will use `ByteBuffer.allocate(int)` call.

If not provided, default value is `true`.

Parameters:
  `directBuf` - Flag indicates to allocate direct or heap buffer in SPI.

#### isDirectBuffer

    public boolean isDirectBuffer()

Gets flag that indicates whether direct or heap allocated buffer is used.

Specified by:
  `isDirectBuffer` in interface `TcpCommunicationSpiMBean`
Returns:
  Flag that indicates whether direct or heap allocated buffer is used.

#### isDirectSendBuffer

    public boolean isDirectSendBuffer()

Gets flag defining whether direct send buffer should be used.

Specified by:
  `isDirectSendBuffer` in interface `TcpCommunicationSpiMBean`
Returns:
  `True` if direct buffers should be used.

#### setDirectSendBuffer

    @IgniteSpiConfiguration(optional=true)
    public void setDirectSendBuffer(boolean directSndBuf)

Sets whether to use direct buffer for sending.

If not provided default is `false`.

Parameters:
  `directSndBuf` - `True` to use direct buffers for send.

#### setSelectorsCount

    @IgniteSpiConfiguration(optional=true)
    public void setSelectorsCount(int selectorsCnt)

Sets the count of selectors te be used in TCP server.

If not provided, default value is `DFLT_SELECTORS_CNT`.

Parameters:
  `selectorsCnt` - Selectors count.

#### getSelectorsCount

    public int getSelectorsCount()

Gets count of selectors used in TCP server. Default value equals to the number of CPUs available in the system.

Specified by:
  `getSelectorsCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Count of selectors in TCP server.

#### setTcpNoDelay

    @IgniteSpiConfiguration(optional=true)
    public void setTcpNoDelay(boolean tcpNoDelay)

Sets value for `TCP_NODELAY` socket option. Each socket will be opened using provided value.

Setting this option to `true` disables Nagle's algorithm for socket decreasing latency and delivery time for small messages.

For systems that work under heavy network load it is advisable to set this value to `false`.

If not provided, default value is `DFLT_TCP_NODELAY`.

Parameters:
  `tcpNoDelay` - `True` to disable TCP delay.

#### isTcpNoDelay

    public boolean isTcpNoDelay()

Gets value for `TCP_NODELAY` socket option.

Specified by:
  `isTcpNoDelay` in interface `TcpCommunicationSpiMBean`
Returns:
  `True` if TCP delay is disabled.

#### setSocketReceiveBuffer

    @IgniteSpiConfiguration(optional=true)
    public void setSocketReceiveBuffer(int sockRcvBuf)

Sets receive buffer size for sockets created or accepted by this SPI.

If not provided, default is `DFLT_SOCK_BUF_SIZE`.

Parameters:
  `sockRcvBuf` - Socket receive buffer size.

#### getSocketReceiveBuffer

    public int getSocketReceiveBuffer()

Gets receive buffer size for sockets created or accepted by this SPI.

If not provided, default is `DFLT_SOCK_BUF_SIZE`.

Specified by:
  `getSocketReceiveBuffer` in interface `TcpCommunicationSpiMBean`
Returns:
  Socket receive buffer size.

#### setSocketSendBuffer

    @IgniteSpiConfiguration(optional=true)
    public void setSocketSendBuffer(int sockSndBuf)

Sets send buffer size for sockets created or accepted by this SPI.

If not provided, default is `DFLT_SOCK_BUF_SIZE`.

Parameters:
  `sockSndBuf` - Socket send buffer size.

#### getSocketSendBuffer

    public int getSocketSendBuffer()

Gets send buffer size for sockets created or accepted by this SPI.

If not provided, default is `DFLT_SOCK_BUF_SIZE`.

Specified by:
  `getSocketSendBuffer` in interface `TcpCommunicationSpiMBean`
Returns:
  Socket send buffer size.

#### setMessageQueueLimit

    @IgniteSpiConfiguration(optional=true)
    public void setMessageQueueLimit(int msgQueueLimit)

Sets message queue limit for incoming and outgoing messages.

When set to positive number send queue is limited to the configured value. `0` disables the size limitations.

If not provided, default is `DFLT_MSG_QUEUE_LIMIT`.

Parameters:
  `msgQueueLimit` - Send queue size limit.

#### getMessageQueueLimit

    public int getMessageQueueLimit()

Gets message queue limit for incoming and outgoing messages.

Specified by:
  `getMessageQueueLimit` in interface `TcpCommunicationSpiMBean`
Returns:
  Send queue size limit.

#### setMinimumBufferedMessageCount

    @IgniteSpiConfiguration(optional=true)
    public void setMinimumBufferedMessageCount(int minBufferedMsgCnt)

Sets the minimum number of messages for this SPI, that are buffered prior to sending.

Defaults to either `512` or `IgniteSystemProperties.IGNITE_MIN_BUFFERED_COMMUNICATION_MSG_CNT` system property (if specified).

Parameters:
  `minBufferedMsgCnt` - Minimum buffered message count.

#### getMinimumBufferedMessageCount

    public int getMinimumBufferedMessageCount()

Gets the minimum number of messages for this SPI, that are buffered prior to sending.

Specified by:
  `getMinimumBufferedMessageCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Minimum buffered message count.

#### setBufferSizeRatio

    @IgniteSpiConfiguration(optional=true)
    public void setBufferSizeRatio(double bufSizeRatio)

Sets the buffer size ratio for this SPI. As messages are sent, the buffer size is adjusted using this ratio.

Defaults to either `0.8` or `IgniteSystemProperties.IGNITE_COMMUNICATION_BUF_RESIZE_RATIO` system property (if specified).

Parameters:
  `bufSizeRatio` - Buffer size ratio.

#### getBufferSizeRatio

    public double getBufferSizeRatio()

Gets the buffer size ratio for this SPI. As messages are sent, the buffer size is adjusted using this ratio.

Specified by:
  `getBufferSizeRatio` in interface `TcpCommunicationSpiMBean`
Returns:
  Buffer size ratio.

#### setListener

    public void setListener(CommunicationListener<MessageAdapter> lsnr)

Set communication listener.

Specified by:
  `setListener` in interface `CommunicationSpi<MessageAdapter>`
Parameters:
  `lsnr` - Listener to set or `null` to unset the listener.

#### getListener

    public CommunicationListener getListener()

Returns:
  Listener.

#### getSentMessagesCount

    public int getSentMessagesCount()

Gets sent messages count.

Specified by:
  `getSentMessagesCount` in interface `CommunicationSpi<MessageAdapter>`
Specified by:
  `getSentMessagesCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Sent messages count.

#### getSentBytesCount

    public long getSentBytesCount()

Gets sent bytes count.

Specified by:
  `getSentBytesCount` in interface `CommunicationSpi<MessageAdapter>`
Specified by:
  `getSentBytesCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Sent bytes count.

#### getReceivedMessagesCount

    public int getReceivedMessagesCount()

Gets received messages count.

Specified by:
  `getReceivedMessagesCount` in interface `CommunicationSpi<MessageAdapter>`
Specified by:
  `getReceivedMessagesCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Received messages count.

#### getReceivedBytesCount

    public long getReceivedBytesCount()

Gets received bytes count.

Specified by:
  `getReceivedBytesCount` in interface `CommunicationSpi<MessageAdapter>`
Specified by:
  `getReceivedBytesCount` in interface `TcpCommunicationSpiMBean`
Returns:
  Received bytes count.

#### getOutboundMessagesQueueSize

    public int getOutboundMessagesQueueSize()

Gets outbound messages queue size.

Specified by:
  `getOutboundMessagesQueueSize` in interface `CommunicationSpi<MessageAdapter>`
Specified by:
  `getOutboundMessagesQueueSize` in interface `TcpCommunicationSpiMBean`
Returns:
  Outbound messages queue size.

#### resetMetrics

    public void resetMetrics()

Resets metrics for this SPI instance.

Specified by:
  `resetMetrics` in interface `CommunicationSpi<MessageAdapter>`

#### getNodeAttributes

    public Map<String,Object> getNodeAttributes()
                                         throws IgniteSpiException

This method is called before SPI starts (before method `IgniteSpi.spiStart(String)` is called). It allows SPI implementation to add attributes to a local node. Kernal collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.

Specified by:
  `getNodeAttributes` in interface `IgniteSpi`
Overrides:
  `getNodeAttributes` in class `IgniteSpiAdapter`
Returns:
  Map of local node attributes this SPI wants to add.
Throws:
  `IgniteSpiException` - Throws in case of any error.

#### spiStart

    public void spiStart(String gridName)
                  throws IgniteSpiException

This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Specified by:
  `spiStart` in interface `IgniteSpi`
Parameters:
  `gridName` - Name of grid instance this SPI is being started for (`null` for default grid).
Throws:
  `IgniteSpiException` - Throws in case of any error during SPI start.

#### onContextInitialized0

    public void onContextInitialized0(IgniteSpiContext spiCtx)
                               throws IgniteSpiException

Method to be called in the end of onContextInitialized method. }

Overrides:
  `onContextInitialized0` in class `IgniteSpiAdapter`
Parameters:
  `spiCtx` - SPI context.
Throws:
  `IgniteSpiException` - In case of errors.

#### getSpiContext

    public IgniteSpiContext getSpiContext()

Gets SPI context.

Overrides:
  `getSpiContext` in class `IgniteSpiAdapter`
Returns:
  SPI context.

#### spiStop

    public void spiStop()
                 throws IgniteSpiException

This method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.

Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.

Specified by:
  `spiStop` in interface `IgniteSpi`
Throws:
  `IgniteSpiException` - Thrown in case of any error during SPI stop.

#### onContextDestroyed0

    protected void onContextDestroyed0()

Method to be called in the beginning of onContextDestroyed() method.

Overrides:
  `onContextDestroyed0` in class `IgniteSpiAdapter`

#### checkConfigurationConsistency0

    protected void checkConfigurationConsistency0(IgniteSpiContext spiCtx,
                                      ClusterNode node,
                                      boolean starting)
                                           throws IgniteSpiException

Method which is called in the end of checkConfigurationConsistency() method. May be overriden in SPIs.

Overrides:
  `checkConfigurationConsistency0` in class `IgniteSpiAdapter`
Parameters:
  `spiCtx` - SPI context.
  `node` - Remote node.
  `starting` - If this node is starting or not.
Throws:
  `IgniteSpiException` - in case of errors.

#### sendMessage

    public void sendMessage(ClusterNode node,
                   MessageAdapter msg)
                     throws IgniteSpiException

Sends given message to destination node. Note that characteristics of the exchange such as durability, guaranteed delivery or error notification is dependant on SPI implementation.

Specified by:
  `sendMessage` in interface `CommunicationSpi<MessageAdapter>`
Parameters:
  `node` - Destination node.
  `msg` - Message to send.
Throws:
  `IgniteSpiException` - Thrown in case of any error during sending the message. Note that this is not guaranteed that failed communication will result in thrown exception as this is dependant on SPI implementation.

#### createNioClient

    @Nullable
    protected GridCommunicationClient createNioClient(ClusterNode node)
                                               throws IgniteCheckedException

Parameters:
  `node` - Node to create client for.
Returns:
  Client.
Throws:
  `IgniteCheckedException` - If failed.

#### createShmemClient

    @Nullable
    protected GridCommunicationClient createShmemClient(ClusterNode node,
                                                     Integer port)
                                                 throws IgniteCheckedException

Parameters:
  `node` - Node.
  `port` - Port.
Returns:
  Client.
Throws:
  `IgniteCheckedException` - If failed.

#### createTcpClient

    protected GridCommunicationClient createTcpClient(ClusterNode node)
                                               throws IgniteCheckedException

Establish TCP connection to remote node and returns client.

Parameters:
  `node` - Remote node.
Returns:
  Client.
Throws:
  `IgniteCheckedException` - If failed.

#### notifyListener

    protected void notifyListener(UUID sndId,
                      MessageAdapter msg,
                      IgniteRunnable msgC)

Parameters:
  `sndId` - Sender ID.
  `msg` - Communication message.
  `msgC` - Closure to call when message processing finished.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015