Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-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 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.
 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

 

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

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


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