GridGain™ 2.1.0
Java API Specification

org.gridgain.grid.spi.discovery.multicast
Class GridMulticastDiscoverySpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.discovery.multicast.GridMulticastDiscoverySpi
All Implemented Interfaces:
GridDiscoverySpi, GridMulticastDiscoverySpiMBean, GridSpi, GridSpiManagementMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.org",
             email="support@gridgain.com",
             version="x.x")
@GridSpiMultipleInstancesSupport(value=true)
public class GridMulticastDiscoverySpi
extends GridSpiAdapter
implements GridDiscoverySpi, GridMulticastDiscoverySpiMBean

Discovery SPI implementation that uses IP-multicast for node discovery. At startup SPI starts sending IP/Multicast heartbeat messages. Once other nodes receive these messages, they use TCP/IP to exchange node attributes and then add the new node to their topology. When a node shuts down, it sends LEAVE heartbeat to other nodes, so every node in the grid can gracefully remove this node from topology.

Note that since IP/Multicast is not a reliable protocol, there is no guarantee that a node will be discovered by other grid members. However, IP/Multicast works very reliably within LANs and in most cases this SPI provides a very light weight and easy to use grid node discovery.

Configuration

Mandatory

This SPI has no mandatory configuration parameters.

Optional

The following configuration parameters are optional:

Java Example

GridMulticastDiscoverySpi is used by default and should be explicitely configured only if some SPI configuration parameters need to be overridden. Examples below insert own multicast group value that differs from default 228.1.2.4.
 GridMulticastDiscoverySpi spi = new GridMulticastDiscoverySpi();

 // Put another multicast group.
 spi.setMulticastGroup("228.10.10.157");

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

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

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

Spring Example

GridMulticastDiscoverySpi can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
         ...
         <property name="discoverySpi">
             <bean class="org.gridgain.grid.spi.discovery.multicast.GridMulticastDiscoverySpi">
                 <property name="multicastGroup" value="228.10.10.157"/>
             </bean>
         </property>
         ...
 </bean>
 


For information about Spring framework visit www.springframework.org



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0

See Also:
GridDiscoverySpi
 

Field Summary
static long DFLT_HEARTBEAT_FREQ
          Default heartbeat delay (value is 3000).
static int DFLT_LEAVE_ATTEMPTS
          Default number of attempts to send leaving notification (value is 3).
static int DFLT_MAX_MISSED_HEARTBEATS
          Default number of heartbeat messages that could be missed (value is 3).
static String DFLT_MCAST_GROUP
          Default multicast IP address (value is 228.1.2.4).
static int DFLT_MCAST_PORT
          Default multicast port number (value is 47200).
static int DFLT_PORT_RANGE
          Default local port range (value is 10).
static int DFLT_TCP_PORT
          Default local port number for SPI (value is 47300).
static int DFLT_TTL
          Default multicast messages time-to-live value (value is 8).
 
