Package org.infinispan.commands
Interface SegmentSpecificCommand
- All Known Subinterfaces:
DataCommand
- All Known Implementing Classes:
org.infinispan.commands.read.AbstractDataCommand,TouchCommand
public interface SegmentSpecificCommand
Interface to be implemented when the command can define a single segment for its operation. This is useful so that
subsequent operations requiring a segment can retrieve it from the command and have it only computed once at creation
time.
If a command implements this interface, the command MUST ensure that it is initialized properly to always
return a number 0 or greater when invoking getSegment().
- Since:
- 9.3
- Author:
- wburns
-
Method Summary
Modifier and TypeMethodDescriptionstatic intextractSegment(ReplicableCommand command, Object key, KeyPartitioner keyPartitioner) Utility to extract the segment from a given command that may be aSegmentSpecificCommand.static <K> SegmentAwareKey<K>extractSegmentAwareKey(ReplicableCommand command, K key, KeyPartitioner keyPartitioner) Create anSegmentAwareKeyinstance with the key and its segment.intReturns the segment that this key maps to.
-
Method Details
-
getSegment
int getSegment()Returns the segment that this key maps to. This must always return a number 0 or larger.- Returns:
- the segment of the key
-
extractSegment
Utility to extract the segment from a given command that may be aSegmentSpecificCommand. If the command is aSegmentSpecificCommand, it will immediately return the value fromgetSegment(). Otherwise it will return the result from invokingKeyPartitioner.getSegment(Object)passing the provided key.- Parameters:
command- the command to extract the segment fromkey- the key the segment belongs tokeyPartitioner- the partitioner to calculate the segment of the key- Returns:
- the segment value to use.
-
extractSegmentAwareKey
static <K> SegmentAwareKey<K> extractSegmentAwareKey(ReplicableCommand command, K key, KeyPartitioner keyPartitioner) Create anSegmentAwareKeyinstance with the key and its segment.If the
commandimplementsSegmentSpecificCommand, it will return the segment fromgetSegment()instead of computing it.- Type Parameters:
K- The key's type.- Parameters:
command- the command to extract the segment fromkey- the key the segment belongs tokeyPartitioner- the partitioner to calculate the segment of the key- Returns:
- The
SegmentAwareKeyinstance.
-