GridGain™ 4.3.1e
Enterprise "Big Data" Edition

org.gridgain.grid
Interface GridJobContext

All Superinterfaces:
GridJobContinuation, GridMetadataAware, Serializable

public interface GridJobContext
extends GridJobContinuation, GridMetadataAware

Context attached to every job executed on the grid. Note that unlike GridTaskSession, which distributes all attributes to all jobs in the task including the task itself, job context attributes belong to a job and do not get sent over network unless a job moves from one node to another.

In most cases a job, once assigned to a node, will never move to another node. However, it is possible that collision SPI rejects a job before it ever got a chance to execute (job rejection) which will cause fail-over to another node. Or user is not satisfied with the outcome of a job and fails it over to another node by returning GridJobResultPolicy.FAILOVER policy from GridTask.result(GridJobResult, List) method. In this case all context attributes set on one node will be available on any other node this job travels to.

You can also use GridJobContext to communicate between SPI's and jobs. For example, if you need to cancel an actively running job from GridCollisionSpi you may choose to set some context attribute on the job to mark the fact that a job was cancelled by grid and not by a user. Context attributes can also be assigned in GridFailoverSpi prior to failing over a job.

From within GridTask.result(GridJobResult, List) or GridTask.reduce(List) methods, job context is available via GridJobResult.getJobContext() method which gives user the ability to check context attributes from within grid task implementation for every job returned from remote nodes.

Job context can be injected into GridJob via GridJobContextResource annotation. Refer to the GridJobContextResource documentation for coding examples on how to inject job context.

Attribute names that start with "gridgain:" are reserved for internal system use.

 

Method Summary
<T> T
affinityKey()
          Gets affinity key with which job was co-located.
 String cacheName()
          Gets cache name for which job was co-located.
<K,V> V
getAttribute(K key)
          Gets attribute from this job context.
 Map<?,?> getAttributes()
          Gets all attributes present in this job context.
 GridUuid getJobId()
          Gets ID of the job this context belongs to.
 void setAttribute(Object key, Object val)
          Sets an attribute into this job context.
 void setAttributes(Map<?,?> attrs)
          Sets map of attributes into this job context.
 
Methods inherited from interface org.gridgain.grid.GridJobContinuation
callcc, heldcc, holdcc, holdcc
 
Methods inherited from interface org.gridgain.grid.GridMetadataAware
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, removeMeta, removeMeta, replaceMeta
 

Method Detail

cacheName

String cacheName()
Gets cache name for which job was co-located.

Returns:
Cache name if job was co-located or null otherwise.
See Also:
GridJobContext.affinityKey(), GridProjection.affinityCall(String, Collection, Callable, GridPredicate[]), GridProjection.affinityCall(String, Object, Callable, GridPredicate[]), GridProjection.affinityCallAsync(String, Object, Callable, GridPredicate[]), GridProjection.affinityCallAsync(String, Object, Callable, GridPredicate[]), GridProjection.affinityRun(String, Collection, Runnable, GridPredicate[]), GridProjection.affinityRun(String, Object, Runnable, GridPredicate[]), GridProjection.affinityRunAsync(String, Collection, Runnable, GridPredicate[]), GridProjection.affinityRunAsync(String, Collection, Runnable, GridPredicate[])

affinityKey

<T> T affinityKey()
Gets affinity key with which job was co-located.

Returns:
Affinity key if job was co-located or null otherwise.
See Also:
GridJobContext.cacheName(), GridProjection.affinityCall(String, Collection, Callable, GridPredicate[]), GridProjection.affinityCall(String, Object, Callable, GridPredicate[]), GridProjection.affinityCallAsync(String, Object, Callable, GridPredicate[]), GridProjection.affinityCallAsync(String, Object, Callable, GridPredicate[]), GridProjection.affinityRun(String, Collection, Runnable, GridPredicate[]), GridProjection.affinityRun(String, Object, Runnable, GridPredicate[]), GridProjection.affinityRunAsync(String, Collection, Runnable, GridPredicate[]), GridProjection.affinityRunAsync(String, Collection, Runnable, GridPredicate[])

getJobId

GridUuid getJobId()
Gets ID of the job this context belongs to.

Returns:
ID of the job this context belongs to.

setAttribute

void setAttribute(Object key,
                  @Nullable
                  Object val)
Sets an attribute into this job context.

Parameters:
key - Attribute key.
val - Attribute value.

setAttributes

void setAttributes(Map<?,?> attrs)
Sets map of attributes into this job context.

Parameters:
attrs - Local attributes.

getAttribute

<K,V> V getAttribute(K key)
Gets attribute from this job context.

Type Parameters:
K - Type of the attribute key.
V - Type of the attribute value.
Parameters:
key - Attribute key.
Returns:
Attribute value (possibly null).

getAttributes

Map<?,?> getAttributes()
Gets all attributes present in this job context.

Returns:
All attributes.

GridGain™ 4.3.1e
Enterprise "Big Data" Edition

GridGain - In-Memory Big Data
Enterprise "Big Data" Edition, ver. 4.3.1e.10112012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Join GridGain User Group Follow GridGain on Twitter Follow GridGain on Vimeo