org.apache.ignite.spi.discovery.tcp

## Class TcpDiscoverySpi

- java.lang.Object
- - org.apache.ignite.spi.IgniteSpiAdapter
  - - org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi

All Implemented Interfaces:
  DiscoverySpi, TcpDiscoverySpiMBean, IgniteSpi, IgniteSpiManagementMBean

    @IgniteSpiMultipleInstancesSupport(value=true)
    @DiscoverySpiOrderSupport(value=true)
    @DiscoverySpiHistorySupport(value=true)
    public class TcpDiscoverySpi
    extends IgniteSpiAdapter
    implements DiscoverySpi, TcpDiscoverySpiMBean

Discovery SPI implementation that uses TCP/IP for node discovery.

Nodes are organized in ring. So almost all network exchange (except few cases) is done across it.

If node is configured as client node (see `IgniteConfiguration.clientMode`) TcpDiscoverySpi starts in client mode as well. In this case node does not take its place in the ring, but it connects to random node in the ring (IP taken from IP finder configured) and use it as a router for discovery traffic. Therefore slow client node or its shutdown will not affect whole cluster. If TcpDiscoverySpi needs to be started in server mode regardless of `IgniteConfiguration.clientMode`, `forceSrvMode` should be set to true.

At startup SPI tries to send messages to random IP taken from `TcpDiscoveryIpFinder` about self start (stops when send succeeds) and then this info goes to coordinator. When coordinator processes join request and issues node added messages and all other nodes then receive info about new node.

# Failure Detection

Configuration defaults (see Configuration section below and `IgniteConfiguration.getFailureDetectionTimeout()`) for details) are chosen to make possible for discovery SPI work reliably on most of hardware and virtual deployments, but this has made failure detection time worse.

If it's needed to tune failure detection then it's highly recommended to do this using `IgniteConfiguration.setFailureDetectionTimeout(long)`. This failure timeout automatically controls the following parameters: `getSocketTimeout()`, `getAckTimeout()`, `getMaxAckTimeout()`, `getReconnectCount()`. If any of those parameters is set explicitly, then the failure timeout setting will be ignored. As an example, for stable low-latency networks the failure detection timeout may be set to ~120 ms.

If it's required to perform advanced settings of failure detection and `IgniteConfiguration.getFailureDetectionTimeout()` is unsuitable then various `TcpDiscoverySpi` configuration parameters may be used. As an example, for stable low-latency networks the following more aggressive settings are recommended (which allows failure detection time ~200ms):

- Heartbeat frequency (see `setHeartbeatFrequency(long)`) - 100ms
- Socket timeout (see `setSocketTimeout(long)`) - 200ms
- Message acknowledgement timeout (see `setAckTimeout(long)`) - 50ms

# Configuration

## Mandatory

There are no mandatory configuration parameters.

## Optional

The following configuration parameters are optional:

- IP finder to share info about nodes IP addresses (see `setIpFinder(TcpDiscoveryIpFinder)`). See the following IP finder implementations for details on configuration:
  - `TcpDiscoverySharedFsIpFinder`
  - `TcpDiscoveryS3IpFinder`
  - `TcpDiscoveryJdbcIpFinder`
  - `TcpDiscoveryVmIpFinder`
  - `TcpDiscoveryMulticastIpFinder` - default

