GridGain™ 2.1.0
Java API Specification

org.gridgain.grid.spi
Interface GridSpiContext


@Apache20LicenseCompatible
public interface GridSpiContext

TODO: add file description.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

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

 

Method Summary
 void addDiscoveryListener(GridDiscoveryListener listener)
          Adds a listener for discovery events.
 void addLocalEventListener(GridLocalEventListener listener)
          Adds an event listener for local events.
 void addMessageListener(GridMessageListener listener, String topic)
          Register a message listener to receive messages sent by remote nodes.
 Collection<GridNode> getAllNodes()
          Gets a collection of all grid nodes.
 GridNode getLocalNode()
          Gets local grid node.
 GridNode getNode(UUID nodeId)
          Gets a node instance based on its ID.
 Collection<GridNode> getRemoteNodes()
          Gets a collection of remote grid nodes.
 Collection<GridNode> getTopology(GridTaskSession taskSes, Collection<GridNode> grid)
          Obtain grid node topology for a given task.
 boolean pingNode(UUID nodeId)
          Pings a remote node.
 boolean removeDiscoveryListener(GridDiscoveryListener listener)
          Removes discovery event listener.
 boolean removeLocalEventListener(GridLocalEventListener listener)
          Removes local event listener.
 boolean removeMessageListener(GridMessageListener listener, String topic)
          Removes a previously registered message listener.
 void sendMessage(Collection<GridNode> nodes, Serializable msg, String topic)
          Sends a message to a group of remote nodes.
 void sendMessage(GridNode node, Serializable msg, String topic)
          Sends a message to a remote node.
 

Method Detail

getRemoteNodes

Collection<GridNode> getRemoteNodes()
Gets a collection of remote grid nodes. Remote nodes are discovered via underlying GridDiscoverySpi implementation used. Unlike GridSpiContext.getAllNodes(), this method does not include local grid node.

Returns:
Collection of remote grid nodes.
See Also:
GridSpiContext.getLocalNode(), GridSpiContext.getAllNodes(), GridDiscoverySpi

getAllNodes

Collection<GridNode> getAllNodes()
Gets a collection of all grid nodes. Remote nodes are discovered via underlying GridDiscoverySpi implementation used. Unlike GridSpiContext.getRemoteNodes(), this method does include local grid node.

Returns:
Collection of remote grid nodes.
See Also:
GridSpiContext.getLocalNode(), GridSpiContext.getRemoteNodes(), GridDiscoverySpi

getLocalNode

GridNode getLocalNode()
Gets local grid node. Instance of local node is provided by underlying GridDiscoverySpi implementation used.

Returns:
Local grid node.
See Also:
GridDiscoverySpi

getNode

GridNode getNode(UUID nodeId)
Gets a node instance based on its ID.

Parameters:
nodeId - ID of a node to get.
Returns:
Node for a given ID or null is such not has not been discovered.
See Also:
GridDiscoverySpi

pingNode

boolean pingNode(UUID nodeId)
Pings a remote node. The underlying communication is provided via GridDiscoverySpi.pingNode(UUID) implementation.

Discovery SPIs usually have some latency in discovering failed nodes. Hence, communication to remote nodes may fail at times if an attempt was made to establish communication with a failed node. This method can be used to check if communication has failed due to node failure or due to some other reason.

Parameters:
nodeId - ID of a node to ping.
Returns:
true if node for a given ID is alive, false otherwise.
See Also:
GridDiscoverySpi

addDiscoveryListener

void addDiscoveryListener(GridDiscoveryListener listener)
Adds a listener for discovery events. Refer to GridDiscoveryEventType for a set of all possible discovery events.

Parameters:
listener - Listener to discovery events.

removeDiscoveryListener

boolean removeDiscoveryListener(GridDiscoveryListener listener)
Removes discovery event listener.

Parameters:
listener - Discovery event listener to remove.
Returns:
True if listener was removed, false otherwise.

sendMessage

void sendMessage(GridNode node,
                 Serializable msg,
                 String topic)
                 throws GridSpiException
Sends a message to a remote node. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can receive messages by registering a listener through GridSpiContext.addMessageListener(GridMessageListener, String) method.

Throws:
GridSpiException - If failed to send a message to remote node.
Parameters:
node - Node to send a message to.
msg - Message to send.
topic - Topic to send message to.
See Also:
GridCommunicationSpi, GridSpiContext.addMessageListener(GridMessageListener, String), GridSpiContext.removeMessageListener(GridMessageListener, String)

sendMessage

void sendMessage(Collection<GridNode> nodes,
                 Serializable msg,
                 String topic)
                 throws GridSpiException
Sends a message to a group of remote nodes. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can receive messages by registering a listener through GridSpiContext.addMessageListener(GridMessageListener, String) method.

Throws:
GridSpiException - If failed to send a message to any of the remote nodes.
Parameters:
nodes - Group of nodes to send a message to.
msg - Message to send.
topic - Topic to send message to.
See Also:
GridCommunicationSpi, GridSpiContext.addMessageListener(GridMessageListener, String), GridSpiContext.removeMessageListener(GridMessageListener, String)

addMessageListener

void addMessageListener(GridMessageListener listener,
                        String topic)
Register a message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can send messages by calling GridSpiContext.sendMessage(GridNode, Serializable, String) or GridSpiContext.sendMessage(Collection, Serializable, String) methods.

Parameters:
listener - Message listener to register.
topic - Topic to register listener for.
See Also:
GridCommunicationSpi, GridSpiContext.sendMessage(GridNode, Serializable, String), GridSpiContext.sendMessage(Collection, Serializable, String), GridSpiContext.removeMessageListener(GridMessageListener, String)

removeMessageListener

boolean removeMessageListener(GridMessageListener listener,
                              String topic)
Removes a previously registered message listener.

Parameters:
listener - Message listener to remove.
topic - Topic to unregister listener for.
Returns:
true of message listener was removed, false if it was not previously registered.
See Also:
GridSpiContext.addMessageListener(GridMessageListener, String)

addLocalEventListener

void addLocalEventListener(GridLocalEventListener listener)
Adds an event listener for local events. Refer to GridEventType for a set of all possible events.

Parameters:
listener - Event listener for local events.
See Also:
GridEventType

removeLocalEventListener

boolean removeLocalEventListener(GridLocalEventListener listener)
Removes local event listener.

Parameters:
listener - Local event listener to remove.
Returns:
true if listener was removed, false otherwise.

getTopology

Collection<GridNode> getTopology(GridTaskSession taskSes,
                                 Collection<GridNode> grid)
                                 throws GridSpiException
Obtain grid node topology for a given task.

Throws:
GridSpiException - If failed to get topology.
Parameters:
taskSes - Task session.
grid - Available grid nodes.
Returns:
Topology for given task session.

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.