GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.spi
Interface GridSpiContext


public interface GridSpiContext

SPI context provides common functionality for all SPI implementations.

Wiki & Forum:


Wiki
Forum

 

Method Summary
 void addLocalEventListener(GridLocalEventListener lsnr, int... types)
          Adds an event listener for local events.
 void addMessageListener(GridMessageListener lsnr, String topic)
          Register a message listener to receive messages sent by remote nodes.
<K> boolean
containsKey(String cacheName, K key)
          Returns true if this cache contains a mapping for the specified key.
 void deregisterPort(int port, org.gridgain.grid.kernal.processors.port.GridPortProtocol proto)
          Deregisters closed port.
 void deregisterPorts()
          Deregisters all closed ports.
<K,V> V
get(String cacheName, K key)
          Gets object from cache.
 boolean isEnterprise()
          Tests whether or not this GridGain runtime runs on an enterprise edition.
 GridNode localNode()
          Gets local grid node.
 GridNode node(UUID nodeId)
          Gets a node instance based on its ID.
 Collection<GridNode> nodes()
          Gets a collection of all grid nodes.
 boolean pingNode(UUID nodeId)
          Pings a remote node.
<K,V> V
put(String cacheName, K key, V val, long ttl)
          Puts object in cache.
<K,V> V
putIfAbsent(String cacheName, K key, V val, long ttl)
          Puts object into cache if there was no previous object associated with given key.
<T> T
readFromSwap(String spaceName, Object key, ClassLoader ldr)
          Reads object from swap.
 void recordEvent(GridEvent evt)
          Records local event.
 void registerPort(int port, org.gridgain.grid.kernal.processors.port.GridPortProtocol proto)
          Registers open port.
 Collection<GridNode> remoteNodes()
          Gets a collection of remote grid nodes.
<K,V> V
remove(String cacheName, K key)
          Removes object from cache.
 void removeFromSwap(String spaceName, Object key, ClassLoader ldr)
          Removes object from swap.
 boolean removeLocalEventListener(GridLocalEventListener lsnr)
          Removes local event listener.
 boolean removeMessageListener(GridMessageListener lsnr, String topic)
          Removes a previously registered message listener.
 void send(Collection<? extends GridNode> nodes, Serializable msg, String topic)
          Sends a message to a group of remote nodes.
 void send(GridNode node, Serializable msg, String topic)
          Sends a message to a remote node.
 Collection<? extends GridNode> topology(GridTaskSession taskSes, Collection<? extends GridNode> grid)
          Obtain grid node topology for a given task.
 void writeToSwap(String spaceName, Object key, Object val, ClassLoader ldr)
          Writes object to swap.
 

Method Detail

remoteNodes

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

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

nodes

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

Returns:
Collection of remote grid nodes.
See Also:
GridSpiContext.localNode(), GridSpiContext.remoteNodes(), GridDiscoverySpi

isEnterprise

boolean isEnterprise()
Tests whether or not this GridGain runtime runs on an enterprise edition. This method is primarily for informational purpose.

Returns:
True for enterprise edition, false - for community edition.
See Also:
GridEnterpriseFeatureException, GridEnterpriseOnly

localNode

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

Returns:
Local grid node.
See Also:
GridDiscoverySpi

node