Local address (see `setLocalAddress(String)`)
Local port to bind to (see `setLocalPort(int)`)
Local port range to try binding to if previous ports are in use (see `setLocalPortRange(int)`)
Heartbeat frequency (see `setHeartbeatFrequency(long)`)
Max missed heartbeats (see `setMaxMissedHeartbeats(int)`)
Number of times node tries to (re)establish connection to another node (see `setReconnectCount(int)`)
Network timeout (see `setNetworkTimeout(long)`)
Socket timeout (see `setSocketTimeout(long)`)
Message acknowledgement timeout (see `setAckTimeout(long)`)
Maximum message acknowledgement timeout (see `setMaxAckTimeout(long)`)
Join timeout (see `setJoinTimeout(long)`)
Thread priority for threads started by SPI (see `setThreadPriority(int)`)
IP finder clean frequency (see `setIpFinderCleanFrequency(long)`)
Statistics print frequency (see `setStatisticsPrintFrequency(long)`
Force server mode (see `setForceServerMode(boolean)`

## Java Example

     TcpDiscoverySpi spi = new TcpDiscoverySpi();

     TcpDiscoveryVmIpFinder finder =
         new GridTcpDiscoveryVmIpFinder();

     spi.setIpFinder(finder);

     IgniteConfiguration cfg = new IgniteConfiguration();

     // Override default discovery SPI.
     cfg.setDiscoverySpi(spi);

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

## Spring Example

TcpDiscoverySpi can be configured from Spring XML configuration file:

     <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
             ...
             <property name="discoverySpi">
                 <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                     <property name="ipFinder">
                         <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder" />
                     </property>
                 </bean>
             </property>
             ...
     </bean>

For information about Spring framework visit www.springframework.org

See Also:
  `DiscoverySpi`

### Field Summary

Fields
`static String` `ATTR_EXT_ADDRS` Node attribute that is mapped to node's external addresses (value is `disc.tcp.ext-addrs`).
`protected UUID` `cfgNodeId`
`static long` `DFLT_ACK_TIMEOUT` Default timeout for receiving message acknowledgement in milliseconds (value is `5000ms`).
`static long` `DFLT_ACK_TIMEOUT_CLIENT` Default timeout for receiving message acknowledgement in milliseconds (value is `5000ms`).
`static long` `DFLT_HEARTBEAT_FREQ` Default heartbeat messages issuing frequency (value is `2000ms`).
`static long` `DFLT_IP_FINDER_CLEAN_FREQ` Default IP finder clean frequency in milliseconds (value is `60,000ms`).
`static long` `DFLT_JOIN_TIMEOUT` Default timeout for joining topology (value is `0`).
`static long` `DFLT_MAX_ACK_TIMEOUT` Maximum ack timeout value for receiving message acknowledgement in milliseconds (value is `600,000ms`).
`static int` `DFLT_MAX_MISSED_CLIENT_HEARTBEATS` Default max heartbeats count node can miss without failing client node (value is `5`).
`static int` `DFLT_MAX_MISSED_HEARTBEATS` Default max heartbeats count node can miss without initiating status check (value is `1`).
`static long` `DFLT_NETWORK_TIMEOUT` Default network timeout in milliseconds (value is `5000ms`).
`static int` `DFLT_PORT` Default port to listen (value is `47500`).
`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 long` `DFLT_SOCK_TIMEOUT` Default socket operations timeout in milliseconds (value is `5000ms`).
`static long` `DFLT_SOCK_TIMEOUT_CLIENT` Default socket operations timeout in milliseconds (value is `5000ms`).
`static long` `DFLT_STATS_PRINT_FREQ` Default statistics print frequency in milliseconds (value is `0ms`).
`static int` `DFLT_THREAD_PRI` Default value for thread priority (value is `10`).
`static int` `DFLT_TOP_HISTORY_SIZE` Default size of topology snapshots history.
`protected DiscoverySpiDataExchange` `exchange` Data exchange.
`protected long` `gridStartTime` Start time of the very first grid node.
`protected long` `hbFreq` Heartbeat messages issuing frequency.
`protected org.apache.ignite.spi.discovery.tcp.TcpDiscoveryImpl` `impl`
`protected CopyOnWriteArrayList<IgniteInClosure<Socket>>` `incomeConnLsnrs`
`protected TcpDiscoveryIpFinder` `ipFinder` IP finder.
`protected long` `ipFinderCleanFreq` IP finder clean frequency.
`protected long` `joinTimeout` Join timeout.
`protected String` `locAddr` Local address.
`protected InetAddress` `locHost` Local host.
`protected TcpDiscoveryNode` `locNode` Local node.
`protected Collection<InetSocketAddress>` `locNodeAddrs` Internal and external addresses of local node.
`protected Map<String,Object>` `locNodeAttrs` Local node attributes.
`protected IgniteProductVersion` `locNodeVer` Local node version.
`protected int` `locPort` Local port which node uses.
`protected int` `locPortRange` Local port range.
`protected IgniteLogger` `log` Logger.
`protected DiscoverySpiListener` `lsnr` Grid discovery listener.
`protected int` `maxMissedClientHbs` Max heartbeats count node can miss without failing client node.
`protected int` `maxMissedHbs` Max heartbeats count node can miss without initiating status check.
`protected DiscoveryMetricsProvider` `metricsProvider` Metrics provider.
`protected long` `netTimeout` Network timeout.
`protected DiscoverySpiNodeAuthenticator` `nodeAuth` Node authenticator.
`protected CopyOnWriteArrayList<IgniteInClosure<TcpDiscoveryAbstractMessage>>` `sndMsgLsnrs`
`protected SSLSocketFactory` `sslSockFactory` SSL socket factory.
`protected SSLServerSocketFactory` `sslSrvSockFactory` SSL server socket factory.
`protected TcpDiscoveryStatistics` `stats` Statistics.
`protected long` `statsPrintFreq` Statistics print frequency.
`protected int` `threadPri` Thread priority for all threads started by SPI.
`protected int` `topHistSize` Size of topology snapshots history.

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

`gridName, ignite`

### Constructor Summary

Constructors
Constructor and Description
`TcpDiscoverySpi()`

### Method Summary

Methods
`void` `addIncomeConnectionListener(IgniteInClosure<Socket> lsnr)` FOR TEST ONLY!!!
`void` `addSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> lsnr)` FOR TEST ONLY!!!
`protected IgniteSpiException` `authenticationFailedError(TcpDiscoveryAuthFailedMessage msg)`
`void` `brakeConnection()` FOR TEST PURPOSE ONLY!
`protected IgniteSpiException` `checkFailedError(TcpDiscoveryCheckFailedMessage msg)`
`int` `clientWorkerCount()` FOR TEST ONLY!!!
`protected Map<Integer,byte[]>` `collectExchangeData(UUID nodeId)`
`void` `disconnect()` Tells discovery SPI to disconnect from topology.
`void` `dumpDebugInfo()` Dumps debug info using configured logger.
`protected IgniteSpiException` `duplicateIdError(TcpDiscoveryDuplicateIdMessage msg)`
`protected boolean` `ensured(TcpDiscoveryAbstractMessage msg)`
`void` `failNode(UUID nodeId, String warning)` Initiates failure of provided node.
`long` `getAckTimeout()` Gets message acknowledgement timeout.
`AddressResolver` `getAddressResolver()` Gets address resolver.
`long` `getAvgMessageProcessingTime()` Gets avg message processing time.
`UUID` `getCoordinator()` Gets current coordinator.
`long` `getCoordinatorSinceTimestamp()` Gets time local node has been coordinator since.
`long` `getGridStartTime()` Gets start time of the very first node in the grid.
`long` `getHeartbeatFrequency()` Gets delay between heartbeat messages sent by coordinator.
`TcpDiscoveryIpFinder` `getIpFinder()` Gets IP finder for IP addresses sharing and storing.
`long` `getIpFinderCleanFrequency()` Gets IP finder clean frequency.
`String` `getIpFinderFormatted()` Gets `TcpDiscoveryIpFinder` (string representation).
`long` `getJoinTimeout()` Gets join timeout.
`String` `getLocalAddress()` Gets local address that was set to SPI with `setLocalAddress(String)` method.
`ClusterNode` `getLocalNode()` Gets local node.
`int` `getLocalPort()` Gets local TCP port SPI listens to.
`int` `getLocalPortRange()` Gets local TCP port range.
`long` `getMaxAckTimeout()` Gets maximum message acknowledgement timeout.
`long` `getMaxMessageProcessingTime()` Gets max message processing time.
`int` `getMaxMissedClientHeartbeats()` Gets max heartbeats count node can miss without failing client node.
`int` `getMaxMissedHeartbeats()` Gets max heartbeats count node can miss without initiating status check.
`int` `getMessageWorkerQueueSize()` Gets message worker queue current size.
`long` `getNetworkTimeout()` Gets network timeout.
`ClusterNode` `getNode(UUID nodeId)` Gets node by ID.
`long` `getNodesFailed()` Gets failed nodes count.
`long` `getNodesJoined()` Gets joined nodes count.
`long` `getNodesLeft()` Gets left nodes count.
`long` `getPendingMessagesDiscarded()` Gets pending messages discarded count.
`long` `getPendingMessagesRegistered()` Gets pending messages registered count.
`Map<String,Integer>` `getProcessedMessages()` Gets processed messages counts (grouped by type).
`Map<String,Integer>` `getReceivedMessages()` Gets received messages counts (grouped by type).
`int` `getReconnectCount()` Gets number of connection attempts.
`Collection<ClusterNode>` `getRemoteNodes()` Gets collection of remote nodes in grid or empty collection if no remote nodes found.
`long` `getSocketTimeout()` Gets socket timeout.
`IgniteSpiContext` `getSpiContext()` Gets SPI context.
`String` `getSpiState()` Gets current SPI state.
`long` `getStatisticsPrintFrequency()` Gets statistics print frequency.
`int` `getThreadPriority()` Gets thread priority.
`long` `getTopHistorySize()`
`int` `getTotalProcessedMessages()` Gets total processed messages count.
`int` `getTotalReceivedMessages()` Gets total received messages count.
`protected void` `initLocalNode(int srvPort, boolean addExtAddrAttr)`
`Collection<Object>` `injectables()` This method returns SPI internal instances that need to be injected as well.
`protected void` `injectResources(Ignite ignite)` Inject resources
`boolean` `isClientMode()` Whether or not discovery is started in client mode.
`boolean` `isClientReconnectDisabled()` If `true` client does not try to reconnect after server detected client node failure.
`boolean` `isForceServerMode()` If `true` TcpDiscoverySpi will started in server mode regardless of `IgniteConfiguration.isClientMode()`
`protected Marshaller` `marshaller()`
`protected void` `onContextDestroyed0()` Method to be called in the beginning of onContextDestroyed() method.
`protected void` `onContextInitialized0(IgniteSpiContext spiCtx)` Method to be called in the end of onContextInitialized method.
`protected void` `onExchange(UUID joiningNodeID, UUID nodeId, Map<Integer,byte[]> data, ClassLoader clsLdr)`
`protected Socket` `openSocket(InetSocketAddress sockAddr, IgniteSpiOperationTimeoutHelper timeoutHelper)`
`protected Socket` `openSocket(Socket sock, InetSocketAddress remAddr, IgniteSpiOperationTimeoutHelper timeoutHelper)` Connects to remote address sending `U.IGNITE_HEADER` when connection is established.
`boolean` `pingNode(UUID nodeId)` Pings the remote node to see if it's alive.
`protected <T> T` `readMessage(Socket sock, InputStream in, long timeout)` Reads message from the socket limiting read time.
`protected int` `readReceipt(Socket sock, long timeout)` Reads message delivery receipt from the socket.
`protected Collection<InetSocketAddress>` `registeredAddresses()` Gets addresses registered in the IP finder, initializes addresses having no port (or 0 port) with `DFLT_PORT`.
`void` `removeIncomeConnectionListener(IgniteInClosure<Socket> lsnr)` FOR TEST ONLY!!!
`void` `removeSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> lsnr)` FOR TEST ONLY!!!
`protected Collection<InetSocketAddress>` `resolvedAddresses()` Resolves addresses registered in the IP finder, removes duplicates and local host address and returns the collection of.
`void` `sendCustomEvent(DiscoverySpiCustomMessage msg)` Sends custom message across the ring.
`TcpDiscoverySpi` `setAckTimeout(long ackTimeout)` Sets timeout for receiving acknowledgement for sent message.
`void` `setAddressResolver(AddressResolver addrRslvr)` Sets address resolver.
`void` `setAuthenticator(DiscoverySpiNodeAuthenticator auth)` Sets discovery SPI node authenticator.
`void` `setClientReconnectDisabled(boolean clientReconnectDisabled)` Sets client reconnect disabled flag.
`TcpDiscoverySpi` `setDataExchange(DiscoverySpiDataExchange exchange)` Sets a handler for initial data exchange between Ignite nodes.
`TcpDiscoverySpi` `setForceServerMode(boolean forceSrvMode)` Sets force server mode flag.
`TcpDiscoverySpi` `setHeartbeatFrequency(long hbFreq)` Sets delay between issuing of heartbeat messages.
`TcpDiscoverySpi` `setIpFinder(TcpDiscoveryIpFinder ipFinder)` Sets IP finder for IP addresses sharing and storing.
`TcpDiscoverySpi` `setIpFinderCleanFrequency(long ipFinderCleanFreq)` Sets IP finder clean frequency in milliseconds.
`TcpDiscoverySpi` `setJoinTimeout(long joinTimeout)` Sets join timeout.
`void` `setListener(DiscoverySpiListener lsnr)` Sets a listener for discovery events.
`TcpDiscoverySpi` `setLocalAddress(String locAddr)` Sets local host IP address that discovery SPI uses.
`TcpDiscoverySpi` `setLocalPort(int locPort)` Sets local port to listen to.
`TcpDiscoverySpi` `setLocalPortRange(int locPortRange)` Range for local ports.
`TcpDiscoverySpi` `setMaxAckTimeout(long maxAckTimeout)` Sets maximum timeout for receiving acknowledgement for sent message.
`TcpDiscoverySpi` `setMaxMissedClientHeartbeats(int maxMissedClientHbs)` Sets max heartbeats count node can miss without failing client node.
`TcpDiscoverySpi` `setMaxMissedHeartbeats(int maxMissedHbs)` Sets max heartbeats count node can miss without initiating status check.
`TcpDiscoverySpi` `setMetricsProvider(DiscoveryMetricsProvider metricsProvider)` Sets discovery metrics provider.
`TcpDiscoverySpi` `setNetworkTimeout(long netTimeout)` Sets maximum network timeout to use for network operations.
`void` `setNodeAttributes(Map<String,Object> attrs, IgniteProductVersion ver)` Sets node attributes and node version which will be distributed in grid during join process.
`TcpDiscoverySpi` `setReconnectCount(int reconCnt)` Number of times node tries to (re)establish connection to another node.
`TcpDiscoverySpi` `setSocketTimeout(long sockTimeout)` Sets socket operations timeout.
`TcpDiscoverySpi` `setStatisticsPrintFrequency(long statsPrintFreq)` Sets statistics print frequency.
`TcpDiscoverySpi` `setThreadPriority(int threadPri)` Sets thread priority.
`TcpDiscoverySpi` `setTopHistorySize(int topHistSize)` Sets size of topology snapshots history.
`protected void` `simulateNodeFailure()` FOR TEST ONLY!!!
`void` `spiStart(String gridName)` This method is called to start SPI.
`void` `spiStop()` This method is called to stop SPI.
`String` `toString()`
`void` `waitForClientMessagePrecessed()` FOR TEST PURPOSE ONLY!
`protected void` `writeToSocket(Socket sock, OutputStream out, TcpDiscoveryAbstractMessage msg, long timeout)` Writes message to the socket.
`protected void` `writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, byte[] data, long timeout)` Writes message to the socket.
`protected void` `writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, long timeout)` Writes message to the socket.
`protected void` `writeToSocket(TcpDiscoveryAbstractMessage msg, Socket sock, int res, long timeout)` Writes response to the socket.

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

`addTimeoutObject, assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getIgniteHome, getLocalNodeId, getName, getNodeAttributes, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, initFailureDetectionTimeout, isNodeStopping, onBeforeStart, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized, registerMBean, removeTimeoutObject, setName, started, 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, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized`

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

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

### Field Detail

#### ATTR_EXT_ADDRS

    public static final String ATTR_EXT_ADDRS

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

See Also:
  Constant Field Values

#### DFLT_PORT_RANGE

    public static final int DFLT_PORT_RANGE

Default local port range (value is `100`).

See Also:
  Constant Field Values

#### DFLT_PORT

    public static final int DFLT_PORT

Default port to listen (value is `47500`).

See Also:
  Constant Field Values

#### DFLT_JOIN_TIMEOUT

    public static final long DFLT_JOIN_TIMEOUT

Default timeout for joining topology (value is `0`).

See Also:
  Constant Field Values

#### DFLT_NETWORK_TIMEOUT

    public static final long DFLT_NETWORK_TIMEOUT

Default network timeout in milliseconds (value is `5000ms`).

See Also:
  Constant Field Values

#### DFLT_THREAD_PRI

    public static final int DFLT_THREAD_PRI

Default value for thread priority (value is `10`).

See Also:
  Constant Field Values

#### DFLT_HEARTBEAT_FREQ

    public static final long DFLT_HEARTBEAT_FREQ

Default heartbeat messages issuing frequency (value is `2000ms`).

See Also:
  Constant Field Values

#### DFLT_TOP_HISTORY_SIZE

    public static final int DFLT_TOP_HISTORY_SIZE

Default size of topology snapshots history.

See Also:
  Constant Field Values

#### DFLT_SOCK_TIMEOUT

    public static final long DFLT_SOCK_TIMEOUT

Default socket operations timeout in milliseconds (value is `5000ms`).

See Also:
  Constant Field Values

#### DFLT_ACK_TIMEOUT

    public static final long DFLT_ACK_TIMEOUT

Default timeout for receiving message acknowledgement in milliseconds (value is `5000ms`).

See Also:
  Constant Field Values

#### DFLT_SOCK_TIMEOUT_CLIENT

    public static final long DFLT_SOCK_TIMEOUT_CLIENT

Default socket operations timeout in milliseconds (value is `5000ms`).

See Also:
  Constant Field Values

#### DFLT_ACK_TIMEOUT_CLIENT

    public static final long DFLT_ACK_TIMEOUT_CLIENT

Default timeout for receiving message acknowledgement in milliseconds (value is `5000ms`).

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_MAX_MISSED_HEARTBEATS

    public static final int DFLT_MAX_MISSED_HEARTBEATS

Default max heartbeats count node can miss without initiating status check (value is `1`).

See Also:
  Constant Field Values

#### DFLT_MAX_MISSED_CLIENT_HEARTBEATS

    public static final int DFLT_MAX_MISSED_CLIENT_HEARTBEATS

Default max heartbeats count node can miss without failing client node (value is `5`).

See Also:
  Constant Field Values

#### DFLT_IP_FINDER_CLEAN_FREQ

    public static final long DFLT_IP_FINDER_CLEAN_FREQ

Default IP finder clean frequency in milliseconds (value is `60,000ms`).

See Also:
  Constant Field Values

#### DFLT_STATS_PRINT_FREQ

    public static final long DFLT_STATS_PRINT_FREQ

Default statistics print frequency in milliseconds (value is `0ms`).

See Also:
  Constant Field Values

#### DFLT_MAX_ACK_TIMEOUT

    public static final long DFLT_MAX_ACK_TIMEOUT

Maximum ack timeout value for receiving message acknowledgement in milliseconds (value is `600,000ms`).

See Also:
  Constant Field Values

#### locAddr

    protected String locAddr

Local address.

#### ipFinder

    protected TcpDiscoveryIpFinder ipFinder

IP finder.

#### netTimeout

    protected long netTimeout

Network timeout.

#### joinTimeout

    protected long joinTimeout

Join timeout.

#### threadPri

    protected int threadPri

Thread priority for all threads started by SPI.

#### hbFreq

    protected long hbFreq

Heartbeat messages issuing frequency.

#### topHistSize

    protected int topHistSize

Size of topology snapshots history.

#### lsnr

    protected volatile DiscoverySpiListener lsnr

Grid discovery listener.

#### exchange

    protected DiscoverySpiDataExchange exchange

Data exchange.

#### metricsProvider

    protected DiscoveryMetricsProvider metricsProvider

Metrics provider.

#### locNodeAttrs

    protected Map<String,Object> locNodeAttrs

Local node attributes.

#### locNodeVer

    protected IgniteProductVersion locNodeVer

Local node version.

#### locNode

    protected TcpDiscoveryNode locNode

Local node.

#### cfgNodeId

    protected UUID cfgNodeId

#### locHost

    protected InetAddress locHost

Local host.

#### locNodeAddrs

    protected Collection<InetSocketAddress> locNodeAddrs

Internal and external addresses of local node.

#### gridStartTime

    protected volatile long gridStartTime

Start time of the very first grid node.

#### stats

    protected final TcpDiscoveryStatistics stats

Statistics.

#### locPort

    protected int locPort

Local port which node uses.

#### locPortRange

    protected int locPortRange

Local port range.

#### statsPrintFreq

    protected long statsPrintFreq

Statistics print frequency.

#### maxMissedHbs

    protected int maxMissedHbs

Max heartbeats count node can miss without initiating status check.

#### maxMissedClientHbs

    protected int maxMissedClientHbs

Max heartbeats count node can miss without failing client node.

#### ipFinderCleanFreq

    protected long ipFinderCleanFreq

IP finder clean frequency.

#### nodeAuth

    protected DiscoverySpiNodeAuthenticator nodeAuth

Node authenticator.

#### sslSrvSockFactory

    protected SSLServerSocketFactory sslSrvSockFactory

SSL server socket factory.

#### sslSockFactory

    protected SSLSocketFactory sslSockFactory

SSL socket factory.

#### sndMsgLsnrs

    protected final CopyOnWriteArrayList<IgniteInClosure<TcpDiscoveryAbstractMessage>> sndMsgLsnrs

#### incomeConnLsnrs

    protected final CopyOnWriteArrayList<IgniteInClosure<Socket>> incomeConnLsnrs

#### log

    @LoggerResource
    protected IgniteLogger log

Logger.

#### impl

    protected org.apache.ignite.spi.discovery.tcp.TcpDiscoveryImpl impl

### Constructor Detail

#### TcpDiscoverySpi

    public TcpDiscoverySpi()

### Method Detail

#### getSpiState

    public String getSpiState()

Gets current SPI state.

Specified by:
  `getSpiState` in interface `TcpDiscoverySpiMBean`
Returns:
  Current SPI state.

#### getMessageWorkerQueueSize

    public int getMessageWorkerQueueSize()

Gets message worker queue current size.

Specified by:
  `getMessageWorkerQueueSize` in interface `TcpDiscoverySpiMBean`
Returns:
  Message worker queue current size.

#### getCoordinator

    @Nullable
    public UUID getCoordinator()

Gets current coordinator.

Specified by:
  `getCoordinator` in interface `TcpDiscoverySpiMBean`
Returns:
  Gets current coordinator.

#### getRemoteNodes

    public Collection<ClusterNode> getRemoteNodes()

Gets collection of remote nodes in grid or empty collection if no remote nodes found.

Specified by:
  `getRemoteNodes` in interface `DiscoverySpi`
Returns:
  Collection of remote nodes.

#### getNode

    @Nullable
    public ClusterNode getNode(UUID nodeId)

Gets node by ID.

Specified by:
  `getNode` in interface `DiscoverySpi`
Parameters:
  `nodeId` - Node ID.
Returns:
  Node with given ID or `null` if node is not found.

#### pingNode

    public boolean pingNode(UUID nodeId)

Pings the remote node to see if it's alive.

Specified by:
  `pingNode` in interface `DiscoverySpi`
Parameters:
  `nodeId` - Node Id.
Returns:
  `true` if node alive, `false` otherwise.

#### disconnect

    public void disconnect()
                    throws IgniteSpiException

Tells discovery SPI to disconnect from topology. This is very close to calling `IgniteSpi.spiStop()` with accounting that it is not a full stop, but disconnect due to segmentation.

Specified by:
  `disconnect` in interface `DiscoverySpi`
Throws:
  `IgniteSpiException` - If any error occurs.

#### setAuthenticator

    public void setAuthenticator(DiscoverySpiNodeAuthenticator auth)

Sets discovery SPI node authenticator. This method is called before SPI start() method.

Specified by:
  `setAuthenticator` in interface `DiscoverySpi`
Parameters:
  `auth` - Discovery SPI authenticator.

#### sendCustomEvent

    public void sendCustomEvent(DiscoverySpiCustomMessage msg)
                         throws IgniteException

Sends custom message across the ring.

Specified by:
  `sendCustomEvent` in interface `DiscoverySpi`
Parameters:
  `msg` - Custom message.
Throws:
  `IgniteException` - if failed to marshal evt.

#### failNode

    public void failNode(UUID nodeId,
                @Nullable
                String warning)

Initiates failure of provided node.

Specified by:
  `failNode` in interface `DiscoverySpi`
Parameters:
  `nodeId` - Node ID.
  `warning` - Warning to be shown on all cluster nodes.

#### dumpDebugInfo

    public void dumpDebugInfo()

Dumps debug info using configured logger.

Specified by:
  `dumpDebugInfo` in interface `TcpDiscoverySpiMBean`

#### isClientMode

    public boolean isClientMode()

Whether or not discovery is started in client mode.

Specified by:
  `isClientMode` in interface `DiscoverySpi`
Specified by:
  `isClientMode` in interface `TcpDiscoverySpiMBean`
Returns:
  `true` if node is in client mode.

#### isForceServerMode

    public boolean isForceServerMode()

If `true` TcpDiscoverySpi will started in server mode regardless of `IgniteConfiguration.isClientMode()`

Returns:
  forceServerMode flag.

#### setForceServerMode

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setForceServerMode(boolean forceSrvMode)

Sets force server mode flag.

If `true` TcpDiscoverySpi is started in server mode regardless of `IgniteConfiguration.isClientMode()`.

Parameters:
  `forceSrvMode` - forceServerMode flag.
Returns:
  `this` for chaining.

#### isClientReconnectDisabled

    public boolean isClientReconnectDisabled()

If `true` client does not try to reconnect after server detected client node failure.

Returns:
  Client reconnect disabled flag.

#### setClientReconnectDisabled

    @IgniteSpiConfiguration(optional=true)
    public void setClientReconnectDisabled(boolean clientReconnectDisabled)

Sets client reconnect disabled flag.

If `true` client does not try to reconnect after server detected client node failure.

Parameters:
  `clientReconnectDisabled` - Client reconnect disabled flag.

#### injectResources

    @IgniteInstanceResource
    protected void injectResources(Ignite ignite)

Inject resources

Overrides:
  `injectResources` in class `IgniteSpiAdapter`
Parameters:
  `ignite` - Ignite.

#### setLocalAddress

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

Sets local host IP address that discovery SPI uses.

If not provided, by default a first found non-loopback address will be used. If there is no non-loopback address available, then `InetAddress.getLocalHost()` will be used.

Parameters:
  `locAddr` - IP address.
Returns:
  `this` for chaining.

#### getLocalAddress

    public String getLocalAddress()

Gets local address that was set to SPI with `setLocalAddress(String)` method.

Returns:
  local address.

#### setAddressResolver

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

Sets address resolver.

Parameters:
  `addrRslvr` - Address resolver.

#### getAddressResolver

    public AddressResolver getAddressResolver()

Gets address resolver.

Returns:
  Address resolver.

#### getReconnectCount

    public int getReconnectCount()

Gets number of connection attempts.

Specified by:
  `getReconnectCount` in interface `TcpDiscoverySpiMBean`
Returns:
  Number of connection attempts.

#### setReconnectCount

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

Number of times node tries to (re)establish connection to another node.

Note that SPI implementation will increase `ackTimeout` by factor 2 on every retry.

If not specified, default is `DFLT_RECONNECT_CNT`.

When this property is explicitly set `IgniteConfiguration.getFailureDetectionTimeout()` is ignored.

Parameters:
  `reconCnt` - Number of retries during message sending.
Returns:
  `this` for chaining.
See Also:
  `setAckTimeout(long)`

#### getMaxAckTimeout

    public long getMaxAckTimeout()

Gets maximum message acknowledgement timeout.

Specified by:
  `getMaxAckTimeout` in interface `TcpDiscoverySpiMBean`
Returns:
  Maximum message acknowledgement timeout.

#### setMaxAckTimeout

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setMaxAckTimeout(long maxAckTimeout)

Sets maximum timeout for receiving acknowledgement for sent message.

If acknowledgement is not received within this timeout, sending is considered as failed and SPI tries to repeat message sending. Every time SPI retries messing sending, ack timeout will be increased. If no acknowledgement is received and `maxAckTimeout` is reached, then the process of message sending is considered as failed.

If not specified, default is `DFLT_MAX_ACK_TIMEOUT`.

Affected server nodes only.

When this property is explicitly set `IgniteConfiguration.getFailureDetectionTimeout()` is ignored.

Parameters:
  `maxAckTimeout` - Maximum acknowledgement timeout.
Returns:
  `this` for chaining.

#### getLocalPort

    public int getLocalPort()

Gets local TCP port SPI listens to.

Specified by:
  `getLocalPort` in interface `TcpDiscoverySpiMBean`
Returns:
  Local port range.

#### setLocalPort

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

Sets local port to listen to.

If not specified, default is `DFLT_PORT`.

Affected server nodes only.

Parameters:
  `locPort` - Local port to bind.
Returns:
  `this` for chaining.

#### getLocalPortRange

    public int getLocalPortRange()

Gets local TCP port range.

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

#### setLocalPortRange

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

Range for local ports. Local node will try to bind on first available port starting from `getLocalPort()` up until ``getLocalPort()` `+ locPortRange``. 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.

If not specified, default is `DFLT_PORT_RANGE`.

Affected server nodes only.

Parameters:
  `locPortRange` - Local port range to bind.
Returns:
  `this` for chaining.

#### getMaxMissedHeartbeats

    public int getMaxMissedHeartbeats()

Gets max heartbeats count node can miss without initiating status check.

Specified by:
  `getMaxMissedHeartbeats` in interface `TcpDiscoverySpiMBean`
Returns:
  Max missed heartbeats.

#### setMaxMissedHeartbeats

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setMaxMissedHeartbeats(int maxMissedHbs)

Sets max heartbeats count node can miss without initiating status check.

If not provided, default value is `DFLT_MAX_MISSED_HEARTBEATS`.

Affected server nodes only.

Parameters:
  `maxMissedHbs` - Max missed heartbeats.
Returns:
  `this` for chaining.

#### getMaxMissedClientHeartbeats

    public int getMaxMissedClientHeartbeats()

Gets max heartbeats count node can miss without failing client node.

Specified by:
  `getMaxMissedClientHeartbeats` in interface `TcpDiscoverySpiMBean`
Returns:
  Max missed client heartbeats.

#### setMaxMissedClientHeartbeats

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setMaxMissedClientHeartbeats(int maxMissedClientHbs)

Sets max heartbeats count node can miss without failing client node.

If not provided, default value is `DFLT_MAX_MISSED_CLIENT_HEARTBEATS`.

Parameters:
  `maxMissedClientHbs` - Max missed client heartbeats.
Returns:
  `this` for chaining.

#### getStatisticsPrintFrequency

    public long getStatisticsPrintFrequency()

Gets statistics print frequency.

Specified by:
  `getStatisticsPrintFrequency` in interface `TcpDiscoverySpiMBean`
Returns:
  Statistics print frequency in milliseconds.

#### setStatisticsPrintFrequency

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setStatisticsPrintFrequency(long statsPrintFreq)

Sets statistics print frequency.

If not set default value is `DFLT_STATS_PRINT_FREQ`. 0 indicates that no print is required. If value is greater than 0 and log is not quiet then statistics are printed out with INFO level.

This may be very helpful for tracing topology problems.

Parameters:
  `statsPrintFreq` - Statistics print frequency in milliseconds.
Returns:
  `this` for chaining.

#### getIpFinderCleanFrequency

    public long getIpFinderCleanFrequency()

Gets IP finder clean frequency.

Specified by:
  `getIpFinderCleanFrequency` in interface `TcpDiscoverySpiMBean`
Returns:
  IP finder clean frequency.

#### setIpFinderCleanFrequency

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setIpFinderCleanFrequency(long ipFinderCleanFreq)

Sets IP finder clean frequency in milliseconds.

If not provided, default value is `DFLT_IP_FINDER_CLEAN_FREQ`

Affected server nodes only.

Parameters:
  `ipFinderCleanFreq` - IP finder clean frequency.
Returns:
  `this` for chaining.

#### getIpFinder

    public TcpDiscoveryIpFinder getIpFinder()

Gets IP finder for IP addresses sharing and storing.

Returns:
  IP finder for IP addresses sharing and storing.

#### setIpFinder

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setIpFinder(TcpDiscoveryIpFinder ipFinder)

Sets IP finder for IP addresses sharing and storing.

If not provided `TcpDiscoveryMulticastIpFinder` will be used by default.

Parameters:
  `ipFinder` - IP finder.
Returns:
  `this` for chaining.

#### setSocketTimeout

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setSocketTimeout(long sockTimeout)

Sets socket operations timeout. This timeout is used to limit connection time and write-to-socket time.

Note that when running Ignite on Amazon EC2, socket timeout must be set to a value significantly greater than the default (e.g. to `30000`).

If not specified, default is `DFLT_SOCK_TIMEOUT` or `DFLT_SOCK_TIMEOUT_CLIENT`.

When this property is explicitly set `IgniteConfiguration.getFailureDetectionTimeout()` is ignored.

Parameters:
  `sockTimeout` - Socket connection timeout.
Returns:
  `this` for chaining.

#### setAckTimeout

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setAckTimeout(long ackTimeout)

Sets timeout for receiving acknowledgement for sent message.

If acknowledgement is not received within this timeout, sending is considered as failed and SPI tries to repeat message sending.

If not specified, default is `DFLT_ACK_TIMEOUT` or `DFLT_ACK_TIMEOUT_CLIENT`.

When this property is explicitly set `IgniteConfiguration.getFailureDetectionTimeout()` is ignored.

Parameters:
  `ackTimeout` - Acknowledgement timeout.
Returns:
  `this` for chaining.

#### setNetworkTimeout

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setNetworkTimeout(long netTimeout)

Sets maximum network timeout to use for network operations.

If not specified, default is `DFLT_NETWORK_TIMEOUT`.

Parameters:
  `netTimeout` - Network timeout.
Returns:
  `this` for chaining.

#### getJoinTimeout

    public long getJoinTimeout()

Gets join timeout.

Specified by:
  `getJoinTimeout` in interface `TcpDiscoverySpiMBean`
Returns:
  Join timeout.

#### setJoinTimeout

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setJoinTimeout(long joinTimeout)

Sets join timeout.

If non-shared IP finder is used and node fails to connect to any address from IP finder, node keeps trying to join within this timeout. If all addresses are still unresponsive, exception is thrown and node startup fails.

If not specified, default is `DFLT_JOIN_TIMEOUT`.

Parameters:
  `joinTimeout` - Join timeout (`0` means wait forever).
Returns:
  `this` for chaining.
See Also:
  `TcpDiscoveryIpFinder.isShared()`

#### setThreadPriority

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setThreadPriority(int threadPri)

Sets thread priority. All threads within SPI will be started with it.

If not provided, default value is `DFLT_THREAD_PRI`

Parameters:
  `threadPri` - Thread priority.
Returns:
  `this` for chaining.

#### setHeartbeatFrequency

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setHeartbeatFrequency(long hbFreq)

Sets delay between issuing of heartbeat messages. SPI sends heartbeat messages in configurable time interval to other nodes to notify them about its state.

If not provided, default value is `DFLT_HEARTBEAT_FREQ`.

Parameters:
  `hbFreq` - Heartbeat frequency in milliseconds.
Returns:
  `this` for chaining.

#### getTopHistorySize

    public long getTopHistorySize()

Returns:
  Size of topology snapshots history.

#### setTopHistorySize

    @IgniteSpiConfiguration(optional=true)
    public TcpDiscoverySpi setTopHistorySize(int topHistSize)

Sets size of topology snapshots history. Specified size should be greater than or equal to default size `DFLT_TOP_HISTORY_SIZE`.

Parameters:
  `topHistSize` - Size of topology snapshots history.
Returns:
  `this` for chaining.

#### setNodeAttributes

    public void setNodeAttributes(Map<String,Object> attrs,
                         IgniteProductVersion ver)

Sets node attributes and node version which will be distributed in grid during join process. Note that these attributes cannot be changed and set only once.

Specified by:
  `setNodeAttributes` in interface `DiscoverySpi`
Parameters:
  `attrs` - Map of node attributes.
  `ver` - Product version.

#### initLocalNode

    protected void initLocalNode(int srvPort,
                     boolean addExtAddrAttr)

Parameters:
  `srvPort` - Server port.
  `addExtAddrAttr` - If `true` adds `ATTR_EXT_ADDRS` attribute.

#### injectables

    public Collection<Object> injectables()

This method returns SPI internal instances that need to be injected as well. Usually these will be instances provided to SPI externally by user, e.g. during SPI configuration.

Overrides:
  `injectables` in class `IgniteSpiAdapter`
Returns:
  Internal SPI objects that also need to be injected.

#### getSocketTimeout

    public long getSocketTimeout()

Gets socket timeout.

Specified by:
  `getSocketTimeout` in interface `TcpDiscoverySpiMBean`
Returns:
  Socket timeout.

#### getAckTimeout

    public long getAckTimeout()

Gets message acknowledgement timeout.

Specified by:
  `getAckTimeout` in interface `TcpDiscoverySpiMBean`
Returns:
  Message acknowledgement timeout.

#### getNetworkTimeout

    public long getNetworkTimeout()

Gets network timeout.

Specified by:
  `getNetworkTimeout` in interface `TcpDiscoverySpiMBean`
Returns:
  Network timeout.

#### getThreadPriority

    public int getThreadPriority()

Gets thread priority. All threads within SPI will be started with it.

Specified by:
  `getThreadPriority` in interface `TcpDiscoverySpiMBean`
Returns:
  Thread priority.

#### getHeartbeatFrequency

    public long getHeartbeatFrequency()

Gets delay between heartbeat messages sent by coordinator.

Specified by:
  `getHeartbeatFrequency` in interface `TcpDiscoverySpiMBean`
Returns:
  Time period in milliseconds.

#### getIpFinderFormatted

    public String getIpFinderFormatted()

Gets `TcpDiscoveryIpFinder` (string representation).

Specified by:
  `getIpFinderFormatted` in interface `TcpDiscoverySpiMBean`
Returns:
  IPFinder (string representation).

#### getNodesJoined

    public long getNodesJoined()

Gets joined nodes count.

Specified by:
  `getNodesJoined` in interface `TcpDiscoverySpiMBean`
Returns:
  Nodes joined count.

#### getNodesLeft

    public long getNodesLeft()

Gets left nodes count.

Specified by:
  `getNodesLeft` in interface `TcpDiscoverySpiMBean`
Returns:
  Left nodes count.

#### getNodesFailed

    public long getNodesFailed()

Gets failed nodes count.

Specified by:
  `getNodesFailed` in interface `TcpDiscoverySpiMBean`
Returns:
  Failed nodes count.

#### getPendingMessagesRegistered

    public long getPendingMessagesRegistered()

Gets pending messages registered count.

Specified by:
  `getPendingMessagesRegistered` in interface `TcpDiscoverySpiMBean`
Returns:
  Pending messages registered count.

#### getPendingMessagesDiscarded

    public long getPendingMessagesDiscarded()

Gets pending messages discarded count.

Specified by:
  `getPendingMessagesDiscarded` in interface `TcpDiscoverySpiMBean`
Returns:
  Pending messages registered count.

#### getAvgMessageProcessingTime

    public long getAvgMessageProcessingTime()

Gets avg message processing time.

Specified by:
  `getAvgMessageProcessingTime` in interface `TcpDiscoverySpiMBean`
Returns:
  Avg message processing time.

#### getMaxMessageProcessingTime

    public long getMaxMessageProcessingTime()

Gets max message processing time.

Specified by:
  `getMaxMessageProcessingTime` in interface `TcpDiscoverySpiMBean`
Returns:
  Max message processing time.

#### getTotalReceivedMessages

    public int getTotalReceivedMessages()

Gets total received messages count.

Specified by:
  `getTotalReceivedMessages` in interface `TcpDiscoverySpiMBean`
Returns:
  Total received messages count.

#### getReceivedMessages

    public Map<String,Integer> getReceivedMessages()

Gets received messages counts (grouped by type).

Specified by:
  `getReceivedMessages` in interface `TcpDiscoverySpiMBean`
Returns:
  Map containing message types and respective counts.

#### getTotalProcessedMessages

    public int getTotalProcessedMessages()

Gets total processed messages count.

Specified by:
  `getTotalProcessedMessages` in interface `TcpDiscoverySpiMBean`
Returns:
  Total processed messages count.

#### getProcessedMessages

    public Map<String,Integer> getProcessedMessages()

Gets processed messages counts (grouped by type).

Specified by:
  `getProcessedMessages` in interface `TcpDiscoverySpiMBean`
Returns:
  Map containing message types and respective counts.

#### getCoordinatorSinceTimestamp

    public long getCoordinatorSinceTimestamp()

Gets time local node has been coordinator since.

Specified by:
  `getCoordinatorSinceTimestamp` in interface `TcpDiscoverySpiMBean`
Returns:
  Time local node is coordinator since.

#### onContextInitialized0

    protected 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.

#### onContextDestroyed0

    protected void onContextDestroyed0()

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

Overrides:
  `onContextDestroyed0` in class `IgniteSpiAdapter`

#### getSpiContext

    public IgniteSpiContext getSpiContext()

Gets SPI context.

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

#### getLocalNode

    public ClusterNode getLocalNode()

Gets local node.

Specified by:
  `getLocalNode` in interface `DiscoverySpi`
Overrides:
  `getLocalNode` in class `IgniteSpiAdapter`
Returns:
  Local node.

#### setListener

    public void setListener(@Nullable
                   DiscoverySpiListener lsnr)

Sets a listener for discovery events. Refer to `DiscoveryEvent` for a set of all possible discovery events.

Note that as of Ignite 3.0.2 this method is called before method `IgniteSpi.spiStart(String)` is called. This is done to avoid potential window when SPI is started but the listener is not registered yet.

Specified by:
  `setListener` in interface `DiscoverySpi`
Parameters:
  `lsnr` - Listener to discovery events or `null` to unset the listener.

#### setDataExchange

    public TcpDiscoverySpi setDataExchange(DiscoverySpiDataExchange exchange)

Sets a handler for initial data exchange between Ignite nodes.

Specified by:
  `setDataExchange` in interface `DiscoverySpi`
Parameters:
  `exchange` - Discovery data exchange handler.
Returns:
  `this` for chaining.

#### setMetricsProvider

    public TcpDiscoverySpi setMetricsProvider(DiscoveryMetricsProvider metricsProvider)

Sets discovery metrics provider. Use metrics provided by `DiscoveryMetricsProvider.metrics()` method to exchange dynamic metrics between nodes.

Specified by:
  `setMetricsProvider` in interface `DiscoverySpi`
Parameters:
  `metricsProvider` - Provider of metrics data.
Returns:
  `this` for chaining.

#### getGridStartTime

    public long getGridStartTime()

Gets start time of the very first node in the grid. This value should be the same on all nodes in the grid and it should not change even if very first node fails of leaves grid.

Specified by:
  `getGridStartTime` in interface `DiscoverySpi`
Returns:
  Start time of the first node in grid or `0` if SPI implementation does not support this method.

#### openSocket

    protected Socket openSocket(InetSocketAddress sockAddr,
                    IgniteSpiOperationTimeoutHelper timeoutHelper)
                         throws IOException,
                                IgniteSpiOperationTimeoutException

Parameters:
  `sockAddr` - Remote address.
  `timeoutHelper` - Timeout helper.
Returns:
  Opened socket.
Throws:
  `IOException` - If failed.
  `IgniteSpiOperationTimeoutException` - In case of timeout.

#### openSocket

    protected Socket openSocket(Socket sock,
                    InetSocketAddress remAddr,
                    IgniteSpiOperationTimeoutHelper timeoutHelper)
                         throws IOException,
                                IgniteSpiOperationTimeoutException

Connects to remote address sending `U.IGNITE_HEADER` when connection is established.

Parameters:
  `sock` - Socket bound to a local host address.
  `remAddr` - Remote address.
  `timeoutHelper` - Timeout helper.
Returns:
  Connected socket.
Throws:
  `IOException` - If failed.
  `IgniteSpiOperationTimeoutException` - In case of timeout.

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     TcpDiscoveryAbstractMessage msg,
                     byte[] data,
                     long timeout)
                          throws IOException

Writes message to the socket.

Parameters:
  `sock` - Socket.
  `msg` - Message.
  `data` - Raw data to write.
  `timeout` - Socket write timeout.
Throws:
  `IOException` - If IO failed or write timed out.

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     TcpDiscoveryAbstractMessage msg,
                     long timeout)
                          throws IOException,
                                 IgniteCheckedException