Constructor Summary
GridMulticastDiscoverySpi()
           
 
Method Summary
protected  List<String> getConsistentAttributeNames()
          Returns back list of attributes that should be consistent for this SPI.
 long getHeartbeatFrequency()
          Gets delay between heartbeat requests.
 int getLeaveAttempts()
          Gets number of attempts to notify another nodes that this one is leaving grid.
 String getLocalHost()
          Gets local host IP address that discovery SPI uses.
 GridNode getLocalNode()
          Gets local node.
 int getLocalPortRange()
          Gets local port range for either TCP or multicast ports.
 int getMaximumMissedHeartbeats()
          Gets number of heartbeat requests that could be missed before remote node is considered to be failed.
 String getMulticastGroup()
          Gets IP address of multicast group.
 int getMulticastPort()
          Gets port number which multicast messages are sent to.
 GridNode getNode(UUID nodeId)
          Gets node by ID.
 Map<String,Serializable> getNodeAttributes()
          This method is called before SPI starts (before method GridSpi.spiStart(String) is called). It allows SPI implementation to add attributes to a local node. Kernel collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.
 int getRemoteNodeCount()
          Gets the number of remote nodes.
 Collection<UUID> getRemoteNodeIds()
          Gets set of remote nodes IDs that have READY state.
 List<GridNode> getRemoteNodes()
          Gets collection of remote nodes in grid or empty collection if no remote nodes found.
 int getTcpPort()
          Gets local port number that is used by discovery SPI.
 int getTimeToLive()
          Gets TCP messages time-to-live.
 boolean isCheckMulticastEnabled()
          By default this value is true.
 boolean pingNode(UUID nodeId)
          Pings the remote node to see if it's alive.
 void setCheckMulticastEnabled(boolean isCheckMulticastEnabled)
          Enables or disabled check whether multicast is enabled on local node.
 void setHeartbeatFrequency(long beatFreq)
          Sets delay between heartbeat requests.
 void setLeaveAttempts(int leaveAttempts)
          Sets number of attempts to notify another nodes that this one is leaving grid.
 void setListener(GridDiscoveryListener listener)
          Sets a listener for discovery events.
 void setLocalAddress(String localAddr)
          Sets local host IP address that discovery SPI uses.
 void setLocalPortRange(int localPortRange)
          Sets local port range for TCP and Multicast ports (value must greater than or equal to 0).
 void setMaxMissedHeartbeats(int maxMissedBeats)
          Sets number of heartbeat requests that could be missed before remote node is considered to be failed.
 void setMetricsProvider(GridDiscoveryMetricsProvider metricsProvider)
          Sets discovery metrics provider.
 void setMulticastGroup(String mcastGroup)
          Sets IP address of multicast group.
 void setMulticastPort(int mcastPort)
          Sets port number which multicast messages are sent to.
 void setNodeAttributes(Map<String,Serializable> attrs)
          Sets node attributes which will be distributed in grid during join process.
 void setTcpPort(int tcpPort)
          Sets local TCP port number to be used for node attribute exchange upon discovery.
 void setTimeToLive(int ttl)
          Sets Multicast messages time-to-live in router hops.
 void spiStart(String gridName)
          This method is called to start SPI.
 void spiStop()
          This method is called to stop SPI.
 String toString()
          
 
Methods inherited from class org.gridgain.grid.spi.GridSpiAdapter
assertParameter, configInfo, createSpiAttributeName, getAuthor, getGridGainHome, getLocalNodeId, getName, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, onContextDestroyed, onContextInitialized, registerMBean, setName, setSpiContext, 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.gridgain.grid.spi.GridSpi
getName, onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_HEARTBEAT_FREQ

public static final long DFLT_HEARTBEAT_FREQ
Default heartbeat delay (value is 3000).

See Also:
Constant Field Values

DFLT_MAX_MISSED_HEARTBEATS

public static final int DFLT_MAX_MISSED_HEARTBEATS
Default number of heartbeat messages that could be missed (value is 3).

See Also:
Constant Field Values

DFLT_MCAST_GROUP

public static final String DFLT_MCAST_GROUP
Default multicast IP address (value is 228.1.2.4).

See Also:
Constant Field Values

DFLT_MCAST_PORT

public static final int DFLT_MCAST_PORT
Default multicast port number (value is 47200).

See Also:
Constant Field Values

DFLT_TCP_PORT

public static final int DFLT_TCP_PORT
Default local port number for SPI (value is 47300).

See Also:
Constant Field Values

DFLT_PORT_RANGE

public static final int DFLT_PORT_RANGE
Default local port range (value is 10). See GridMulticastDiscoverySpi.setLocalPortRange(int) for details.

See Also:
Constant Field Values

DFLT_LEAVE_ATTEMPTS

public static final int DFLT_LEAVE_ATTEMPTS
Default number of attempts to send leaving notification (value is 3).

See Also:
Constant Field Values

DFLT_TTL

public static final int DFLT_TTL
Default multicast messages time-to-live value (value is 8).

See Also:
Constant Field Values
Constructor Detail

GridMulticastDiscoverySpi

public GridMulticastDiscoverySpi()
Method Detail

setMulticastGroup

@GridSpiConfiguration(optional=true)
public void setMulticastGroup(String mcastGroup)
Sets IP address of multicast group.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_MCAST_GROUP.

Parameters:
mcastGroup - Multicast IP address.

getMulticastGroup

public String getMulticastGroup()
Gets IP address of multicast group.

Specified by:
getMulticastGroup in interface GridMulticastDiscoverySpiMBean
Returns:
Multicast IP address.

