GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.discovery.jgroups
Class GridJgroupsDiscoverySpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.discovery.jgroups.GridJgroupsDiscoverySpi
All Implemented Interfaces:
GridDiscoverySpi, GridJgroupsDiscoverySpiMBean, GridSpi, GridSpiManagementMBean

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

JGroups implementation of GridDiscoverySpi SPI. It uses JGroups to discover nodes in the grid.

Configuration

Mandatory

This SPI has no mandatory parameters.

Optional

This SPI has the following optional parameters: Note, if you have an OS with IPv6 enabled, Java applications may try to route IP multicast traffic over IPv6. Use "-Djava.net.preferIPv4Stack=true" system property at VM startup to prevent this. You may also wish to specify local bind address in JGroups configuration file to make sure that JGroups binds to correct network interface.

Java Example

GridJgroupsDiscoverySpi needs to be explicitely configured to override default Multicast discovery SPI.
 GridJgroupsDiscoverySpi spi = new GridJgroupsDiscoverySpi();

 // Override default JGroups configuration file.
 spi.setConfigurationFile("/my/config/path/jgroups.xml");

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

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

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

Spring Example

GridJgroupsDiscoverySpi 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.jgroups.GridJgroupsDiscoverySpi">
                 <property name="configurationFile" value="/my/config/path/jgroups.xml"/>
             </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.0.3

See Also:
GridDiscoverySpi
 

Field Summary
static String ATTR_ADDR
          Name of address attribute added to local node attributes at startup (value is grid.disco.jgroups.address).
static String DFLT_CONFIG_FILE
          Default JGroups configuration path relative to GridGain installation home folder (value is config/jgroups/multicast/jgroups.xml).
static String DFLT_GRP_NAME
          Default JGroups group name (value is grid.disco.jgroups.channel).
static long DFLT_JOIN_TIMEOUT
          Default timeout to discover all nodes (value is 10000).
static long DFLT_METRICS_FREQ
          Default metrics heartbeat delay (value is 3000).
static String DFLT_STACK_NAME
          Default JGroups stack name (value is grid.jgroups.stack).
 
Constructor Summary
GridJgroupsDiscoverySpi()
           
 
Method Summary
protected  void checkConfigurationConsistency(GridNode node)
          Checks remote node SPI configuration and prints warnings if necessary.
 String getConfigurationFile()
          Gets either absolute or relative to GridGain installation home folder path to JGroups XML configuration file.
 String getGroupName()
          Gets JGroups group name.
 long getJoinTimeout()
          Gets time limit in milliseconds to wait for message responses from remote nodes.
 String getLocalHost()
          Gets JGroups channel local IP address.
 GridNode getLocalNode()
          Gets local node.
 int getLocalPort()
          Gets JGroups channel local port number.
 long getMetricsFrequency()
          Gets delay between metrics requests.
 GridNode getNode(UUID nodeId)
          Make node search by node id in collection of discovered nodes.
 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.
 List<GridNode> getRemoteNodes()
          Gets collection of remote nodes in grid or empty collection if no remote nodes found.
 String getStackName()
          Gets JGroups stack name.
 boolean pingNode(UUID nodeId)
          Pings the remote node to see if it's alive.
 void setConfigurationFile(String cfgFile)
          Sets either absolute or relative to GridGain installation home folder path to JGroups XML configuration file.
 void setGroupName(String grpName)
          Sets JGroups group name.
 void setJoinTimeout(long joinTimeout)
          Sets time limit in milliseconds to wait for responses from remote nodes.
 void setListener(GridDiscoveryListener listener)
          Sets a listener for discovery events.
 void setMetricsFrequency(long metricsFreq)
          Sets delay between metrics requests.
 void setMetricsProvider(GridDiscoveryMetricsProvider metricsProvider)
          Sets discovery metrics provider.
 void setNodeAttributes(Map<String,Serializable> attrs)
          Sets node attributes which will be distributed in grid during join process.
 void setStackName(String stackName)
          Sets JGroups stack name.
 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, getAuthor, getGridGainHome, getLocalNodeId, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, onContextDestroyed, onContextInitialized, registerMBean, setSpiContext, startInfo, startStopwatch, stopInfo, unregisterMBean, warnSpi, warnSpiParameter
 
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
onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_GRP_NAME

public static final String DFLT_GRP_NAME
Default JGroups group name (value is grid.disco.jgroups.channel).

See Also:
Constant Field Values

DFLT_STACK_NAME

public static final String DFLT_STACK_NAME
Default JGroups stack name (value is grid.jgroups.stack).

See Also:
Constant Field Values

DFLT_JOIN_TIMEOUT

public static final long DFLT_JOIN_TIMEOUT
Default timeout to discover all nodes (value is 10000).

See Also:
Constant Field Values