Writes message to the socket.

Parameters:
  `sock` - Socket.
  `msg` - Message.
  `timeout` - Socket write timeout.
Throws:
  `IOException` - If IO failed or write timed out.
  `IgniteCheckedException` - If marshalling failed.

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     OutputStream out,
                     TcpDiscoveryAbstractMessage msg,
                     long timeout)
                          throws IOException,
                                 IgniteCheckedException

Writes message to the socket.

Parameters:
  `sock` - Socket.
  `out` - Stream to write to.
  `msg` - Message.
  `timeout` - Timeout.
Throws:
  `IOException` - If IO failed or write timed out.
  `IgniteCheckedException` - If marshalling failed.

#### writeToSocket

    protected void writeToSocket(TcpDiscoveryAbstractMessage msg,
                     Socket sock,
                     int res,
                     long timeout)
                          throws IOException

Writes response to the socket.

Parameters:
  `msg` - Received message.
  `sock` - Socket.
  `res` - Integer response.
  `timeout` - Socket timeout.
Throws:
  `IOException` - If IO failed or write timed out.

#### readMessage

    protected <T> T readMessage(Socket sock,
                    @Nullable
                    InputStream in,
                    long timeout)
                     throws IOException,
                            IgniteCheckedException

Reads message from the socket limiting read time.

