Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


com.tangosol.net.partition
Class DefaultKeyPartitioningStrategy

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.BitHelper
          extended by com.tangosol.util.ExternalizableHelper
              extended by com.tangosol.net.partition.DefaultKeyPartitioningStrategy

All Implemented Interfaces:
KeyPartitioningStrategy
Direct Known Subclasses:
BroadKeyPartitioningStrategy

public class DefaultKeyPartitioningStrategy
extends ExternalizableHelper
implements KeyPartitioningStrategy

DefaultKeyPartitioningStrategy provides a simple strategy for assigning keys to partitions which is based on the hash code of keys in internal (serialized to Binary) form.

Since:
Coherence 3.6
Author:
gg 2010.05.19

Nested Class Summary

 

Nested classes/interfaces inherited from interface com.tangosol.net.partition.KeyPartitioningStrategy
KeyPartitioningStrategy.PartitionAwareKey

 

Field Summary
protected  PartitionedService m_service
          The PartitionedService that this strategy is bound to.

 

Constructor Summary
DefaultKeyPartitioningStrategy()
          Default constructor.

 

Method Summary
static int calculateBasePartitionHash(PartitionedService service, java.lang.Object oKey)
          Determine the partition-hash of the given key.
static int calculateKeyPartition(PartitionedService service, java.lang.Object oKey)
          Determine the partition to which the given key should be assigned for the specified PartitionService, taking into consideration the associations provided by the service's KeyAssociator.
static int calculateKeyPartitionHash(PartitionedService service, java.lang.Object oKey)
          Determine the partition-hash of the given key.
static int calculatePartition(PartitionedService service, int nHash)
          Return the partition associated with the specified hash value in the specified PartitionedService.
 PartitionSet getAssociatedPartitions(java.lang.Object oKey)
          Determine the set of partitions that all keys associated with the specified key are assigned to.
 int getKeyPartition(java.lang.Object oKey)
          Determine the partition to which a particular key should be assigned.
 void init(PartitionedService service)
          Initialize the KeyPartitioningStrategy and bind it to the specified PartitionedService.

 

Methods inherited from class com.tangosol.util.BitHelper
countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, rotateLeft, rotateLeft, rotateLeft, rotateRight, rotateRight, rotateRight, toBitString, toBitString, toBitString, toBytes, toBytes, toBytes, toBytes, toInt, toInt, toLong, toLong

 

Field Detail

m_service

protected PartitionedService m_service
The PartitionedService that this strategy is bound to.

Constructor Detail

DefaultKeyPartitioningStrategy

public DefaultKeyPartitioningStrategy()
Default constructor.

Method Detail

init

public void init(PartitionedService service)
Initialize the KeyPartitioningStrategy and bind it to the specified PartitionedService.
Specified by:
init in interface KeyPartitioningStrategy
Parameters:
service - the PartitionedService that this strategy is being bound to

getKeyPartition

public int getKeyPartition(java.lang.Object oKey)
Determine the partition to which a particular key should be assigned.

In general, implementations are expected to respect the associations provided by the service's KeyAssociator in such a way that keys that return the same associated key would be assigned to the same partition. Furthermore, implementations are also expected to respect explicit partition-assignments dictated by the KeyPartitioningStrategy.PartitionAwareKey interface. Naturally, those two interfaces should not be combined for a given key.

The resulting partition must be in the range [0..N-1], where N is the value returned from PartitionedService.getPartitionCount().

Specified by:
getKeyPartition in interface KeyPartitioningStrategy
Parameters:
oKey - a key in its Object form
Returns:
the partition ID that the specified key is assigned to
See Also:
PartitionedService.getPartitionOwner(int)

getAssociatedPartitions

public PartitionSet getAssociatedPartitions(java.lang.Object oKey)
Determine the set of partitions that all keys associated with the specified key are assigned to. Most commonly, this method returns a partition set containing a single partition returned by the getKeyPartition method.
Specified by:
getAssociatedPartitions in interface KeyPartitioningStrategy
Parameters:
oKey - a key in its Object form
Returns:
the PartitionSet associated with the specified key

calculateKeyPartition

public static int calculateKeyPartition(PartitionedService service,
                                        java.lang.Object oKey)
Determine the partition to which the given key should be assigned for the specified PartitionService, taking into consideration the associations provided by the service's KeyAssociator.

The resulting partition will be in the range [0..N), where N is the value returned from the PartitionedService.getPartitionCount() method.

Parameters:
service - the PartitionedService
oKey - a key in its original (Object) format
Returns:
the partition that the corresponding key is assigned to

calculateKeyPartitionHash

public static int calculateKeyPartitionHash(PartitionedService service,
                                            java.lang.Object oKey)
Determine the partition-hash of the given key. The partition-hash is a property of the key identity itself, irrespective of the associated PartitionService's configured partition-count. The returned partition-hash is calculated by taking into consideration the associations provided by the service's KeyAssociator.
Parameters:
service - the PartitionedService
oKey - a key in its original (Object) format
Returns:
the partition-hash of the corresponding key

calculateBasePartitionHash

public static int calculateBasePartitionHash(PartitionedService service,
                                             java.lang.Object oKey)
Determine the partition-hash of the given key. The partition-hash is a property of the key identity itself, irrespective of the associated PartitionService's configured partition-count.
Parameters:
service - the PartitionedService
oKey - a key in its original (Object) format
Returns:
the partition-hash of the corresponding key

calculatePartition

public static int calculatePartition(PartitionedService service,
                                     int nHash)
Return the partition associated with the specified hash value in the specified PartitionedService.
Parameters:
service - the PartitionedService
nHash - the hash value
Returns:
the partition-id that the specified hash value belongs to

Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.