GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.loadbalancing.coherence
Class GridCoherenceAffinityJobAdapter<A extends Serializable,G extends Serializable>

java.lang.Object
  extended by org.gridgain.grid.GridJobAdapter<G>
      extended by org.gridgain.grid.spi.loadbalancing.coherence.GridCoherenceAffinityJobAdapter<A,G>
Type Parameters:
A - Affinity key type.
G - Job argument type.
All Implemented Interfaces:
Serializable, GridJob, GridCoherenceAffinityJob<A>

public abstract class GridCoherenceAffinityJobAdapter<A extends Serializable,G extends Serializable>
extends GridJobAdapter<G>
implements GridCoherenceAffinityJob<A>

Convenience adapter for GridCoherenceAffinityJob interface that provides default implementation of GridJob.cancel() method and allows to add arguments.

Here is an example of how affinity job is implemented:

 public class MyFooBarCoherenceAffinityJob extends GridCoherenceAffinityJobAdapter<Integer, Serializable> {
    ...                                                                      
    private static final String CACHE_NAME = "myDistributedCache";

    public MyFooBarCoherenceAffinityJob(Integer cacheKey) {
        super(CACHE_NAME, cacheKey);
    }
                                                                             
    public Serializable execute() throws GridException {                     
        ...                                                                  
        // Access data by the same key returned in 'getAffinityKey()' method 
        // and for cache with name returned in 'getCacheName()'.             
        NamedCache mycache = CacheFactory.getCache(getCacheName);              
                                                                             
        mycache.get(getAffinityKey());                                                  
        ...                                                                  
    }                                                                        
 }
 
For complete documentation on how affinity jobs are created and used, refer to GridCoherenceLoadBalancingSpi documentation.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

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

See Also:
Serialized Form
 

Constructor Summary
protected GridCoherenceAffinityJobAdapter()
          No-arg constructor.
protected GridCoherenceAffinityJobAdapter(String cacheName)
          Initializes coherence affinity job with cache name.
protected GridCoherenceAffinityJobAdapter(String cacheName, A affKey)
          Initializes coherence affinity job with cache name.
protected GridCoherenceAffinityJobAdapter(String cacheName, A affKey, G... args)
          Creates fully initialized job with specified cache name, affinity key, and job argument(s).
 
Method Summary
 A getAffinityKey()
          Gets affinity key for this job.
 String getCacheName()
          Gets cache name for this job.
 
Methods inherited from class org.gridgain.grid.GridJobAdapter
addArgument, cancel, getAllArguments, getArgument, getArgument, isCancelled, setArgument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.GridJob
cancel, execute
 

Constructor Detail

GridCoherenceAffinityJobAdapter

protected GridCoherenceAffinityJobAdapter()
No-arg constructor. Note that all fields will be null.

Please use GridJobAdapter.setArgument(Serializable) to set job argument(s), GridCoherenceAffinityJobAdapter.setAffinityKey(Serializable) to set affinity key, and GridCoherenceAffinityJobAdapter.setCacheName(String) to set cache name.


GridCoherenceAffinityJobAdapter

protected GridCoherenceAffinityJobAdapter(String cacheName)
Initializes coherence affinity job with cache name. Note that all other fields will be null.

Please use GridJobAdapter.setArgument(Serializable) to set job argument(s), and GridCoherenceAffinityJobAdapter.setAffinityKey(Serializable) to set affinity key.

Parameters:
cacheName - Coherence cache name.

GridCoherenceAffinityJobAdapter

protected GridCoherenceAffinityJobAdapter(String cacheName,
                                          A affKey)
Initializes coherence affinity job with cache name. Note that all arguments will be null.

Please use GridJobAdapter.setArgument(Serializable) to set job argument(s).

Parameters:
cacheName - Coherence cache name.
affKey - Coherence affinity key.

GridCoherenceAffinityJobAdapter

protected GridCoherenceAffinityJobAdapter(String cacheName,
                                          A affKey,
                                          G... args)
Creates fully initialized job with specified cache name, affinity key, and job argument(s).

Parameters:
cacheName - Coherence cache name.
affKey - Coherence affinity key.
args - Job argument(s).
Method Detail

getCacheName

public String getCacheName()
Gets cache name for this job.

Specified by:
getCacheName in interface GridCoherenceAffinityJob<A extends Serializable>
Returns:
Cache name for this job.

getAffinityKey

public A getAffinityKey()
Description copied from interface: GridCoherenceAffinityJob
Gets affinity key for this job.

Specified by:
getAffinityKey in interface GridCoherenceAffinityJob<A extends Serializable>
Returns:
The affKey.

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.