org.apache.ignite.spi.discovery.tcp

## Class TcpClientDiscoverySpi

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

All Implemented Interfaces:
  DiscoverySpi, TcpClientDiscoverySpiMBean, IgniteSpi, IgniteSpiManagementMBean

    @IgniteSpiMultipleInstancesSupport(value=true)
    @DiscoverySpiOrderSupport(value=true)
    @DiscoverySpiHistorySupport(value=true)
    public class TcpClientDiscoverySpi
    extends IgniteSpiAdapter
    implements TcpClientDiscoverySpiMBean

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

This discovery SPI requires at least on server node configured with `TcpDiscoverySpi`. It will try to connect to random IP taken from `TcpDiscoveryIpFinder` which should point to one of these server nodes and will maintain connection only with this node (will not enter the ring). If this connection is broken, it will try to reconnect using addresses from the same IP finder.

### Field Summary

Fields
`protected long` `ackTimeout` Message acknowledgement timeout.
`static long` `DFLT_ACK_TIMEOUT` Default timeout for receiving message acknowledgement in milliseconds (value is `200ms`).
`static long` `DFLT_DISCONNECT_CHECK_INT` Default disconnect check interval.
`static long` `DFLT_HEARTBEAT_FREQ` Default heartbeat messages issuing frequency (value is `300ms`).
`static long` `DFLT_NETWORK_TIMEOUT` Default network timeout in milliseconds (value is `200ms`).
`static int` `DFLT_PORT` Default port to listen (value is `47500`).
`static long` `DFLT_SOCK_TIMEOUT` Default socket operations timeout in milliseconds (value is `200ms`).
`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 TcpDiscoveryIpFinder` `ipFinder` IP finder.
`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 IgniteLogger` `log` Logger.
`protected DiscoverySpiListener` `lsnr` Grid discovery listener.
`protected Marshaller` `marsh` Marshaller.
`protected DiscoveryMetricsProvider` `metricsProvider` Metrics provider.
`protected long` `netTimeout` Network timeout.
`protected static int` `RES_CONTINUE_JOIN` Response CONTINUE JOIN.
`protected static int` `RES_OK` Response OK.
`protected static int` `RES_WAIT` Response WAIT.
`protected long` `sockTimeout` Socket operations timeout.
`protected org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpiAdapter.SocketTimeoutWorker` `sockTimeoutWorker` Socket timeout worker.
`protected TcpDiscoverySpiState` `spiState` Discovery state.
`protected TcpDiscoveryStatistics` `stats` Statistics.
`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, nodeId`

### Constructor Summary

Constructors
Constructor and Description
`TcpClientDiscoverySpi()`

### Method Summary

