@InterfaceStability.Evolving public class Position extends Object
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.
Modifier and Type | Method and Description |
---|---|
Position |
copy()
Create a deep copy of the Position.
|
static Position |
emptyPosition()
Create a new, empty Position.
|
boolean |
equals(Object o) |
static Position |
fromMap(Map<String,? extends Map<Integer,Long>> map)
Create a new Position and populate it with a mapping of topic -> partition -> offset.
|
Map<Integer,Long> |
getPartitionPositions(String topic)
Return the partition -> offset mapping for a specific topic.
|
Set<String> |
getTopics()
Return the topics that are represented in this Position.
|
int |
hashCode() |
boolean |
isEmpty() |
Position |
merge(Position other)
Merges the provided Position into the current instance.
|
String |
toString() |
Position |
withComponent(String topic,
int partition,
long offset)
Augment an existing Position by setting a new offset for a topic and partition.
|
public static Position emptyPosition()
public static Position fromMap(Map<String,? extends Map<Integer,Long>> map)
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.
public Position withComponent(String topic, int partition, long offset)
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.
public Position copy()
public Position merge(Position other)
If both Positions contain the same topic -> partition -> offset mapping, the resulting Position will contain a mapping with the larger of the two offsets.
public Map<Integer,Long> getPartitionPositions(String topic)
public boolean isEmpty()