org.apache.ignite.internal.processors.cache

## Class GridCacheAffinityManager

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter
  - - org.apache.ignite.internal.processors.cache.GridCacheAffinityManager

All Implemented Interfaces:
  GridCacheManager

    public class GridCacheAffinityManager
    extends GridCacheManagerAdapter

Cache affinity manager.

### Field Summary

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter

`cctx, log`

### Constructor Summary

Constructors
Constructor and Description
`GridCacheAffinityManager()`

### Method Summary

Methods
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuture(AffinityTopologyVersion topVer)` Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuture(long topVer)` Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuturex(AffinityTopologyVersion topVer)` Gets affinity ready future that will be completed after affinity with given topology version is calculated.
`AffinityTopologyVersion` `affinityTopologyVersion()`
`List<List<ClusterNode>>` `assignments(AffinityTopologyVersion topVer)`
`boolean` `backup(ClusterNode n, int part, AffinityTopologyVersion topVer)`
`Set<Integer>` `backupPartitions(UUID nodeId, AffinityTopologyVersion topVer)`
`Collection<ClusterNode>` `backups(int part, AffinityTopologyVersion topVer)`
`Collection<ClusterNode>` `backups(Object key, AffinityTopologyVersion topVer)`
`boolean` `belongs(ClusterNode node, int part, AffinityTopologyVersion topVer)`
`List<List<ClusterNode>>` `calculateAffinity(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` `dumpDebugInfo()` Dumps debug information.
`void` `initializeAffinity(AffinityTopologyVersion topVer, List<List<ClusterNode>> affAssignment)` Initializes affinity for joined node.
`boolean` `localNode(int part, AffinityTopologyVersion topVer)`
`boolean` `localNode(Object key, AffinityTopologyVersion topVer)`
`List<ClusterNode>` `nodes(int part, AffinityTopologyVersion topVer)`
`List<ClusterNode>` `nodes(Object key, AffinityTopologyVersion topVer)`
`void` `onDisconnected(IgniteFuture reconnectFut)`
`protected void` `onKernalStart0()`
`protected void` `onKernalStop0(boolean cancel)`
`void` `onReconnected()`
`int` `partition(Object key)` NOTE: Use this method always when you need to calculate partition id for a key provided by user.
`int` `partitions()`
`boolean` `primary(ClusterNode n, int part, AffinityTopologyVersion topVer)`
`boolean` `primary(ClusterNode n, Object key, AffinityTopologyVersion topVer)`
`ClusterNode` `primary(int part, AffinityTopologyVersion topVer)`
`ClusterNode` `primary(Object key, AffinityTopologyVersion topVer)`
`Set<Integer>` `primaryPartitions(UUID nodeId, AffinityTopologyVersion topVer)`
`Collection<ClusterNode>` `remoteNodes(Iterable keys, AffinityTopologyVersion topVer)`
`void` `start0()`
`protected void` `stop0(boolean cancel)`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter

`context, kernalStartInfo, kernalStopInfo, log, onKernalStart, onKernalStop, printMemoryStats, start, startInfo, stop, stopInfo, toString`

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

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

### Constructor Detail

#### GridCacheAffinityManager

    public GridCacheAffinityManager()

### Method Detail

#### start0

    public void start0()
                throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### onKernalStart0

    protected void onKernalStart0()
                           throws IgniteCheckedException

Overrides:
  `onKernalStart0` in class `GridCacheManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### onKernalStop0

    protected void onKernalStop0(boolean cancel)

Overrides:
  `onKernalStop0` in class `GridCacheManagerAdapter`
Parameters:
  `cancel` - Cancel flag.

#### onDisconnected

    public void onDisconnected(IgniteFuture reconnectFut)

Specified by:
  `onDisconnected` in interface `GridCacheManager`
Overrides:
  `onDisconnected` in class `GridCacheManagerAdapter`
Parameters:
  `reconnectFut` - Reconnect future.

#### onReconnected

    public void onReconnected()

#### stop0

    protected void stop0(boolean cancel)

Overrides:
  `stop0` in class `GridCacheManagerAdapter`
Parameters:
  `cancel` - Cancel flag.

#### affinityReadyFuture

    public IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuture(long topVer)

Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.

Parameters:
  `topVer` - Topology version to wait.
Returns:
  Affinity ready future.

#### affinityReadyFuture

    public IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuture(AffinityTopologyVersion topVer)

Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.

Parameters:
  `topVer` - Topology version to wait.
Returns:
  Affinity ready future.

#### affinityReadyFuturex

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

Gets affinity ready future that will be completed after affinity with given topology version is calculated. Will return `null` if topology with given version is ready by the moment method is invoked.

Parameters:
  `topVer` - Topology version to wait.
Returns:
  Affinity ready future or `null`.

#### cleanUpCache

    public void cleanUpCache(AffinityTopologyVersion topVer)

Clean up outdated cache items.

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

#### initializeAffinity

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

Initializes affinity for joined node.

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

#### assignments

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

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

#### calculateAffinity

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

Calculates affinity cache for given topology version.

Parameters:
  `topVer` - Topology version to calculate affinity for.
  `discoEvt` - Discovery event that causes this topology 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.

#### 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(Object key,
                          AffinityTopologyVersion topVer)

Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### nodes

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

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

