GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.communication.jgroups
Class GridJgroupsCommunicationSpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.communication.jgroups.GridJgroupsCommunicationSpi
All Implemented Interfaces:
GridCommunicationSpi, GridJgroupsCommunicationSpiMBean, GridSpi, GridSpiManagementMBean

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

JGroups implementation of GridCommunicationSpi SPI. It uses JGroups to communicate with one or more other nodes.

This SPI has no mandatory parameters.

Configuration

Mandatory

This SPI has no mandatory configuration parameters.

Optional

This SPI has the following optional configuration 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

GridJgroupsCommunicationSpi needs to be explicitely configured to override default TCP communication SPI.
 GridJgroupsCommunicationSpi commSpi = new GridJgroupsCommunicationSpi();

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

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override default communication SPI.
 cfg.setCommunicationSpi(commSpi);

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

Spring Example

GridJgroupsCommunicationSpi can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
         ...
         <property name="communicationSpi">
             <bean class="org.gridgain.grid.spi.communication.jgroups.GridJgroupsCommunicationSpi">
                 <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:
GridCommunicationSpi
 

Field Summary
static String ATTR_ADDR
          Name of address attribute added to local node attributes at startup (value is grid.comm.jgroups.address).
static String DFLT_CONFIG_FILE
          Default JGroups configuration path relative to GridGain installation home folder.
static String DFLT_GRP_NAME
          Default JGroups group name (value is grid.comm.jgroups.channel).
static long DFLT_SEND_TIMEOUT
          Default timeout for message acknowledgments (value is 10000).
static String DFLT_STACK_NAME
          Default JGroups stack name (value is grid.jgroups.stack).
 
Constructor Summary
GridJgroupsCommunicationSpi()
           
 
Method Summary
 String getConfigurationFile()
          Gets either absolute or relative to GridGain installation home folder path to JGroups XML configuration file.
 String getGroupName()
          Gets JGroups group name.
 InetAddress getLocalAddress()
          Gets JGroups channel local IP address.
 int getLocalPort()
          Gets JGroups channel local port number.
 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.
 long getSendTimeout()
          Gets time limit in milliseconds to wait for message acknowledgements from remote nodes.
 String getStackName()
          Gets JGroups stack name.
 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...

 void sendMessage(Collection<GridNode> destNodes, Serializable msg)
          Sends given message to destination nodes.
 void sendMessage(GridNode destNode, Serializable msg)
          Sends given message to destination node.
 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 setListener(GridMessageListener listener)
          Set communication listener.
 void setSendTimeout(long sendTimeout)
          Sets time limit in milliseconds to wait for message acknowledgements from remote nodes.
 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, checkConfigurationConsistency, 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_GRP_NAME

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

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.comm.jgroups.address).

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_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_SEND_TIMEOUT

public static final long DFLT_SEND_TIMEOUT
Default timeout for message acknowledgments (value is 10000).

See Also:
Constant Field Values
Constructor Detail

GridJgroupsCommunicationSpi

public GridJgroupsCommunicationSpi()
Method Detail

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 GridJgroupsCommunicationSpi.DFLT_CONFIG_FILE.

Parameters:
cfgFile - Path to JGroups configuration file.

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 GridJgroupsCommunicationSpiMBean
Returns:
Path to JGroups configuration file.

getLocalAddress

public InetAddress getLocalAddress()
Gets JGroups channel local IP address.

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

getLocalPort

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

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

setSendTimeout

@GridSpiConfiguration(optional=true)
public void setSendTimeout(long sendTimeout)
Sets time limit in milliseconds to wait for message acknowledgements from remote nodes. This configuration parameter is optional.

If not provided, default value is GridJgroupsCommunicationSpi.DFLT_SEND_TIMEOUT.

Parameters:
sendTimeout - Timeout to wait for responses.

getSendTimeout

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

Specified by:
getSendTimeout in interface GridJgroupsCommunicationSpiMBean
Returns:
Timeout to wait for responses.

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 GridJgroupsCommunicationSpiMBean
Returns:
JGroups group name.

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.

If not provided, default value is GridJgroupsCommunicationSpi.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 GridJgroupsCommunicationSpiMBean
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 GridJgroupsCommunicationSpi.DFLT_STACK_NAME.

Parameters:
stackName - JGroups stack name.

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.

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.

sendMessage

public void sendMessage(GridNode destNode,
                        Serializable msg)
                 throws GridSpiException
Sends given message to destination node. Note that characteristics of the exchange such as durability, guaranteed delivery or error notification is dependant on SPI implementation.

Specified by:
sendMessage in interface GridCommunicationSpi
Throws:
GridSpiException - Thrown in case of any error during sending the message. Note that this is not guaranteed that failed communication will result in thrown exception as this is dependant on SPI implementation.
Parameters:
destNode - Destination node.
msg - Message to send.

sendMessage

public void sendMessage(Collection<GridNode> destNodes,
                        Serializable msg)
                 throws GridSpiException
Sends given message to destination nodes. Note that characteristics of the exchange such as durability, guaranteed delivery or error notification is dependant on SPI implementation.

Specified by:
sendMessage in interface GridCommunicationSpi
Throws:
GridSpiException - Thrown in case of any error during sending the message. Note that this is not guaranteed that failed communication will result in thrown exception as this is dependant on SPI implementation.
Parameters:
destNodes - Destination nodes.
msg - Message to send.

setListener

public void setListener(GridMessageListener listener)
Set communication listener.

Specified by:
setListener in interface GridCommunicationSpi
Parameters:
listener - Listener to set or null to unset the listener.

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.