Class Position

java.lang.Object
org.apache.kafka.streams.query.Position

@Evolving public class Position extends Object
A representation of a position vector with respect to a set of topic partitions. For example, in Interactive Query (KafkaStreams.query(StateQueryRequest), a query result may contain information from multiple store partitions, each of which contains information from multiple input topics' partitions. This class can be used to summarize all of that positional information.

This class is threadsafe, although it is mutable. Readers are recommended to use copy() to avoid seeing mutations to the Position after they get the reference. For examples, when a store executes a StateStore.query(Query, PositionBound, QueryConfig) request and returns its current position via QueryResult.setPosition(Position), it should pass a copy of its position instead of the mutable reference.

  • Method Details

    • emptyPosition

      public static Position emptyPosition()
      Create a new, empty Position.
    • fromMap

      public static Position fromMap(Map<String,? extends Map<Integer,Long>> map)
      Create a new Position and populate it with a mapping of topic -> partition -> offset.

      Note, the resulting Position does not share any structure with the provided map, so subsequent changes to the map or Position will not affect the other.

    • withComponent

      public Position withComponent(String topic, int partition, long offset)
      Augment an existing Position by setting a new offset for a topic and partition.

      Note: enforces monotonicity on offsets. I.e., if there is already a component for the same topic and partition with a larger offset, the update will succeed but not overwrite the offset.

      Returns a self-reference for chained calls. Note: this method mutates the Position.

    • copy

      public Position copy()
      Create a deep copy of the Position.
    • merge

      public Position merge(Position other)
      Merges the provided Position into the current instance.

      If both Positions contain the same topic -> partition -> offset mapping, the resulting Position will contain a mapping with the larger of the two offsets.

    • getTopics

      public Set<String> getTopics()
      Return the topics that are represented in this Position.
    • getPartitionPositions

      public Map<Integer,Long> getPartitionPositions(String topic)
      Return the partition -> offset mapping for a specific topic.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isEmpty

      public boolean isEmpty()