Class RendezvousHashMapper
- java.lang.Object
-
- io.hekate.partition.PartitionMapperBase
-
- io.hekate.partition.RendezvousHashMapper
-
- All Implemented Interfaces:
PartitionMapper
public final class RendezvousHashMapper extends PartitionMapperBase
Implementation ofPartitionMapper
that uses Rendezvous (aka Highest Random Weight) hashing algorithm for partition mapping.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RendezvousHashMapper.Builder
Builder forRendezvousHashMapper
.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PARTITIONS
Default value (=256) forRendezvousHashMapper.Builder.withPartitions(int)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RendezvousHashMapper
copy(ClusterTopologySupport cluster)
Returns a copy of this mapper that will use the specified cluster topology and will inherit the mapping logic and all the configuration options from this instance.boolean
isSnapshot()
Returnstrue
if this instance is asnapshot
.Partition
map(Object key)
Maps the specified key to aPartition
.Partition
mapInt(int key)
static RendezvousHashMapper.Builder
of(ClusterTopologySupport cluster)
Constructs a new builder that can be used to configureRendezvousHashMapper
.static RendezvousHashMapper
of(ClusterTopologySupport cluster, int partitions, int backupNodes)
Constructs a new mapper.Partition
partition(int id)
Returns a partition for the specifiedPartition.id()
.PartitionMapper
snapshot()
Creates a point in time snapshot of this mapper.ClusterTopology
topology()
Returns the cluster topology as it is visible to this mapper.String
toString()
-
Methods inherited from class io.hekate.partition.PartitionMapperBase
backupNodes, partitions
-
-
-
-
Field Detail
-
DEFAULT_PARTITIONS
public static final int DEFAULT_PARTITIONS
Default value (=256) forRendezvousHashMapper.Builder.withPartitions(int)
.- See Also:
- Constant Field Values
-
-
Method Detail
-
of
public static RendezvousHashMapper.Builder of(ClusterTopologySupport cluster)
Constructs a new builder that can be used to configureRendezvousHashMapper
.- Parameters:
cluster
- Cluster topology that should be used for partitions mapping.- Returns:
- Builder.
- See Also:
RendezvousHashMapper.Builder.build()
-
of
public static RendezvousHashMapper of(ClusterTopologySupport cluster, int partitions, int backupNodes)
Constructs a new mapper.- Parameters:
cluster
- Cluster topology that should be used for partitions mapping.partitions
- SeeRendezvousHashMapper.Builder.withPartitions(int)
backupNodes
- SeeRendezvousHashMapper.Builder.withBackupNodes(int)
- Returns:
- New mapper.
-
copy
public RendezvousHashMapper copy(ClusterTopologySupport cluster)
Description copied from interface:PartitionMapper
Returns a copy of this mapper that will use the specified cluster topology and will inherit the mapping logic and all the configuration options from this instance.Note that copying is not supported on snapshots (see
PartitionMapper.isSnapshot()
).- Parameters:
cluster
- Cluster topology.- Returns:
- New mapper.
-
map
public Partition map(Object key)
Description copied from interface:PartitionMapper
Maps the specified key to aPartition
.Note that the returned
Partition
instances are immutable and will not reflect changes in the cluster topology. Consider calling this method with the same key in order to obtain thePartition
instance with the latest cluster topology mapping.- Specified by:
map
in interfacePartitionMapper
- Overrides:
map
in classPartitionMapperBase
- Parameters:
key
- Data key.- Returns:
- Partition.
- See Also:
Partition.primaryNode()
,Partition.backupNodes()
-
mapInt
public Partition mapInt(int key)
Description copied from interface:PartitionMapper
Maps the specified key ofInteger
type to aPartition
.Note that the returned
Partition
instances are immutable and will not reflect changes in the cluster topology. Consider calling this method with the same key in order to obtain thePartition
instance with the latest cluster topology mapping.- Specified by:
mapInt
in interfacePartitionMapper
- Overrides:
mapInt
in classPartitionMapperBase
- Parameters:
key
- Data key.- Returns:
- Partition.
- See Also:
Partition.primaryNode()
,Partition.backupNodes()
-
partition
public Partition partition(int id)
Description copied from interface:PartitionMapper
Returns a partition for the specifiedPartition.id()
.- Parameters:
id
- SeePartition.id()
.- Returns:
- Partition.
-
topology
public ClusterTopology topology()
Description copied from interface:PartitionMapper
Returns the cluster topology as it is visible to this mapper.If mapper is a
snapshot
then this method will always return the same topology at the time when the snapshot was created. If mapper is a live mapper then it will always return the latest cluster topology.- Returns:
- Cluster topology.
-
snapshot
public PartitionMapper snapshot()
Description copied from interface:PartitionMapper
Creates a point in time snapshot of this mapper. The returned snapshot is immutable and will not change its partitions mapping even if cluster topology changes.- Returns:
- New snapshot or the same instance if this instance is already a snapshot.
- See Also:
PartitionMapper.isSnapshot()
-
isSnapshot
public boolean isSnapshot()
Description copied from interface:PartitionMapper
Returnstrue
if this instance is asnapshot
.- Returns:
true
if this instance is asnapshot
.- See Also:
PartitionMapper.snapshot()
-
-