Package org.infinispan.commands
Interface SegmentSpecificCommand
- All Known Subinterfaces:
DataCommand
,DataWriteCommand
- All Known Implementing Classes:
AbstractDataCommand
,AbstractDataWriteCommand
,AbstractWriteKeyCommand
,ClusteredGetCommand
,ComputeCommand
,ComputeIfAbsentCommand
,EvictCommand
,GetCacheEntryCommand
,GetKeyValueCommand
,IracPutKeyValueCommand
,PutKeyValueCommand
,ReadOnlyKeyCommand
,ReadWriteKeyCommand
,ReadWriteKeyValueCommand
,RemoveCommand
,RemoveExpiredCommand
,ReplaceCommand
,TouchCommand
,TxReadOnlyKeyCommand
,WriteOnlyKeyCommand
,WriteOnlyKeyValueCommand
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 int
extractSegment
(ReplicableCommand command, Object key, KeyPartitioner keyPartitioner) Utility to extract the segment from a given command that may be aSegmentSpecificCommand
.static <K> org.infinispan.commons.util.SegmentAwareKey<K>
extractSegmentAwareKey
(ReplicableCommand command, K key, KeyPartitioner keyPartitioner) Create anSegmentAwareKey
instance with the key and its segment.int
Returns 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> org.infinispan.commons.util.SegmentAwareKey<K> extractSegmentAwareKey(ReplicableCommand command, K key, KeyPartitioner keyPartitioner) Create anSegmentAwareKey
instance with the key and its segment.If the
command
implementsSegmentSpecificCommand
, 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
SegmentAwareKey
instance.
-