org.apache.ignite.internal.client

## Class GridClientPartitionAffinity

- java.lang.Object
- - org.apache.ignite.internal.client.GridClientPartitionAffinity

All Implemented Interfaces:
  GridClientDataAffinity, GridClientTopologyListener

    public class GridClientPartitionAffinity
    extends Object
    implements GridClientDataAffinity, GridClientTopologyListener

Affinity function for partitioned cache. This function supports the following configuration:

- `backupFilter` - Optional filter for back up nodes. If provided, then only nodes that pass this filter will be selected as backup nodes and only nodes that don't pass this filter will be selected as primary nodes. If not provided, then primary and backup nodes will be selected out of all nodes available for this cache.

  NOTE: In situations where there are no primary nodes at all, i.e. no nodes for which backup filter returns `false`, first backup node for the key will be considered primary.

### Nested Class Summary

Nested Classes
`static interface` `GridClientPartitionAffinity.HashIdResolver` This resolver is used to provide alternate hash ID, other than node ID.

### Field Summary

Fields
`static int` `DFLT_PARTITION_CNT` Default number of partitions.

### Constructor Summary

Constructors
Constructor and Description
`GridClientPartitionAffinity()` Empty constructor with all defaults.
`GridClientPartitionAffinity(Integer parts, GridClientPredicate<UUID> backupFilter)` Initializes optional counts for replicas and backups.

### Method Summary

Methods
`GridClientPredicate<UUID>` `getBackupFilter()` Gets optional backup filter.
`GridClientPartitionAffinity.HashIdResolver` `getHashIdResolver()` Gets hash ID resolver for nodes.
`int` `getPartitions()` Gets total number of key partitions.
`GridClientNode` `node(Object key, Collection<? extends GridClientNode> nodes)` Gets primary affinity node for a key.
`void` `onNodeAdded(GridClientNode node)` Callback for new nodes joining the remote grid.
`void` `onNodeRemoved(GridClientNode node)` Callback for nodes leaving the remote grid.
`void` `setBackupFilter(GridClientPredicate<UUID> backupFilter)` Sets optional backup filter.
`void` `setHashIdResolver(GridClientPartitionAffinity.HashIdResolver hashIdRslvr)` Sets hash ID resolver for nodes.
`void` `setPartitions(int parts)` Sets total number of partitions.
`String` `toString()`

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

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

### Field Detail

#### DFLT_PARTITION_CNT

    public static final int DFLT_PARTITION_CNT

Default number of partitions.

See Also:
  Constant Field Values

### Constructor Detail

#### GridClientPartitionAffinity

    public GridClientPartitionAffinity()

Empty constructor with all defaults.

#### GridClientPartitionAffinity

    public GridClientPartitionAffinity(Integer parts,
                               GridClientPredicate<UUID> backupFilter)

Initializes optional counts for replicas and backups.

Note that `excludeNeighbors` parameter is ignored if `backupFilter` is set.

Parameters:
  `parts` - Total number of partitions. If `null` than `DFLT_PARTITION_CNT` will be used.
  `backupFilter` - Optional back up filter for nodes. If provided, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.

### Method Detail

#### getPartitions

    public int getPartitions()

Gets total number of key partitions. To ensure that all partitions are equally distributed across all nodes, please make sure that this number is significantly larger than a number of nodes. Also, partition size should be relatively small. Try to avoid having partitions with more than quarter million keys.

Note that for fully replicated caches this method should always return `1`.

Returns:
  Total partition count.

#### setPartitions

    public void setPartitions(int parts)

Sets total number of partitions.

Parameters:
  `parts` - Total number of partitions.

#### getHashIdResolver

    public GridClientPartitionAffinity.HashIdResolver getHashIdResolver()

Gets hash ID resolver for nodes. This resolver is used to provide alternate hash ID, other than node ID.

Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.

Returns:
  Hash ID resolver.

#### setHashIdResolver

    public void setHashIdResolver(GridClientPartitionAffinity.HashIdResolver hashIdRslvr)

Sets hash ID resolver for nodes. This resolver is used to provide alternate hash ID, other than node ID.

Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.

Parameters:
  `hashIdRslvr` - Hash ID resolver.

#### getBackupFilter

    public GridClientPredicate<UUID> getBackupFilter()

Gets optional backup filter. If not `null`, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.

Note that `excludeNeighbors` parameter is ignored if `backupFilter` is set.

Returns:
  Optional backup filter.

#### setBackupFilter

    public void setBackupFilter(GridClientPredicate<UUID> backupFilter)

Sets optional backup filter. If provided, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.

Note that `excludeNeighbors` parameter is ignored if `backupFilter` is set.

Parameters:
  `backupFilter` - Optional backup filter.

#### node

    public GridClientNode node(Object key,
                      Collection<? extends GridClientNode> nodes)

Gets primary affinity node for a key. In case of replicated cache all nodes are equal and can be considered primary, so it may return any node. In case of partitioned cache primary node is returned.

Specified by:
  `node` in interface `GridClientDataAffinity`
Parameters:
  `key` - Key to get affinity for.
  `nodes` - Nodes to choose from.
Returns:
  Affinity nodes for the given partition.

#### onNodeAdded

    public void onNodeAdded(GridClientNode node)

Callback for new nodes joining the remote grid.

Specified by:
  `onNodeAdded` in interface `GridClientTopologyListener`
Parameters:
  `node` - New remote node.

#### onNodeRemoved

    public void onNodeRemoved(GridClientNode node)

Callback for nodes leaving the remote grid.

Specified by:
  `onNodeRemoved` in interface `GridClientTopologyListener`
Parameters:
  `node` - Left node.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC3
Release Date | : March 24 2015