Interface PartitionMapper
-
- All Known Implementing Classes:
PartitionMapperBase
,RendezvousHashMapper
,UpdatablePartitionMapper
public interface PartitionMapper
Partition mapper.This interface represents a data partition mapper that is responsible for mapping user-provided data to cluster partitions.
// Prepare mapper. PartitionMapper mapper = RendezvousHashMapper.of(hekate.cluster()) .withPartitions(128) .withBackupNodes(2) .build(); // Map some imaginary data key to a partition. Partition partition = mapper.map("someDataKey1"); System.out.println("Primary node: " + partition.primaryNode()); System.out.println("Backup nodes: " + partition.backupNodes());
- See Also:
RendezvousHashMapper
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
backupNodes()
Returns the amount of backup nodes that should be assigned to each partition.PartitionMapper
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)
Partition
partition(int id)
Returns a partition for the specifiedPartition.id()
.int
partitions()
Returns the total amount of partitions.PartitionMapper
snapshot()
Creates a point in time snapshot of this mapper.ClusterTopology
topology()
Returns the cluster topology as it is visible to this mapper.
-
-
-
Method Detail
-
map
Partition map(Object key)
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.- Parameters:
key
- Data key.- Returns:
- Partition.
- See Also:
Partition.primaryNode()
,Partition.backupNodes()
-
mapInt
Partition mapInt(int key)
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.- Parameters:
key
- Data key.- Returns:
- Partition.
- See Also:
Partition.primaryNode()
,Partition.backupNodes()
-
partitions
int partitions()
Returns the total amount of partitions.- Returns:
- Total amount of partitions
-
partition
Partition partition(int id)
Returns a partition for the specifiedPartition.id()
.- Parameters:
id
- SeePartition.id()
.- Returns:
- Partition.
-
backupNodes
int backupNodes()
Returns the amount of backup nodes that should be assigned to each partition.- Returns:
- Amount of backup nodes that should be assigned to each partition.
-
topology
ClusterTopology topology()
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
PartitionMapper snapshot()
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:
isSnapshot()
-
isSnapshot
boolean isSnapshot()
Returnstrue
if this instance is asnapshot
.- Returns:
true
if this instance is asnapshot
.- See Also:
snapshot()
-
copy
PartitionMapper copy(ClusterTopologySupport cluster) throws UnsupportedOperationException
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
isSnapshot()
).- Parameters:
cluster
- Cluster topology.- Returns:
- New mapper.
- Throws:
UnsupportedOperationException
- if this partition mapper doesn't support copying.
-
-