DFLT_CONFIG_FILE

public static final String DFLT_CONFIG_FILE
Default JGroups configuration path relative to GridGain installation home folder (value is config/jgroups/multicast/jgroups.xml).

See Also:
Constant Field Values

DFLT_METRICS_FREQ

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

See Also:
Constant Field Values

ATTR_ADDR

public static final String ATTR_ADDR
Name of address attribute added to local node attributes at startup (value is grid.disco.jgroups.address).

See Also:
Constant Field Values
Constructor Detail

GridJgroupsDiscoverySpi

public GridJgroupsDiscoverySpi()
Method Detail

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.

getRemoteNodeIds

public Collection<UUID> getRemoteNodeIds()
Gets set of remote nodes' IDs.

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

getRemoteNodeCount

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

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

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.

setConfigurationFile

@GridSpiConfiguration(optional=true)
public void setConfigurationFile(String cfgFile)
Sets either absolute or relative to GridGain installation home folder path to JGroups XML configuration file. This configuration parameter is optional.

If not provided, default value is GridJgroupsDiscoverySpi.DFLT_CONFIG_FILE.

Parameters:
cfgFile - Path to JGroups configuration file.

setJoinTimeout

@GridSpiConfiguration(optional=true)
public void setJoinTimeout(long joinTimeout)
Sets time limit in milliseconds to wait for responses from remote nodes. This configuration parameter is optional.

If not provided, default value is GridJgroupsDiscoverySpi.DFLT_JOIN_TIMEOUT.

Parameters:
joinTimeout - Timeout to wait for responses.

setGroupName

@GridSpiConfiguration(optional=true)
public void setGroupName(String grpName)
Sets JGroups group name. In order to communicate with each other, nodes must have the same group name. This configuration parameter is optional.

If not provided, default value is GridJgroupsDiscoverySpi.DFLT_GRP_NAME.

Parameters:
grpName - JGroups group name.

getStackName

public String getStackName()
Gets JGroups stack name. In order to use multiplexor over the same channel SPIs must have the same stack name. Stack name is a name of configuration in the configuration file.

Specified by:
getStackName in interface GridJgroupsDiscoverySpiMBean
Returns:
JGroups group name.

setStackName

@GridSpiConfiguration(optional=true)
public void setStackName(String stackName)
Sets JGroups stack name. In order to use multiplexor over the same channel SPIs must have the same stack name. Stack name is a name of configuration in the configuration file.

If not provided, default value is GridJgroupsDiscoverySpi.DFLT_STACK_NAME.

Parameters:
stackName - JGroups stack name.

setMetricsFrequency

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

If not provided the default value is GridJgroupsDiscoverySpi.DFLT_METRICS_FREQ.

Parameters:
metricsFreq - Time in milliseconds.

getMetricsFrequency

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

Specified by:
getMetricsFrequency in interface GridJgroupsDiscoverySpiMBean
Returns:
Time period in milliseconds.

getConfigurationFile

public String getConfigurationFile()
Gets either absolute or relative to GridGain installation home folder path to JGroups XML configuration file.

Specified by:
getConfigurationFile in interface GridJgroupsDiscoverySpiMBean
Returns:
Path to JGroups configuration file.

getJoinTimeout

public long getJoinTimeout()
Gets time limit in milliseconds to wait for message responses from remote nodes.

Specified by:
getJoinTimeout in interface GridJgroupsDiscoverySpiMBean
Returns:
Timeout to wait for responses.

getLocalPort

public int getLocalPort()
Gets JGroups channel local port number.

Specified by:
getLocalPort in interface GridJgroupsDiscoverySpiMBean
Returns:
Channel port or -1 if channel is closed or unconnected.

getLocalHost

public String getLocalHost()
Gets JGroups channel local IP address.

Specified by:
getLocalHost in interface GridJgroupsDiscoverySpiMBean
Returns:
Channel address or null if channel is closed or unconnected.

getGroupName

public String getGroupName()
Gets JGroups group name. In order to communicate with each other nodes must have the same group name.

Specified by:
getGroupName in interface GridJgroupsDiscoverySpiMBean
Returns:
JGroups group name.

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.

getLocalNode

public GridNode getLocalNode()
Gets local node.

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

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.

getNode

public GridNode getNode(UUID nodeId)
Make node search by node id in collection of discovered nodes.

Specified by:
getNode in interface GridDiscoverySpi
Parameters:
nodeId - Node id.
Returns:
Jgroups node.

checkConfigurationConsistency

protected void checkConfigurationConsistency(GridNode node)
Checks remote node SPI configuration and prints warnings if necessary.

Overrides:
checkConfigurationConsistency in class GridSpiAdapter
Parameters:
node - Remote node.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 2.0.3
Java API Specification

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