GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.loadbalancing.coherence
Interface GridCoherenceAffinityJob<A>

Type Parameters:
A - Affinity key type.
All Superinterfaces:
GridJob, Serializable
All Known Implementing Classes:
GridCoherenceAffinityJobAdapter

public interface GridCoherenceAffinityJob<A>
extends GridJob

Affinity job which extends GridJob and asks user to implement GridCoherenceAffinityJob.getAffinityKey() and GridCoherenceAffinityJob.getCacheName() methods. Basically the job should know the data it will access and provide the key and Coherence cache name for it to GridGain which will route it to the grid node on which this data is cached.

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

 

Method Summary
 A getAffinityKey()
          Gets affinity key for this job.
 String getCacheName()
          Gets cache name for this job.
 
Methods inherited from interface org.gridgain.grid.GridJob
cancel, execute
 

Method Detail

getAffinityKey

A getAffinityKey()
Gets affinity key for this job.

Returns:
Affinity key for this job.

getCacheName

String getCacheName()
Gets cache name for this job.

Returns:
Cache name for this job.

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.