Parameters:
  `sock` - Socket.
  `in` - Input stream (in case socket stream was wrapped).
  `timeout` - Socket timeout for this operation.
Returns:
  Message.
Throws:
  `IOException` - If IO failed or read timed out.
  `IgniteCheckedException` - If unmarshalling failed.

#### readReceipt

    protected int readReceipt(Socket sock,
                  long timeout)
                       throws IOException

Reads message delivery receipt from the socket.

Parameters:
  `sock` - Socket.
  `timeout` - Socket timeout for this operation.
Returns:
  Receipt.
Throws:
  `IOException` - If IO failed or read timed out.

#### resolvedAddresses

    protected Collection<InetSocketAddress> resolvedAddresses()
                                                       throws IgniteSpiException

Resolves addresses registered in the IP finder, removes duplicates and local host address and returns the collection of.

Returns:
  Resolved addresses without duplicates and local address (potentially empty but never null).
Throws:
  `IgniteSpiException` - If an error occurs.

#### registeredAddresses

    protected Collection<InetSocketAddress> registeredAddresses()
                                                         throws IgniteSpiException

Gets addresses registered in the IP finder, initializes addresses having no port (or 0 port) with `DFLT_PORT`.

Returns:
  Registered addresses.
Throws:
  `IgniteSpiException` - If an error occurs.

