public class GridCacheAffinityProxy<K,V> extends Object implements GridCacheAffinity<K>
| Constructor and Description |
|---|
GridCacheAffinityProxy(GridCacheContext<K,V> cctx,
GridCacheAffinity<K> delegate) |
| Modifier and Type | Method and Description |
|---|---|
Object |
affinityKey(K key)
Maps passed in key to a key which will be used for node affinity.
|
int[] |
allPartitions(GridNode n)
Gets partition ids for which nodes of the given projection has ownership
(either primary or backup).
|
int[] |
backupPartitions(GridNode n)
Gets partition ids for which nodes of the given projection has backup
ownership.
|
boolean |
isBackup(GridNode n,
K key)
Returns
true if local node is one of the backup nodes for given key. |
boolean |
isPrimary(GridNode n,
K key)
Returns
true if given node is the primary node for given key. |
boolean |
isPrimaryOrBackup(GridNode n,
K key)
Returns
true if local node is primary or one of the backup nodes
for given key. |
Map<GridNode,Collection<K>> |
mapKeysToNodes(Collection<? extends K> keys)
This method provides ability to detect which keys are mapped to which nodes.
|
GridNode |
mapKeyToNode(K key)
This method provides ability to detect to which primary node the given key
is mapped.
|
Collection<GridNode> |
mapKeyToPrimaryAndBackups(K key)
Gets primary and backup nodes for the key.
|
Map<Integer,GridNode> |
mapPartitionsToNodes(Collection<Integer> parts)
Gets primary nodes for the given partitions.
|
GridNode |
mapPartitionToNode(int part)
Gets primary node for the given partition.
|
Collection<GridNode> |
mapPartitionToPrimaryAndBackups(int part)
Gets primary and backup nodes for partition.
|
int |
partition(K key)
Gets partition id for the given key.
|
int |
partitions()
Gets number of partitions in cache according to configured affinity function.
|
int[] |
primaryPartitions(GridNode n)
Gets partition ids for which nodes of the given projection has primary
ownership.
|
public GridCacheAffinityProxy(GridCacheContext<K,V> cctx, GridCacheAffinity<K> delegate)
cctx - Context.delegate - Delegate object.public int partitions()
partitions in interface GridCacheAffinity<K>GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public int partition(K key)
partition in interface GridCacheAffinity<K>key - Key to get partition id for.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public boolean isPrimary(GridNode n, K key)
true if given node is the primary node for given key.
To check if local node is primary for given key, pass
Grid.localNode() as first parameter.isPrimary in interface GridCacheAffinity<K>n - Node to check.key - Key to check.True if local node is the primary node for given key.public boolean isBackup(GridNode n, K key)
true if local node is one of the backup nodes for given key.
To check if local node is primary for given key, pass Grid.localNode()
as first parameter.isBackup in interface GridCacheAffinity<K>n - Node to check.key - Key to check.True if local node is one of the backup nodes for given key.public boolean isPrimaryOrBackup(GridNode n, K key)
true if local node is primary or one of the backup nodes
for given key. To check if local node is primary or backup for given key, pass
Grid.localNode() as first parameter.
This method is essentially equivalent to calling
"GridCacheAffinity.isPrimary(GridNode, Object) || GridCacheAffinity.isBackup(GridNode, Object))",
however it is more efficient as it makes both checks at once.
isPrimaryOrBackup in interface GridCacheAffinity<K>n - Node to check.key - Key to check.True if local node is primary or backup for given key.public int[] primaryPartitions(GridNode n)
Note that since GridNode implements GridProjection,
to find out primary partitions for a single node just pass
a single node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
primaryPartitions in interface GridCacheAffinity<K>n - Grid node.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public int[] backupPartitions(GridNode n)
first backup or third backup by specifying the
'levels parameter. If no 'level' is specified then
all backup partitions are returned.
Note that since GridNode implements GridProjection,
to find out backup partitions for a single node, just pass that single
node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
backupPartitions in interface GridCacheAffinity<K>n - Grid node.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public int[] allPartitions(GridNode n)
Note that since GridNode implements GridProjection,
to find out all partitions for a single node, just pass that single
node into this method.
This method may return an empty array if none of nodes in the projection have nearOnly disabled.
allPartitions in interface GridCacheAffinity<K>n - Grid node.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public GridNode mapPartitionToNode(int part)
mapPartitionToNode in interface GridCacheAffinity<K>part - Partition id.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public Map<Integer,GridNode> mapPartitionsToNodes(Collection<Integer> parts)
mapPartitionsToNodes in interface GridCacheAffinity<K>parts - Partition ids.GridCacheAffinityFunction,
GridCacheConfiguration.getAffinity(),
GridCacheConfiguration.setAffinity(GridCacheAffinityFunction)public Object affinityKey(K key)
GridCacheAffinityKeyMapped annotation
or if a custom GridCacheAffinityKeyMapper was configured.affinityKey in interface GridCacheAffinity<K>key - Key to map.@Nullable public GridNode mapKeyToNode(K key)
This method works as following:
GridCacheAffinityFunction
is returned.
mapKeyToNode in interface GridCacheAffinity<K>key - Keys to map to a node.null if there are no alive nodes for this cache.public Map<GridNode,Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys)
This method works as following:
GridCacheAffinityFunction is
used to determine which keys are mapped to which nodes.
mapKeysToNodes in interface GridCacheAffinity<K>keys - Keys to map to nodes.public Collection<GridNode> mapKeyToPrimaryAndBackups(K key)
If there are only cache nodes in the projection with
GridCacheConfiguration.getDistributionMode() property set to NEAR_ONLY, then this
method will return an empty collection.
mapKeyToPrimaryAndBackups in interface GridCacheAffinity<K>key - Key to get affinity nodes for.GridCacheConfiguration.getDistributionMode() property set to NEAR_ONLY.public Collection<GridNode> mapPartitionToPrimaryAndBackups(int part)
If there are only cache nodes in the projection with
GridCacheConfiguration.getDistributionMode() property set to NEAR_ONLY, then this
method will return an empty collection.
mapPartitionToPrimaryAndBackups in interface GridCacheAffinity<K>part - Partition to get affinity nodes for.GridCacheConfiguration.getDistributionMode() property set to NEAR_ONLY.Copyright © 2014. All rights reserved.