setMulticastPort

@GridSpiConfiguration(optional=true)
public void setMulticastPort(int mcastPort)
Sets port number which multicast messages are sent to.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_MCAST_PORT.

Parameters:
mcastPort - Multicast port number.

getMulticastPort

public int getMulticastPort()
Gets port number which multicast messages are sent to.

Specified by:
getMulticastPort in interface GridMulticastDiscoverySpiMBean
Returns:
Port number.

setTcpPort

@GridSpiConfiguration(optional=true)
public void setTcpPort(int tcpPort)
Sets local TCP port number to be used for node attribute exchange upon discovery.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_TCP_PORT.

Parameters:
tcpPort - Port number.

getTcpPort

public int getTcpPort()
Gets local port number that is used by discovery SPI.

Specified by:
getTcpPort in interface GridMulticastDiscoverySpiMBean
Returns:
Port number.

setHeartbeatFrequency

@GridSpiConfiguration(optional=true)
public void setHeartbeatFrequency(long beatFreq)
Sets delay between heartbeat requests. SPI sends broadcast messages in configurable time interval to other nodes to notify them about its state.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_HEARTBEAT_FREQ.

Parameters:
beatFreq - Time in milliseconds.

getHeartbeatFrequency

public long getHeartbeatFrequency()
Gets delay between heartbeat requests. SPI sends broadcast messages in configurable time interval to another nodes to notify them about node state.

Specified by:
getHeartbeatFrequency in interface GridMulticastDiscoverySpiMBean
Returns:
Time period in milliseconds.

setMaxMissedHeartbeats

@GridSpiConfiguration(optional=true)
public void setMaxMissedHeartbeats(int maxMissedBeats)
Sets number of heartbeat requests that could be missed before remote node is considered to be failed.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_MAX_MISSED_HEARTBEATS.

Parameters:
maxMissedBeats - Number of missed requests.

getMaximumMissedHeartbeats

public int getMaximumMissedHeartbeats()
Gets number of heartbeat requests that could be missed before remote node is considered to be failed.

Specified by:
getMaximumMissedHeartbeats in interface GridMulticastDiscoverySpiMBean
Returns:
Number of requests.

setLeaveAttempts

@GridSpiConfiguration(optional=true)
public void setLeaveAttempts(int leaveAttempts)
Sets number of attempts to notify another nodes that this one is leaving grid. Multiple leave requests are sent to increase the chance of successful delivery to every node, since IP Multicast protocol is unreliable. Note that on most networks loss of IP Multicast packets is generally negligible.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_LEAVE_ATTEMPTS.

Parameters:
leaveAttempts - Number of attempts.

getLeaveAttempts

public int getLeaveAttempts()
Gets number of attempts to notify another nodes that this one is leaving grid. It might be impossible to send leaving request and node will try to do it several times.

Specified by:
getLeaveAttempts in interface GridMulticastDiscoverySpiMBean
Returns:
Number of retries.

setLocalAddress

@GridSpiConfiguration(optional=true)
public void setLocalAddress(String localAddr)
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:
localAddr - IP address.

getLocalHost

public String getLocalHost()
Gets local host IP address that discovery SPI uses.

Specified by:
getLocalHost in interface GridMulticastDiscoverySpiMBean
Returns:
IP address.

getTimeToLive

public int getTimeToLive()
Gets TCP messages time-to-live.

Specified by:
getTimeToLive in interface GridMulticastDiscoverySpiMBean
Returns:
TTL.

setTimeToLive

@GridSpiConfiguration(optional=true)
public void setTimeToLive(int ttl)
Sets Multicast messages time-to-live in router hops.

If not provided, default value is GridMulticastDiscoverySpi.DFLT_TTL.

Parameters:
ttl - Messages TTL.

setLocalPortRange