#### duplicateIdError

    protected IgniteSpiException duplicateIdError(TcpDiscoveryDuplicateIdMessage msg)

Parameters:
  `msg` - Message.
Returns:
  Error.

#### authenticationFailedError

    protected IgniteSpiException authenticationFailedError(TcpDiscoveryAuthFailedMessage msg)

Parameters:
  `msg` - Message.
Returns:
  Error.

#### checkFailedError

    protected IgniteSpiException checkFailedError(TcpDiscoveryCheckFailedMessage msg)

Parameters:
  `msg` - Message.
Returns:
  Error.

#### ensured

    protected boolean ensured(TcpDiscoveryAbstractMessage msg)

Parameters:
  `msg` - Message.
Returns:
  Whether delivery of the message is ensured.

#### collectExchangeData

    protected Map<Integer,byte[]> collectExchangeData(UUID nodeId)

Parameters:
  `nodeId` - Node ID.
Returns:
  Marshalled exchange data.

#### onExchange

    protected void onExchange(UUID joiningNodeID,
                  UUID nodeId,
                  Map<Integer,byte[]> data,
                  ClassLoader clsLdr)

Parameters:
  `joiningNodeID` - Joining node ID.
  `nodeId` - Remote node ID for which data is provided.
  `data` - Collection of marshalled discovery data objects from different components.
  `clsLdr` - Class loader.

