Click on Javadoc link to open Javadoc documentation.
Package
org.gridgain.grid.spi.communication Javadoc![]()
Built-in Implementations
Gridgain comes with following communication SPI's supported out of the box.
- GridCoherenceCommunicationSpi
- GridJgroupsCommunicationSpi
- GridJmsCommunicationSpi
- GridMailCommuncationSpi
- GridMuleCommunicationSpi
- GridTcpCommunicationSpi
Description
GridCommunicationSpi Javadoc
enables communication between different nodes within grid. It provides basic plumbing to send and receive grid messages and is utilized for all distributed grid operations, such as task execution, monitoring data exchange, distributed even querying and others.
To send and receive messages from public API, the following public methods are available
- Grid.sendMessage(GridNode, Serializable) Javadoc

- Grid.sendMessage(Collection<GridNode>, Serializable) Javadoc

- Grid.addMessageListener(GridMessageListener) Javadoc

- Grid.removeMessageListener(GridMessageListener) Javadoc

Note that messages can only be received asynchronously by registering GridMessageListener Javadoc
with Grid Javadoc
interface.
Usage
Here is an example of how to send and receive messages using public Grid ![]()
Grid grid = GridFactory.getGrid(); grid.addMessageListener(new GridMessageListener() { /** * @see GridMessageListener#onMessage(UUID,Serializable) */ public void onMessage(UUID nodeId, Serializable msg) { System.out.println("Received message: " + msg); } )); // Send message to itself. grid.sendMessage(grid.getLocalNode(), "TEST");
GridConfiguration
GridCommunicationSpi is provided in Grid Configuration passed into GridFactory Javadoc
at startup. By default GridTcpCommunicationSpi is used. You can configure a different communication SPI implementation as follows
GridConfigurationAdapter cfg = new GridConfigurationAdapter(); // Configure grid to use JGroups communication layer. cfg.setCommunicationSpi(new GridJgroupsCommunicationSpi()); GridFactory.start(cfg);
Note that GridConfiguration interface is just a bean and can also be configured using spring XML configuration.
Default Implementation
If no communication SPI is provided in configuration by default GridTcpCommunicationSpi is used.