@GridSpiConfiguration(optional=true)
public void setLocalPortRange(int localPortRange)
Sets local port range for TCP and Multicast ports (value must greater than or equal to 0). If provided local port (see GridMulticastDiscoverySpi.setMulticastPort(int) or GridMulticastDiscoverySpi.setTcpPort(int) is occupied, implementation will try to increment the port number for as long as it is less than initial value plus this range.

If port range value is 0, then implementation will try bind only to the port provided by GridMulticastDiscoverySpi.setMulticastPort(int) or GridMulticastDiscoverySpi.setTcpPort(int) methods and fail if binding to these ports did not succeed.

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

Parameters:
localPortRange - New local port range.
See Also:
GridMulticastDiscoverySpi.DFLT_PORT_RANGE

getLocalPortRange

public int getLocalPortRange()
Gets local port range for either TCP or multicast ports. See GridMulticastDiscoverySpi.setLocalPortRange(int) for details.

Specified by:
getLocalPortRange in interface GridMulticastDiscoverySpiMBean
Returns:
Local port range

isCheckMulticastEnabled

public boolean isCheckMulticastEnabled()
By default this value is true. On startup GridGain will check if local node can receive multicast packets, and if not, will not allow the node to startup.

Specified by:
isCheckMulticastEnabled in interface GridMulticastDiscoverySpiMBean
Returns:
checkMulticastEnabled True if multicast check is enabled, false otherwise.

setCheckMulticastEnabled

public void setCheckMulticastEnabled(boolean isCheckMulticastEnabled)
Enables or disabled check whether multicast is enabled on local node. By default this value is true. On startup GridGain will check if local node can receive multicast packets, and if not, will not allow the node to startup.

This property should be disabled in rare cases when loopback multicast is disabled, but multicast to other remote boxes is enabled.

Parameters:
isCheckMulticastEnabled - True for enabling multicast check, false for disabling it.

setNodeAttributes

public void setNodeAttributes(Map<String,Serializable> attrs)
Sets node attributes 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 GridDiscoverySpi
Parameters:
attrs - Map of node attributes.

getRemoteNodes

public List<GridNode> getRemoteNodes()
Gets collection of remote nodes in grid or empty collection if no remote nodes found.

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

getNode

public GridNode getNode(UUID nodeId)
Gets node by ID.

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

getRemoteNodeIds

public Collection<UUID> getRemoteNodeIds()
Gets set of remote nodes IDs that have READY state.

Specified by:
getRemoteNodeIds in interface GridMulticastDiscoverySpiMBean
Returns:
Set of remote nodes IDs.

getRemoteNodeCount

public int getRemoteNodeCount()
Gets the number of remote nodes.

Specified by:
getRemoteNodeCount in interface GridMulticastDiscoverySpiMBean
Returns:
Number of remote nodes.

getLocalNode

public GridNode getLocalNode()
Gets local node.

Specified by:
getLocalNode in interface GridDiscoverySpi
Returns:
Local node.

setListener

public void setListener(GridDiscoveryListener listener)
Sets a listener for discovery events. Refer to GridDiscoveryEventType for a set of all possible discovery events.

Specified by:
setListener in interface GridDiscoverySpi
Parameters:
listener - Listener to discovery events.

setMetricsProvider

public void setMetricsProvider(GridDiscoveryMetricsProvider metricsProvider)
Sets discovery metrics provider. Use metrics provided by GridDiscoveryMetricsProvider.getMetrics() method to exchange dynamic metrics between nodes.

Specified by:
setMetricsProvider in interface GridDiscoverySpi
Parameters:
metricsProvider - Provider of metrics data.

getNodeAttributes

public Map<String,Serializable> getNodeAttributes()
                                           throws GridSpiException
This method is called before SPI starts (before method GridSpi.spiStart(String) is called). It allows SPI implementation to add attributes to a local node. Kernel collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.

Specified by:
getNodeAttributes in interface GridSpi
Overrides:
getNodeAttributes in class GridSpiAdapter
Throws:
GridSpiException - Throws in case of any error.
Returns:
Map of local node attributes this SPI wants to add.

spiStart

public void spiStart(String gridName)
              throws GridSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

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

spiStop

public void spiStop()
             throws GridSpiException
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 GridSpi
Throws:
GridSpiException - Thrown in case of any error during SPI stop.

pingNode

public boolean pingNode(UUID nodeId)
Pings the remote node to see if it's alive.

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

getConsistentAttributeNames

protected List<String> getConsistentAttributeNames()
Returns back list of attributes that should be consistent for this SPI. Consistency means that remote node has to have the same attribute with the same value.

Overrides:
getConsistentAttributeNames in class GridSpiAdapter
Returns:
List or attribute names.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 2.1.0
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.