#### spiStart

    public void spiStart(@Nullable
                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.

#### 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.

#### clientWorkerCount

    public int clientWorkerCount()

FOR TEST ONLY!!!

#### addSendMessageListener

    public void addSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> lsnr)

FOR TEST ONLY!!!

#### removeSendMessageListener

    public void removeSendMessageListener(IgniteInClosure<TcpDiscoveryAbstractMessage> lsnr)

FOR TEST ONLY!!!

#### addIncomeConnectionListener

    public void addIncomeConnectionListener(IgniteInClosure<Socket> lsnr)

FOR TEST ONLY!!!

#### removeIncomeConnectionListener

    public void removeIncomeConnectionListener(IgniteInClosure<Socket> lsnr)

FOR TEST ONLY!!!

#### waitForClientMessagePrecessed

    public void waitForClientMessagePrecessed()

FOR TEST PURPOSE ONLY!

#### simulateNodeFailure

    protected void simulateNodeFailure()

FOR TEST ONLY!!!

Simulates this node failure by stopping service threads. So, node will become unresponsive.

This method is intended for test purposes only.

#### brakeConnection

    public void brakeConnection()

FOR TEST PURPOSE ONLY!

#### marshaller

    protected Marshaller marshaller()

Returns:
  Marshaller.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.8.0
Release Date | : December 5 2016