#### primary

    @Nullable
    public ClusterNode primary(Object key,
                               AffinityTopologyVersion topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Primary node for given key.

#### primary

    @Nullable
    public ClusterNode primary(int part,
                               AffinityTopologyVersion topVer)

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Primary node for given key.

#### primary

    public boolean primary(ClusterNode n,
                  Object key,
                  AffinityTopologyVersion topVer)

Parameters:
  `n` - Node to check.
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  `True` if checked node is primary for given key.

#### primary

    public boolean primary(ClusterNode n,
                  int part,
                  AffinityTopologyVersion topVer)

Parameters:
  `n` - Node to check.
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  `True` if checked node is primary for given partition.

#### backups

    public Collection<ClusterNode> backups(Object key,
                                  AffinityTopologyVersion topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Backup nodes.

#### backups

    public Collection<ClusterNode> backups(int part,
                                  AffinityTopologyVersion topVer)

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

#### backup

    public boolean backup(ClusterNode n,
                 int part,
                 AffinityTopologyVersion topVer)

Parameters:
  `n` - Node to check.
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  `True` if checked node is a backup node for given partition.

#### remoteNodes

    public Collection<ClusterNode> remoteNodes(Iterable keys,
                                      AffinityTopologyVersion topVer)

Parameters:
  `keys` - keys.
  `topVer` - Topology version.
Returns:
  Nodes for the keys.

#### localNode

    public boolean localNode(Object key,
                    AffinityTopologyVersion topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  `true` if given key belongs to local node.

#### localNode

    public boolean localNode(int part,
                    AffinityTopologyVersion topVer)

Parameters:
  `part` - Partition number to check.
  `topVer` - Topology version.
Returns:
  `true` if given partition belongs to local node.

#### belongs

    public boolean belongs(ClusterNode node,
                  int part,
                  AffinityTopologyVersion topVer)

Parameters:
  `node` - Node.
  `part` - Partition number to check.
  `topVer` - Topology version.
Returns:
  `true` if given partition belongs to specified node.

#### primaryPartitions

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

Parameters:
  `nodeId` - Node ID.
  `topVer` - Topology version to calculate affinity.
Returns:
  Partitions for which given node is primary.

#### backupPartitions

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

Parameters:
  `nodeId` - Node ID.
  `topVer` - Topology version to calculate affinity.
Returns:
  Partitions for which given node is backup.

#### affinityTopologyVersion

    public AffinityTopologyVersion affinityTopologyVersion()

Returns:
  Affinity-ready topology version.

#### dumpDebugInfo

    public void dumpDebugInfo()

Dumps debug information.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0.final
Release Date | : December 29 2015