Methods
`protected IgniteSpiException` `authenticationFailedError(TcpDiscoveryAuthFailedMessage msg)`
`protected IgniteSpiException` `checkFailedError(TcpDiscoveryCheckFailedMessage msg)`
`void` `disconnect()` Tells discovery SPI to disconnect from topology.
`protected IgniteSpiException` `duplicateIdError(TcpDiscoveryDuplicateIdMessage msg)`
`protected boolean` `ensured(TcpDiscoveryAbstractMessage msg)`
`void` `failNode(UUID nodeId)` Initiates failure of provided node.
`long` `getAckTimeout()` Gets message acknowledgement timeout.
`long` `getAvgMessageProcessingTime()` Gets avg message processing time.
`long` `getDisconnectCheckInterval()` Gets disconnect check interval.
`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.
`String` `getIpFinderFormatted()` Gets `TcpDiscoveryIpFinder` (string representation).
`String` `getLocalAddress()` Gets local address that was set to SPI with `setLocalAddress(String)` method.
`ClusterNode` `getLocalNode()` Gets local node.
`long` `getMaxMessageProcessingTime()` Gets max message processing time.
`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.
`Map<String,Integer>` `getProcessedMessages()` Gets processed messages counts (grouped by type).
`Map<String,Integer>` `getReceivedMessages()` Gets received messages counts (grouped by type).
`Collection<ClusterNode>` `getRemoteNodes()` Gets collection of remote nodes in grid or empty collection if no remote nodes found.
`long` `getSocketTimeout()` Gets socket timeout.
`int` `getThreadPriority()` Gets thread priority.
`long` `getTopHistorySize()`
`int` `getTotalProcessedMessages()` Gets total processed messages count.
`int` `getTotalReceivedMessages()` Gets total received messages count.
`Collection<Object>` `injectables()` This method returns SPI internal instances that need to be injected as well.
`protected void` `injectResources(Ignite ignite)` Inject resources
`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)`
`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`.
`protected Collection<InetSocketAddress>` `resolvedAddresses()` Resolves addresses registered in the IP finder, removes duplicates and local host address and returns the collection of.
`void` `sendCustomEvent(Serializable evt)` Sends custom message across the ring.
`void` `setAckTimeout(long ackTimeout)` Sets timeout for receiving acknowledgement for sent message.
`void` `setAuthenticator(DiscoverySpiNodeAuthenticator auth)` Sets discovery SPI node authenticator.
`void` `setDataExchange(DiscoverySpiDataExchange exchange)` Sets a handler for initial data exchange between Ignite nodes.
`void` `setDisconnectCheckInterval(long disconnectCheckInt)` Sets disconnect check interval.
`void` `setHeartbeatFrequency(long hbFreq)` Sets delay between issuing of heartbeat messages.
`void` `setIpFinder(TcpDiscoveryIpFinder ipFinder)` Sets IP finder for IP addresses sharing and storing.
`void` `setListener(DiscoverySpiListener lsnr)` Sets a listener for discovery events.
`void` `setLocalAddress(String locAddr)` Sets local host IP address that discovery SPI uses.
`void` `setMetricsProvider(DiscoveryMetricsProvider metricsProvider)` Sets discovery metrics provider.
`void` `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.
`void` `setSocketTimeout(long sockTimeout)` Sets socket operations timeout.
`void` `setThreadPriority(int threadPri)` Sets thread priority.
`void` `setTopHistorySize(int topHistSize)` Sets size of topology snapshots history.
`void` `spiStart(String gridName)` This method is called to start SPI.
`void` `spiStop()` This method is called to stop SPI.
`protected void` `writeToSocket(Socket sock, byte[] data)` Writes message to the socket.
`protected void` `writeToSocket(Socket sock, int res)` Writes response to the socket.
`protected void` `writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg)` Writes message to the socket.
`protected void` `writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, GridByteArrayOutputStream bout)` Writes message to the socket.

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

`assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getConsistentAttributeNames, getExceptionRegistry, getIgniteHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, isNodeStopping, onContextDestroyed, onContextInitialized, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBean`

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

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

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

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

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

`getName, getNodeAttributes, onContextDestroyed, onContextInitialized`

### Field Detail

#### DFLT_DISCONNECT_CHECK_INT

    public static final long DFLT_DISCONNECT_CHECK_INT

Default disconnect check interval.

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_SOCK_TIMEOUT

    public static final long DFLT_SOCK_TIMEOUT

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

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 `200ms`).

See Also:
  Constant Field Values

#### DFLT_NETWORK_TIMEOUT

    public static final long DFLT_NETWORK_TIMEOUT

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

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 `300ms`).

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

#### RES_OK

    protected static final int RES_OK

Response OK.

See Also:
  Constant Field Values

#### RES_CONTINUE_JOIN

    protected static final int RES_CONTINUE_JOIN

Response CONTINUE JOIN.

See Also:
  Constant Field Values

#### RES_WAIT

    protected static final int RES_WAIT

Response WAIT.

See Also:
  Constant Field Values

#### locAddr

    protected String locAddr

Local address.

#### ipFinder

    protected TcpDiscoveryIpFinder ipFinder

IP finder.

#### sockTimeout

    protected long sockTimeout

Socket operations timeout.

#### ackTimeout

    protected long ackTimeout

Message acknowledgement timeout.

#### netTimeout

    protected long netTimeout

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

#### locHost

    protected InetAddress locHost

Local host.

#### locNodeAddrs

    protected Collection<InetSocketAddress> locNodeAddrs

Internal and external addresses of local node.

#### sockTimeoutWorker

    protected org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpiAdapter.SocketTimeoutWorker sockTimeoutWorker

Socket timeout worker.

#### spiState

    protected TcpDiscoverySpiState spiState

Discovery state.

#### gridStartTime

    protected volatile long gridStartTime

Start time of the very first grid node.

#### marsh

    protected final Marshaller marsh

Marshaller.

#### stats

    protected final TcpDiscoveryStatistics stats

Statistics.

#### log

    @LoggerResource
    protected IgniteLogger log

Logger.

### Constructor Detail

#### TcpClientDiscoverySpi

    public TcpClientDiscoverySpi()

### Method Detail

#### getDisconnectCheckInterval

    public long getDisconnectCheckInterval()

Gets disconnect check interval.

Specified by:
  `getDisconnectCheckInterval` in interface `TcpClientDiscoverySpiMBean`
Returns:
  Disconnect check interval.

#### setDisconnectCheckInterval

    @IgniteSpiConfiguration(optional=true)
    public void setDisconnectCheckInterval(long disconnectCheckInt)

Sets disconnect check interval.

Parameters:
  `disconnectCheckInt` - Disconnect check interval.

#### getSocketTimeout

    public long getSocketTimeout()

Gets socket timeout.

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

#### getAckTimeout

    public long getAckTimeout()

Gets message acknowledgement timeout.

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

#### getNetworkTimeout

    public long getNetworkTimeout()

Gets network timeout.

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

#### getThreadPriority

    public int getThreadPriority()

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

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

#### getHeartbeatFrequency

    public long getHeartbeatFrequency()

Gets delay between heartbeat messages sent by coordinator.

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

#### getIpFinderFormatted

    public String getIpFinderFormatted()

Gets `TcpDiscoveryIpFinder` (string representation).

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

#### getMessageWorkerQueueSize

    public int getMessageWorkerQueueSize()

Gets message worker queue current size.

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

#### getNodesJoined

    public long getNodesJoined()

Gets joined nodes count.

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

#### getNodesLeft

    public long getNodesLeft()

Gets left nodes count.

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

#### getNodesFailed

    public long getNodesFailed()

Gets failed nodes count.

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

#### getAvgMessageProcessingTime

    public long getAvgMessageProcessingTime()

Gets avg message processing time.

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

#### getMaxMessageProcessingTime

    public long getMaxMessageProcessingTime()

Gets max message processing time.

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

#### getTotalReceivedMessages

    public int getTotalReceivedMessages()

Gets total received messages count.

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

#### getReceivedMessages

    public Map<String,Integer> getReceivedMessages()

Gets received messages counts (grouped by type).

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

#### getTotalProcessedMessages

    public int getTotalProcessedMessages()

Gets total processed messages count.

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

#### getProcessedMessages

    public Map<String,Integer> getProcessedMessages()

Gets processed messages counts (grouped by type).

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

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

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

#### 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(Serializable evt)

Sends custom message across the ring.

Specified by:
  `sendCustomEvent` in interface `DiscoverySpi`
Parameters:
  `evt` - Event.

#### failNode

    public void failNode(UUID nodeId)

Initiates failure of provided node.

Specified by:
  `failNode` in interface `DiscoverySpi`
Parameters:
  `nodeId` - Node ID.

#### injectResources

    @IgniteInstanceResource
    protected void injectResources(Ignite ignite)

Inject resources

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

#### setLocalAddress

    @IgniteSpiConfiguration(optional=true)
    public void 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.

#### getLocalAddress

    public String getLocalAddress()

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

Returns:
  local address.

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

#### setSocketTimeout

    @IgniteSpiConfiguration(optional=true)
    public void 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`.

