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

    • emptyPosition Link icon

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

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

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

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

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

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

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

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

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

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

      public boolean isEmpty()