public class GridCacheAffinityProxy<K,V> extends Object implements Affinity<K>, Externalizable
Constructor and Description |
---|
GridCacheAffinityProxy()
Required by
Externalizable . |
GridCacheAffinityProxy(GridCacheContext<K,V> cctx,
Affinity<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(ClusterNode n)
Gets partition ids for which given cluster node has any ownership
(either primary or backup).
|
int[] |
backupPartitions(ClusterNode n)
Gets partition ids for which given cluster node has backup ownership.
|
boolean |
isBackup(ClusterNode n,
K key)
Returns
true if local node is one of the backup nodes for given key. |
boolean |
isPrimary(ClusterNode n,
K key)
Returns
true if given node is the primary node for given key. |
boolean |
isPrimaryOrBackup(ClusterNode n,
K key)
Returns
true if local node is primary or one of the backup nodes
This method is essentially equivalent to calling
"Affinity.isPrimary(ClusterNode, Object) || Affinity.isBackup(ClusterNode, Object) )",
however it is more efficient as it makes both checks at once. |
Map<ClusterNode,Collection<K>> |
mapKeysToNodes(Collection<? extends K> keys)
This method provides ability to detect which keys are mapped to which nodes.
|
ClusterNode |
mapKeyToNode(K key)
This method provides ability to detect to which primary node the given key
is mapped.
|
Collection<ClusterNode> |
mapKeyToPrimaryAndBackups(K key)
Gets primary and backup nodes for the key.
|
Map<Integer,ClusterNode> |
mapPartitionsToNodes(Collection<Integer> parts)
Gets primary nodes for the given partitions.
|
ClusterNode |
mapPartitionToNode(int part)
Gets primary node for the given partition.
|
Collection<ClusterNode> |
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(ClusterNode n)
Gets partition ids for which the given cluster node has primary ownership.
|
void |
readExternal(ObjectInput in) |
void |
writeExternal(ObjectOutput out) |
public GridCacheAffinityProxy()
Externalizable
.public GridCacheAffinityProxy(GridCacheContext<K,V> cctx, Affinity<K> delegate)
cctx
- Context.delegate
- Delegate object.public int partitions()
partitions
in interface Affinity<K>
AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public int partition(K key)
partition
in interface Affinity<K>
key
- Key to get partition id for.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public boolean isPrimary(ClusterNode n, K key)
true
if given node is the primary node for given key.public boolean isBackup(ClusterNode n, K key)
true
if local node is one of the backup nodes for given key.public boolean isPrimaryOrBackup(ClusterNode n, K key)
true
if local node is primary or one of the backup nodes
This method is essentially equivalent to calling
"Affinity.isPrimary(ClusterNode, Object)
|| Affinity.isBackup(ClusterNode, Object)
)",
however it is more efficient as it makes both checks at once.
isPrimaryOrBackup
in interface Affinity<K>
n
- Node to check.key
- Key to check.True
if local node is primary or backup for given key.public int[] primaryPartitions(ClusterNode n)
primaryPartitions
in interface Affinity<K>
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public int[] backupPartitions(ClusterNode n)
backupPartitions
in interface Affinity<K>
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public int[] allPartitions(ClusterNode n)
allPartitions
in interface Affinity<K>
n
- Cluster node.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public ClusterNode mapPartitionToNode(int part)
mapPartitionToNode
in interface Affinity<K>
part
- Partition id.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
mapPartitionsToNodes
in interface Affinity<K>
parts
- Partition ids.AffinityFunction
,
CacheConfiguration.getAffinity()
,
CacheConfiguration.setAffinity(AffinityFunction)
public Object affinityKey(K key)
AffinityKeyMapped
annotation
or if a custom AffinityKeyMapper
was configured.affinityKey
in interface Affinity<K>
key
- Key to map.@Nullable public ClusterNode mapKeyToNode(K key)
This method works as following:
AffinityFunction
is returned.
mapKeyToNode
in interface Affinity<K>
key
- Keys to map to a node.public Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys)
This method works as following:
AffinityFunction
is
used to determine which keys are mapped to which nodes.
mapKeysToNodes
in interface Affinity<K>
keys
- Keys to map to nodes.public Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
mapKeyToPrimaryAndBackups
in interface Affinity<K>
key
- Key to get affinity nodes for.public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
mapPartitionToPrimaryAndBackups
in interface Affinity<K>
part
- Partition to get affinity nodes for.public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Follow @ApacheIgnite
Ignite Fabric : ver. 2.0.0 Release Date : April 30 2017