@Nullable
GridNode node(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

send

void send(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.

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.

send

void send(Collection<? extends 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.

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.

addMessageListener

void addMessageListener(GridMessageListener lsnr,
                        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.send(GridNode, Serializable, String) or GridSpiContext.send(Collection, Serializable, String) methods.

Parameters:
lsnr - Message listener to register.
topic - Topic to register listener for.

removeMessageListener

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

Parameters:
lsnr - Message listener to remove.
topic - Topic to unregister listener for.
Returns:
true of message listener was removed, false if it was not previously registered.

addLocalEventListener

void addLocalEventListener(GridLocalEventListener lsnr,
                           int... types)
Adds an event listener for local events.

Parameters:
lsnr - Event listener for local events.
types - Optional types for which this listener will be notified. If no types are provided this listener will be notified for all local events.
See Also:
GridEvent

removeLocalEventListener

boolean removeLocalEventListener(GridLocalEventListener lsnr)
Removes local event listener.

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

topology

Collection<? extends GridNode> topology(GridTaskSession taskSes,
                                        Collection<? extends 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.

recordEvent

void recordEvent(GridEvent evt)
Records local event.

Parameters:
evt - Local grid event to record.

registerPort

void registerPort(int port,
                  org.gridgain.grid.kernal.processors.port.GridPortProtocol proto)
Registers open port.

Parameters:
port - Port.
proto - Protocol.

deregisterPort

void deregisterPort(int port,
                    org.gridgain.grid.kernal.processors.port.GridPortProtocol proto)
Deregisters closed port.

Parameters:
port - Port.
proto - Protocol.

deregisterPorts

void deregisterPorts()
Deregisters all closed ports.


get

@Nullable
<K,V> V get(String cacheName,
                     K key)
      throws GridException
Gets object from cache.

Throws:
GridException - Thrown if any exception occurs.
Parameters:
cacheName - Cache name.
key - Object key.
Returns:
Cached object.

put

@Nullable
<K,V> V put(String cacheName,
                     K key,
                     V val,
                     long ttl)
      throws GridException
Puts object in cache.

Throws:
GridException - Thrown if any exception occurs.
Type Parameters:
K - Key type.
V - Value type.
Parameters:
cacheName - Cache name.
key - Object key.
val - Cached object.
ttl - Time to live, 0 means the entry will never expire.
Returns:
Previous value associated with specified key, possibly null.

putIfAbsent

@Nullable
<K,V> V putIfAbsent(String cacheName,
                             K key,
                             V val,
                             long ttl)
              throws GridException
Puts object into cache if there was no previous object associated with given key.

Throws:
GridException - If put failed.
Type Parameters:
K - Cache key type.
V - Cache value type.
Parameters:
cacheName - Cache name.
key - Cache key.
val - Cache value.
ttl - Time to live.
Returns:
Either existing value or null if there was no value for given key.

remove

@Nullable
<K,V> V remove(String cacheName,
                        K key)
         throws GridException
Removes object from cache.

Throws:
GridException - Thrown if any exception occurs.
Type Parameters:
K - Key type.
V - Value type.
Parameters:
cacheName - Cache name.
key - Object key.
Returns:
Previous value associated with specified key, possibly null.

containsKey

<K> boolean containsKey(String cacheName,
                        K key)
Returns true if this cache contains a mapping for the specified key.

Type Parameters:
K - Key type.
Parameters:
cacheName - Cache name.
key - Object key.
Returns:
true if this cache contains a mapping for the specified key.

writeToSwap

void writeToSwap(String spaceName,
                 Object key,
                 @Nullable
                 Object val,
                 @Nullable
                 ClassLoader ldr)
                 throws GridException
Writes object to swap.

Throws:
GridException - If any exception occurs.
Parameters:
spaceName - Swap space name.
key - Key.
val - Value.
ldr - Class loader (optional).

readFromSwap

@Nullable
<T> T readFromSwap(String spaceName,
                            Object key,
                            @Nullable
                            ClassLoader ldr)
               throws GridException
Reads object from swap.

Throws:
GridException - If any exception occurs.
Parameters:
spaceName - Swap space name.
key - Key.
ldr - Class loader (optional).
Returns:
Swapped value.

removeFromSwap

void removeFromSwap(String spaceName,
                    Object key,
                    @Nullable
                    ClassLoader ldr)
                    throws GridException
Removes object from swap.

Throws:
GridException - If any exception occurs.
Parameters:
spaceName - Swap space name.
key - Key.
ldr - Class loader (optional).

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube