GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.discovery.coherence
Class GridCoherenceDiscoverySpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.discovery.coherence.GridCoherenceDiscoverySpi
All Implemented Interfaces:
GridCoherenceDiscoverySpiMBean, GridDiscoverySpi, GridSpi, GridSpiManagementMBean

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

Oracle Coherence implementation of GridDiscoverySpi SPI. It uses Coherence cluster capabilities discover remote nodes in grid. SPI works with Coherence distributed cache named GridCoherenceDiscoverySpi.DFLT_GRIDGAIN_CACHE and every node in the cluster works with that cache to communicate with other remote nodes.

All grid nodes have information about Coherence cluster members they are associated with in attribute by name GridCoherenceDiscoverySpi.ATTR_COHERENCE_MBR. Use GridNode.getAttribute(ATTR_COHERENCE_MBR) to get a handle on GridCoherenceMember class.

Configuration

Mandatory

This SPI has no mandatory configuration parameters.

Optional

This SPI has the following optional parameters:

Java Example

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

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

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

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

Spring Example

GridCoherenceDiscoverySpi 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.coherence.GridCoherenceDiscoverySpi"/>
         </property>
         ...
 </bean>
 

Note: Coherence is not shipped with GridGain. If you don't have Coherence, you need to download it separately. See http://www.oracle.com/tangosol/index.html for more information. Once installed, Coherence should be available on the classpath for GridGain. If you use [GRIDGAIN_HOME]/bin/gridgain.{sh|bat} script to start a grid node you can simply add Coherence JARs to [GRIDGAIN_HOME]/bin/setenv.{sh|bat} scripts that's used to set up class path for the main scripts.

Note: When using Coherence SPIs (communication or discovery) you cannot start multiple GridGain instances in the same VM due to limitations of Coherence. GridGain runtime will detect this situation and prevent GridGain from starting in such case. See GridSpiMultipleInstancesSupport for details.


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_COHERENCE_CACHE_NAME
          Name of Coherence cache used by SPI (value is disco.coherence.cache).
static String ATTR_COHERENCE_MBR
          Name of cluster GridCoherenceMember attribute added to local node attributes at startup (value is disco.coherence.member).
static String DFLT_GRIDGAIN_CACHE
          Default Coherence cache name (value is gridgain.discovery.cache).
static long DFLT_METRICS_FREQ
          Default metrics heartbeat delay (value is 3000).
 
Constructor Summary
GridCoherenceDiscoverySpi()
           
 
Method Summary
protected  void checkConfigurationConsistency(GridNode node)
          Checks remote node SPI configuration and prints warnings if necessary.
 String getCacheName()
          Gets Coherence cache name.
 GridNode getLocalNode()
          Gets local node.
 long getMetricsFrequency()
          Gets delay between metrics requests.
 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 number of remote nodes.
 Collection<UUID> getRemoteNodeIds()
          Gets set of discovered remote nodes IDs.
 List<GridNode> getRemoteNodes()
          Gets collection of remote nodes in grid or empty collection if no remote nodes found.
 void onContextInitialized(GridSpiContext spiCtx)
          Callback invoked when SPI context is initialized. SPI implementation may store SPI context for future access.

This method is invoked after GridSpi.spiStart(String) method is completed, so SPI should be fully functional at this point. Use this method for post-start initialization, such as subscribing a discovery listener, sending a message to remote node, etc...

 boolean pingNode(UUID nodeId)
          Pings the remote node to see if it's alive.
 void setCacheName(String cacheName)
          Sets name for Coherence cache used in grid.
 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 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, 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
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_GRIDGAIN_CACHE

public static final String DFLT_GRIDGAIN_CACHE
Default Coherence cache name (value is gridgain.discovery.cache).

See Also:
Constant Field Values

ATTR_COHERENCE_MBR

public static final String ATTR_COHERENCE_MBR
Name of cluster GridCoherenceMember attribute added to local node attributes at startup (value is disco.coherence.member).

See Also:
Constant Field Values

ATTR_COHERENCE_CACHE_NAME

public static final String ATTR_COHERENCE_CACHE_NAME
Name of Coherence cache used by SPI (value is disco.coherence.cache).

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
Constructor Detail

GridCoherenceDiscoverySpi

public GridCoherenceDiscoverySpi()
Method Detail

setCacheName

@GridSpiConfiguration(optional=true)
public void setCacheName(String cacheName)
Sets name for Coherence cache used in grid.

If not provided, default value is GridCoherenceDiscoverySpi.DFLT_GRIDGAIN_CACHE.

Parameters:
cacheName - Cache name.

getCacheName

public String getCacheName()
Gets Coherence cache name.

Specified by:
getCacheName in interface GridCoherenceDiscoverySpiMBean
Returns:
Coherence cache 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 GridCoherenceDiscoverySpi.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 GridCoherenceDiscoverySpiMBean
Returns:
Time period in milliseconds.

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 discovered remote nodes IDs.

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

getRemoteNodeCount

public int getRemoteNodeCount()
Gets number of remote nodes.

Specified by:
getRemoteNodeCount in interface GridCoherenceDiscoverySpiMBean
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.

onContextInitialized

public void onContextInitialized(GridSpiContext spiCtx)
                          throws GridSpiException
Callback invoked when SPI context is initialized. SPI implementation may store SPI context for future access.

This method is invoked after GridSpi.spiStart(String) method is completed, so SPI should be fully functional at this point. Use this method for post-start initialization, such as subscribing a discovery listener, sending a message to remote node, etc...

Specified by:
onContextInitialized in interface GridSpi
Overrides:
onContextInitialized in class GridSpiAdapter
Throws:
GridSpiException - If context initialization failed (grid will be stopped).
Parameters:
spiCtx - Spi context.

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.

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.