public class GridCacheAffinityProxy<K,V> extends Object implements CacheAffinity<K>, Externalizable
| Constructor and Description |
|---|
GridCacheAffinityProxy()
Required by
Externalizable. |
GridCacheAffinityProxy(GridCacheContext<K,V> cctx,
CacheAffinity<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 nodes of the given projection has ownership
(either primary or backup).
|
int[] |
backupPartitions(ClusterNode n)
Gets partition ids for which nodes of the given projection 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
"CacheAffinity.isPrimary(org.apache.ignite.cluster.ClusterNode, Object) ||
CacheAffinity.isBackup(org.apache.ignite.cluster.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 nodes of the given projection has primary
ownership.
|
void |
readExternal(ObjectInput in) |
void |
writeExternal(ObjectOutput out) |
public GridCacheAffinityProxy()
Externalizable.public GridCacheAffinityProxy(GridCacheContext<K,V> cctx, CacheAffinity<K> delegate)
cctx - Context.delegate - Delegate object.public int partitions()
partitions in interface CacheAffinity<K>CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public int partition(K key)
partition in interface CacheAffinity<K>key - Key to get partition id for.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public boolean isPrimary(ClusterNode n, K key)
true if given node is the primary node for given key.isPrimary in interface CacheAffinity<K>n - Node to check.key - Key to check.True if local 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.isBackup in interface CacheAffinity<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(ClusterNode n, K key)
true if local node is primary or one of the backup nodes
This method is essentially equivalent to calling
"CacheAffinity.isPrimary(org.apache.ignite.cluster.ClusterNode, Object) ||
CacheAffinity.isBackup(org.apache.ignite.cluster.ClusterNode, Object))",
however it is more efficient as it makes both checks at once.
isPrimaryOrBackup in interface CacheAffinity<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)
Note that since ClusterNode implements ClusterGroup,
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 CacheAffinity<K>n - Grid node.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public int[] backupPartitions(ClusterNode 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 ClusterNode implements ClusterGroup,
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 CacheAffinity<K>n - Grid node.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public int[] allPartitions(ClusterNode n)
Note that since ClusterNode implements ClusterGroup,
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 CacheAffinity<K>n - Grid node.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public ClusterNode mapPartitionToNode(int part)
mapPartitionToNode in interface CacheAffinity<K>part - Partition id.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public Map<Integer,ClusterNode> mapPartitionsToNodes(Collection<Integer> parts)
mapPartitionsToNodes in interface CacheAffinity<K>parts - Partition ids.CacheAffinityFunction,
CacheConfiguration.getAffinity(),
CacheConfiguration.setAffinity(CacheAffinityFunction)public Object affinityKey(K key)
CacheAffinityKeyMapped annotation
or if a custom CacheAffinityKeyMapper was configured.affinityKey in interface CacheAffinity<K>key - Key to map.@Nullable public ClusterNode mapKeyToNode(K key)
This method works as following:
CacheAffinityFunction
is returned.
mapKeyToNode in interface CacheAffinity<K>key - Keys to map to a node.null if there are no alive nodes for this cache.public Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys)
This method works as following:
CacheAffinityFunction is
used to determine which keys are mapped to which nodes.
mapKeysToNodes in interface CacheAffinity<K>keys - Keys to map to nodes.public Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key)
If there are only cache nodes in the projection with
CacheConfiguration.getDistributionMode() property set to NEAR_ONLY, then this
method will return an empty collection.
mapKeyToPrimaryAndBackups in interface CacheAffinity<K>key - Key to get affinity nodes for.CacheConfiguration.getDistributionMode() property set to NEAR_ONLY.public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part)
If there are only cache nodes in the projection with
CacheConfiguration.getDistributionMode() property set to NEAR_ONLY, then this
method will return an empty collection.
mapPartitionToPrimaryAndBackups in interface CacheAffinity<K>part - Partition to get affinity nodes for.CacheConfiguration.getDistributionMode() property set to NEAR_ONLY.public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundException
Follow @ApacheIgnite
Ignite Fabric : ver. 1.0.0-RC3 Release Date : March 24 2015