GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi.loadbalancing.affinity
Interface GridAffinityJob<A>

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

public interface GridAffinityJob<A>
extends GridJob

Affinity job which extends GridJob and adds GridAffinityJob.getAffinityKey() method. Basically the job should know the data it will access and provide the key for it to GridGain which will route it to the grid node on which this data is cached.

Note that if GridAffinityLoadBalancingSpi will receive regular GridJob instead of GridAffinityJob, then a random available node will be picked.

Here is an example of how affinity job is implemented:

 public class MyGridAffinityJob extends GridAffinityJobAdapter<Integer, Serializable> {
    public MyGridAffinityJob(Integer cacheKey) {
        // Pass cache key as a job argument.
        super(cacheKey);
    }

    public Serializable execute() throws GridException {
        ...
        // Access data by the same key returned
        // in 'getAffinityKey()' method.
        mycache.get(getAffinityKey());
        ...
    }
 }
 

Here is another example on how it can be used from task map (or split) method.

 public class MyFooBarAffinityTask extends GridTaskSplitAdapter<List<Integer>,Object> {
    // For this example we receive a list of cache keys and for every key
    // create a job that accesses it.
    @Override
    protected Collection<? extends GridJob> split(int gridSize, List<Integer> cacheKeys) throws GridException {
        List<MyGridAffinityJob> jobs = new ArrayList<MyGridAffinityJob>(gridSize);
 
        for (Integer cacheKey : cacheKeys) {
            jobs.add(new MyGridAffinityJob(cacheKey));
        }

        // Node assignment via load balancer 
        // happens automatically.
        return jobs;
    }
    ...
 }
 
For complete documentation on how affinity jobs are created and used, refer to GridAffinityLoadBalancingSpi 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.
 
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.

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.