@GridSpiMultipleInstancesSupport(value=true) @GridDiscoverySpiOrderSupport(value=true) @GridDiscoverySpiReconnectSupport(value=true) @GridDiscoverySpiHistorySupport(value=true) public class GridTcpDiscoverySpi extends GridSpiAdapter implements GridDiscoverySpi, GridTcpDiscoverySpiMBean
Nodes are organized in ring. So almost all network exchange (except few cases) is done across it.
At startup SPI tries to send messages to random IP taken from
GridTcpDiscoveryIpFinder 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.
setIpFinder(GridTcpDiscoveryIpFinder)).
See the following IP finder implementations for details on configuration:
GridTcpDiscoverySharedFsIpFinderGridTcpDiscoveryS3IpFinderGridTcpDiscoveryJdbcIpFinderGridTcpDiscoveryVmIpFinderGridTcpDiscoveryMulticastIpFinder - defaultsetMetricsStore(GridTcpDiscoveryMetricsStore))GridTcpDiscoverySharedFsMetricsStoreGridTcpDiscoveryS3MetricsStoreGridTcpDiscoveryJdbcMetricsStoreGridTcpDiscoveryVmMetricsStoresetLocalAddress(String))setLocalPort(int))setLocalPortRange(int))setHeartbeatFrequency(long))setMaxMissedHeartbeats(int))setReconnectCount(int))setNetworkTimeout(long))setSocketTimeout(long))setAckTimeout(long))setMaxAckTimeout(long))setJoinTimeout(long))setThreadPriority(int))setStoresCleanFrequency(long))setStatisticsPrintFrequency(long)
GridTcpDiscoverySpi spi = new GridTcpDiscoverySpi();
GridTcpDiscoveryVmIpFinder finder =
new GridTcpDiscoveryVmIpFinder();
spi.setIpFinder(finder);
GridConfiguration cfg = new GridConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
// Start grid.
GridGain.start(cfg);
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true">
...
<property name="discoverySpi">
<bean class="org.gridgain.grid.spi.discovery.tcp.GridTcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.gridgain.grid.spi.discovery.tcp.ipfinder.vm.GridTcpDiscoveryVmIpFinder" />
</property>
</bean>
</property>
...
</bean>
For information about Spring framework visit www.springframework.org
GridDiscoverySpi| Modifier and Type | Field and Description |
|---|---|
static String |
ATTR_EXT_ADDRS
Node attribute that is mapped to node's external addresses (value is disc.tcp.ext-addrs).
|
static long |
DFLT_ACK_TIMEOUT
Default timeout for receiving message acknowledgement in milliseconds (value is 5,000ms).
|
static long |
DFLT_HEARTBEAT_FREQ
Default heartbeat messages issuing frequency (value is 2,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_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 5,000ms).
|
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 2,000ms).
|
static long |
DFLT_STATS_PRINT_FREQ
Default statistics print frequency in milliseconds (value is 0ms).
|
static long |
DFLT_STORES_CLEAN_FREQ
Default stores (IP finder clean and metrics store) frequency in milliseconds (value is 60,000ms).
|
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.
|
| Constructor and Description |
|---|
GridTcpDiscoverySpi() |
| Modifier and Type | Method and Description |
|---|---|
void |
disconnect()
Tells discovery SPI to disconnect from topology.
|
long |
getAckTimeout()
Gets message acknowledgement timeout.
|
GridAddressResolver |
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.
|
GridTcpDiscoveryIpFinder |
getIpFinder()
Gets IP finder for IP addresses sharing and storing.
|
String |
getIpFinderFormatted()
Gets
GridTcpDiscoveryIpFinder (string representation). |
long |
getJoinTimeout()
Gets join timeout.
|
String |
getLocalAddress()
Gets local address that was set to SPI with
setLocalAddress(String) method. |
GridNode |
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 |
getMaxMissedHeartbeats()
Gets max heartbeats count node can miss without initiating status check.
|
int |
getMessageWorkerQueueSize()
Gets message worker queue current size.
|
String |
getMetricsStoreFormatted()
Gets
GridTcpDiscoveryMetricsStore (string representation). |
long |
getNetworkTimeout()
Gets network timeout.
|
GridNode |
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<GridNode> |
getRemoteNodes()
Gets collection of remote nodes in grid or empty collection if no remote nodes found.
|
long |
getSocketTimeout()
Gets socket timeout.
|
protected GridSpiContext |
getSpiContext()
Gets SPI context.
|
String |
getSpiState()
Gets current SPI state.
|
long |
getStatisticsPrintFrequency()
Gets statistics print frequency.
|
long |
getStoresCleanFrequency()
Gets stores (IP finder and metrics store) clean frequency.
|
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 |
onContextDestroyed0()
Method to be called in the beginning of onContextDestroyed() method.
|
void |
onContextInitialized0(GridSpiContext spiCtx)
Method to be called in the end of onContextInitialized method.
|
boolean |
pingNode(UUID nodeId)
Pings the remote node to see if it's alive.
|
void |
reconnect()
Tells discovery SPI to reconnect to topology.
|
void |
setAckTimeout(long ackTimeout)
Sets timeout for receiving acknowledgement for sent message.
|
void |
setAddressResolver(GridAddressResolver addrRslvr)
Sets address resolver.
|
void |
setAuthenticator(GridDiscoverySpiNodeAuthenticator nodeAuth)
Sets discovery SPI node authenticator.
|
void |
setDataExchange(GridDiscoverySpiDataExchange exchange)
Sets a handler for initial data exchange between GridGain nodes.
|
void |
setHeartbeatFrequency(long hbFreq)
Sets delay between issuing of heartbeat messages.
|
void |
setIpFinder(GridTcpDiscoveryIpFinder ipFinder)
Sets IP finder for IP addresses sharing and storing.
|
void |
setJoinTimeout(long joinTimeout)
Sets join timeout.
|
void |
setListener(GridDiscoverySpiListener lsnr)
Sets a listener for discovery events.
|
void |
setLocalAddress(String locAddr)
Sets local host IP address that discovery SPI uses.
|
void |
setLocalPort(int locPort)
Sets local port to listen to.
|
void |
setLocalPortRange(int locPortRange)
Range for local ports.
|
void |
setMaxAckTimeout(long maxAckTimeout)
Sets maximum timeout for receiving acknowledgement for sent message.
|
void |
setMaxMissedHeartbeats(int maxMissedHbs)
Sets max heartbeats count node can miss without initiating status check.
|
void |
setMetricsProvider(GridDiscoveryMetricsProvider metricsProvider)
Sets discovery metrics provider.
|
void |
setMetricsStore(GridTcpDiscoveryMetricsStore metricsStore)
Sets metrics store.
|
void |
setNetworkTimeout(long netTimeout)
Sets maximum network timeout to use for network operations.
|
void |
setNodeAttributes(Map<String,Object> attrs,
GridProductVersion ver)
Sets node attributes and node version which will be distributed in grid during
join process.
|
void |
setReconnectCount(int reconCnt)
Number of times node tries to (re)establish connection to another node.
|
void |
setSocketTimeout(long sockTimeout)
Sets socket operations timeout.
|
void |
setStatisticsPrintFrequency(long statsPrintFreq)
Sets statistics print frequency.
|
void |
setStoresCleanFrequency(long storesCleanFreq)
Sets stores (IP finder and metrics store) clean frequency in milliseconds.
|
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.
|
String |
toString() |
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, onContextDestroyed, onContextInitialized, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBeanclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getNodeAttributes, onContextDestroyed, onContextInitializedgetGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormattedpublic static final int DFLT_PORT
public static final int DFLT_PORT_RANGE
public static final long DFLT_NETWORK_TIMEOUT
public static final long DFLT_SOCK_TIMEOUT
public static final long DFLT_ACK_TIMEOUT
public static final long DFLT_JOIN_TIMEOUT
public static final int DFLT_RECONNECT_CNT
public static final long DFLT_HEARTBEAT_FREQ
public static final int DFLT_MAX_MISSED_HEARTBEATS
public static final int DFLT_THREAD_PRI
public static final long DFLT_STORES_CLEAN_FREQ
public static final long DFLT_STATS_PRINT_FREQ
public static final long DFLT_MAX_ACK_TIMEOUT
public static final int DFLT_TOP_HISTORY_SIZE
public static final String ATTR_EXT_ADDRS
@GridSpiConfiguration(optional=true) @GridLocalHostResource public void setLocalAddress(String locAddr)
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.
locAddr - IP address.public String getLocalAddress()
setLocalAddress(String) method.@GridSpiConfiguration(optional=true) @GridAddressResolverResource public void setAddressResolver(GridAddressResolver addrRslvr)
addrRslvr - Address resolver.public GridAddressResolver getAddressResolver()
public int getReconnectCount()
getReconnectCount in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setReconnectCount(int reconCnt)
Note that SPI implementation will increase ackTimeout by factor 2
on every retry.
If not specified, default is DFLT_RECONNECT_CNT.
reconCnt - Number of retries during message sending.setAckTimeout(long)public long getNetworkTimeout()
getNetworkTimeout in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setTopHistorySize(int topHistSize)
DFLT_TOP_HISTORY_SIZE.topHistSize - Size of topology snapshots history.public long getTopHistorySize()
@GridSpiConfiguration(optional=true) public void setNetworkTimeout(long netTimeout)
If not specified, default is DFLT_NETWORK_TIMEOUT.
netTimeout - Network timeout.public long getAckTimeout()
getAckTimeout in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setAckTimeout(long ackTimeout)
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.
ackTimeout - Acknowledgement timeout.public long getMaxAckTimeout()
getMaxAckTimeout in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setMaxAckTimeout(long maxAckTimeout)
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.
maxAckTimeout - Maximum acknowledgement timeout.public long getSocketTimeout()
getSocketTimeout in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setSocketTimeout(long sockTimeout)
Note that when running GridGain 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.
sockTimeout - Socket connection timeout.public long getJoinTimeout()
getJoinTimeout in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setJoinTimeout(long joinTimeout)
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.
joinTimeout - Join timeout (0 means wait forever).GridTcpDiscoveryIpFinder.isShared()public int getLocalPort()
getLocalPort in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setLocalPort(int locPort)
If not specified, default is DFLT_PORT.
locPort - Local port to bind.public int getLocalPortRange()
getLocalPortRange in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setLocalPortRange(int locPortRange)
getLocalPort() up until
getLocalPort() + locPortRange.
If not specified, default is DFLT_PORT_RANGE.
locPortRange - Local port range to bind.public long getHeartbeatFrequency()
getHeartbeatFrequency in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setHeartbeatFrequency(long hbFreq)
If not provided, default value is DFLT_HEARTBEAT_FREQ.
hbFreq - Heartbeat frequency in milliseconds.public int getMaxMissedHeartbeats()
getMaxMissedHeartbeats in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setMaxMissedHeartbeats(int maxMissedHbs)
If not provided, default value is DFLT_MAX_MISSED_HEARTBEATS.
maxMissedHbs - Max missed heartbeats.public long getStatisticsPrintFrequency()
getStatisticsPrintFrequency in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setStatisticsPrintFrequency(long statsPrintFreq)
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.
statsPrintFreq - Statistics print frequency in milliseconds.public GridTcpDiscoveryIpFinder getIpFinder()
@GridSpiConfiguration(optional=true) public void setIpFinder(GridTcpDiscoveryIpFinder ipFinder)
If not provided GridTcpDiscoveryMulticastIpFinder will be used by default.
ipFinder - IP finder.public int getThreadPriority()
getThreadPriority in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setThreadPriority(int threadPri)
If not provided, default value is DFLT_THREAD_PRI
threadPri - Thread priority.public long getStoresCleanFrequency()
getStoresCleanFrequency in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setStoresCleanFrequency(long storesCleanFreq)
If not provided, default value is DFLT_STORES_CLEAN_FREQ
storesCleanFreq - Stores clean frequency.public String getSpiState()
getSpiState in interface GridTcpDiscoverySpiMBeanpublic String getIpFinderFormatted()
GridTcpDiscoveryIpFinder (string representation).getIpFinderFormatted in interface GridTcpDiscoverySpiMBean@Nullable public String getMetricsStoreFormatted()
GridTcpDiscoveryMetricsStore (string representation).getMetricsStoreFormatted in interface GridTcpDiscoverySpiMBeannull if SPI
does not use metrics store.public int getMessageWorkerQueueSize()
getMessageWorkerQueueSize in interface GridTcpDiscoverySpiMBeanpublic long getNodesJoined()
getNodesJoined in interface GridTcpDiscoverySpiMBeanpublic long getNodesLeft()
getNodesLeft in interface GridTcpDiscoverySpiMBeanpublic long getNodesFailed()
getNodesFailed in interface GridTcpDiscoverySpiMBeanpublic long getPendingMessagesRegistered()
getPendingMessagesRegistered in interface GridTcpDiscoverySpiMBeanpublic long getPendingMessagesDiscarded()
getPendingMessagesDiscarded in interface GridTcpDiscoverySpiMBeanpublic long getAvgMessageProcessingTime()
getAvgMessageProcessingTime in interface GridTcpDiscoverySpiMBeanpublic long getMaxMessageProcessingTime()
getMaxMessageProcessingTime in interface GridTcpDiscoverySpiMBeanpublic int getTotalReceivedMessages()
getTotalReceivedMessages in interface GridTcpDiscoverySpiMBeanpublic Map<String,Integer> getReceivedMessages()
getReceivedMessages in interface GridTcpDiscoverySpiMBeanpublic int getTotalProcessedMessages()
getTotalProcessedMessages in interface GridTcpDiscoverySpiMBeanpublic Map<String,Integer> getProcessedMessages()
getProcessedMessages in interface GridTcpDiscoverySpiMBeanpublic long getCoordinatorSinceTimestamp()
getCoordinatorSinceTimestamp in interface GridTcpDiscoverySpiMBean@Nullable public UUID getCoordinator()
getCoordinator in interface GridTcpDiscoverySpiMBean@GridSpiConfiguration(optional=true) public void setMetricsStore(GridTcpDiscoveryMetricsStore metricsStore)
If provided, SPI does not send metrics across the ring and uses metrics store to exchange metrics. It is recommended to provide metrics store when working with large topologies.
metricsStore - Metrics store.public GridNode getLocalNode()
getLocalNode in interface GridDiscoverySpi@Nullable public GridNode getNode(UUID nodeId)
getNode in interface GridDiscoverySpinodeId - Node ID.null if node is not found.public Collection<GridNode> getRemoteNodes()
getRemoteNodes in interface GridDiscoverySpipublic void setListener(GridDiscoverySpiListener lsnr)
GridDiscoveryEvent for a set of all possible
discovery events.
Note that as of GridGain 3.0.2 this method is called before
method GridSpi.spiStart(String) is called. This is done to
avoid potential window when SPI is started but the listener is
not registered yet.
setListener in interface GridDiscoverySpilsnr - Listener to discovery events or null to unset the listener.public void setDataExchange(GridDiscoverySpiDataExchange exchange)
setDataExchange in interface GridDiscoverySpiexchange - Discovery data exchange handler.public void setMetricsProvider(GridDiscoveryMetricsProvider metricsProvider)
GridDiscoveryMetricsProvider.getMetrics() method to exchange
dynamic metrics between nodes.setMetricsProvider in interface GridDiscoverySpimetricsProvider - Provider of metrics data.public void setNodeAttributes(Map<String,Object> attrs, GridProductVersion ver)
setNodeAttributes in interface GridDiscoverySpiattrs - Map of node attributes.ver - Product version.public Collection<Object> injectables()
injectables in class GridSpiAdapterpublic void spiStart(String gridName) throws GridSpiException
spiStart in interface GridSpigridName - Name of grid instance this SPI is being started for
(null for default grid).GridSpiException - Throws in case of any error during SPI start.public void onContextInitialized0(GridSpiContext spiCtx) throws GridSpiException
onContextInitialized0 in class GridSpiAdapterspiCtx - SPI context.GridSpiException - In case of errors.protected GridSpiContext getSpiContext()
getSpiContext in class GridSpiAdapterpublic void spiStop()
throws GridSpiException
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.
spiStop in interface GridSpiGridSpiException - Thrown in case of any error during SPI stop.protected void onContextDestroyed0()
onContextDestroyed0 in class GridSpiAdapterpublic boolean pingNode(UUID nodeId)
pingNode in interface GridDiscoverySpinodeId - Node Id.true if node alive, false otherwise.public void disconnect()
throws GridSpiException
GridSpi.spiStop() with accounting that it is not a full stop,
but disconnect before reconnect (i.e. some internal threads and
resources may be preserved on disconnect and reused on reconnect again).disconnect in interface GridDiscoverySpiGridSpiException - If any error occurs.GridDiscoverySpi.reconnect()public void reconnect()
throws GridSpiException
GridSpi.spiStart(String) with accounting that it is not a full start,
but reconnect (i.e. some internal threads and resources may be preserved
on disconnect and reused on reconnect again).
Prior to calling this method manager will ensure, that it is in the correct network segment.
reconnect in interface GridDiscoverySpiGridSpiException - If any error occurs.GridDiscoverySpi.disconnect()public void setAuthenticator(GridDiscoverySpiNodeAuthenticator nodeAuth)
setAuthenticator in interface GridDiscoverySpinodeAuth - Discovery SPI authenticator.public long getGridStartTime()
getGridStartTime in interface GridDiscoverySpi0 if SPI implementation
does not support this method.Copyright © 2014. All rights reserved.