Parameters:
  `sockTimeout` - Socket connection timeout.

#### setAckTimeout

    @IgniteSpiConfiguration(optional=true)
    public void 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`.

Parameters:
  `ackTimeout` - Acknowledgement timeout.

#### setNetworkTimeout

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

Sets maximum network timeout to use for network operations.

If not specified, default is `DFLT_NETWORK_TIMEOUT`.

Parameters:
  `netTimeout` - Network timeout.

#### setThreadPriority

    @IgniteSpiConfiguration(optional=true)
    public void 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.

#### setHeartbeatFrequency

    @IgniteSpiConfiguration(optional=true)
    public void 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.

#### getTopHistorySize

    public long getTopHistorySize()

Returns:
  Size of topology snapshots history.

#### setTopHistorySize

    @IgniteSpiConfiguration(optional=true)
    public void 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.

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

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

#### getLocalNode

    public ClusterNode getLocalNode()

Gets local node.

Specified by:
  `getLocalNode` in interface `DiscoverySpi`
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 void 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.

#### setMetricsProvider

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

#### 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)
                         throws IOException

Parameters:
  `sockAddr` - Remote address.
Returns:
  Opened socket.
Throws:
  `IOException` - If failed.

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     byte[] data)
                          throws IOException

Writes message to the socket.

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

#### writeToSocket

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

Writes message to the socket.

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

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     TcpDiscoveryAbstractMessage msg,
                     GridByteArrayOutputStream bout)
                          throws IOException,
                                 IgniteCheckedException

Writes message to the socket.

Parameters:
  `sock` - Socket.
  `msg` - Message.
  `bout` - Byte array output stream.
Throws:
  `IOException` - If IO failed or write timed out.
  `IgniteCheckedException` - If marshalling failed.

#### writeToSocket

    protected void writeToSocket(Socket sock,
                     int res)
                          throws IOException

Writes response to the socket.

Parameters:
  `sock` - Socket.
  `res` - Integer response.
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.

#### 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 for discovery data unmarshalling.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.1.0-incubating
Release Date | : May 20 2015