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 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

      static int extractSegment(ReplicableCommand command, Object key, KeyPartitioner keyPartitioner)
      Utility to extract the segment from a given command that may be a SegmentSpecificCommand. If the command is a SegmentSpecificCommand, it will immediately return the value from getSegment(). Otherwise it will return the result from invoking KeyPartitioner.getSegment(Object) passing the provided key.
      Parameters:
      command - the command to extract the segment from
      key - the key the segment belongs to
      keyPartitioner - 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 an SegmentAwareKey instance with the key and its segment.

      If the command implements SegmentSpecificCommand, it will return the segment from getSegment() instead of computing it.

      Type Parameters:
      K - The key's type.
      Parameters:
      command - the command to extract the segment from
      key - the key the segment belongs to
      keyPartitioner - the partitioner to calculate the segment of the key
      Returns:
      The SegmentAwareKey instance.