org.apache.ignite.internal.processors.affinity

## Class GridAffinityAssignmentCache

- java.lang.Object
- - org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache

    public class GridAffinityAssignmentCache
    extends Object

Affinity cached function.

### Constructor Summary

Constructors
Constructor and Description
`GridAffinityAssignmentCache(GridCacheContext ctx, String cacheName, AffinityFunction aff, AffinityKeyMapper affMapper, int backups)` Constructs affinity cached calculations.

### Method Summary

Methods
`List<List<ClusterNode>>` `assignments(AffinityTopologyVersion topVer)`
`Set<Integer>` `backupPartitions(UUID nodeId, AffinityTopologyVersion topVer)` Get backup partitions for specified node ID.
`List<List<ClusterNode>>` `calculate(AffinityTopologyVersion topVer, DiscoveryEvent discoEvt)` Calculates affinity cache for given topology version.
`void` `cleanUpCache(AffinityTopologyVersion topVer)` Clean up outdated cache items.
`void` `clientEventTopologyChange(DiscoveryEvent evt, AffinityTopologyVersion topVer)` Copies previous affinity assignment when discovery event does not cause affinity assignment changes (e.g. client node joins on leaves).
`void` `initialize(AffinityTopologyVersion topVer, List<List<ClusterNode>> affAssignment)` Initializes affinity with given topology version and assignment.
`AffinityTopologyVersion` `lastVersion()`
`List<ClusterNode>` `nodes(int part, AffinityTopologyVersion topVer)` Gets affinity nodes for specified partition.
`void` `onKernalStop()` Kernal stop callback.
`int` `partition(Object key)` NOTE: Use this method always when you need to calculate partition id for a key provided by user.
`int` `partitions()`
`Set<Integer>` `primaryPartitions(UUID nodeId, AffinityTopologyVersion topVer)` Get primary partitions for specified node ID.
`IgniteInternalFuture<AffinityTopologyVersion>` `readyFuture(AffinityTopologyVersion topVer)` Gets future that will be completed after topology with version `topVer` is calculated.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GridAffinityAssignmentCache

    public GridAffinityAssignmentCache(GridCacheContext ctx,
                               String cacheName,
                               AffinityFunction aff,
                               AffinityKeyMapper affMapper,
                               int backups)

Constructs affinity cached calculations.

Parameters:
  `ctx` - Kernal context.
  `cacheName` - Cache name.
  `aff` - Affinity function.
  `affMapper` - Affinity key mapper.
  `backups` - Number of backups.

### Method Detail

#### initialize

    public void initialize(AffinityTopologyVersion topVer,
                  List<List<ClusterNode>> affAssignment)

Initializes affinity with given topology version and assignment. The assignment is calculated on remote nodes and brought to local node on partition map exchange.

Parameters:
  `topVer` - Topology version.
  `affAssignment` - Affinity assignment for topology version.

#### onKernalStop

    public void onKernalStop()

Kernal stop callback.

#### calculate

    public List<List<ClusterNode>> calculate(AffinityTopologyVersion topVer,
                                    DiscoveryEvent discoEvt)

Calculates affinity cache for given topology version.

Parameters:
  `topVer` - Topology version to calculate affinity cache for.
  `discoEvt` - Discovery event that caused this topology version change.
Returns:
  Affinity assignments.

#### clientEventTopologyChange

    public void clientEventTopologyChange(DiscoveryEvent evt,
                                 AffinityTopologyVersion topVer)

Copies previous affinity assignment when discovery event does not cause affinity assignment changes (e.g. client node joins on leaves).

Parameters:
  `evt` - Event.
  `topVer` - Topology version.

#### lastVersion

    public AffinityTopologyVersion lastVersion()

Returns:
  Last calculated affinity version.

#### cleanUpCache

    public void cleanUpCache(AffinityTopologyVersion topVer)

Clean up outdated cache items.

Parameters:
  `topVer` - Actual topology version, older versions will be removed.

#### assignments

    public List<List<ClusterNode>> assignments(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Affinity assignment.

#### readyFuture

    @Nullable
    public IgniteInternalFuture<AffinityTopologyVersion> readyFuture(AffinityTopologyVersion topVer)

Gets future that will be completed after topology with version `topVer` is calculated.

Parameters:
  `topVer` - Topology version to await for.
Returns:
  Future that will be completed after affinity for topology version `topVer` is calculated.

#### partitions

    public int partitions()

Returns:
  Partition count.

#### partition

    public int partition(Object key)

NOTE: Use this method always when you need to calculate partition id for a key provided by user. It's required since we should apply affinity mapper logic in order to find a key that will eventually be passed to affinity function.

Parameters:
  `key` - Key.
Returns:
  Partition.

#### nodes

    public List<ClusterNode> nodes(int part,
                          AffinityTopologyVersion topVer)

Gets affinity nodes for specified partition.

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### primaryPartitions

    public Set<Integer> primaryPartitions(UUID nodeId,
                                 AffinityTopologyVersion topVer)

Get primary partitions for specified node ID.

Parameters:
  `nodeId` - Node ID to get primary partitions for.
  `topVer` - Topology version.
Returns:
  Primary partitions for specified node ID.

#### backupPartitions

    public Set<Integer> backupPartitions(UUID nodeId,
                                AffinityTopologyVersion topVer)

Get backup partitions for specified node ID.

Parameters:
  `nodeId` - Node ID to get backup partitions for.
  `topVer` - Topology version.
Returns:
  Backup partitions for specified node ID.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.3.0-incubating
Release Date | : July 10 2015