Class DefaultKeyPartitioningStrategy

    • 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​(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​(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,
                                                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,
                                                    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,
                                                     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