use of io.confluent.ksql.rest.entity.QueryStateStoreId in project ksql by confluentinc.
the class MaximumLagFilter method create.
/**
* Creates a FreshnessFilter
* @param lagReportingAgent The optional lag reporting agent.
* @param routingOptions The routing options
* @param hosts The set of all hosts that have the store, including actives and standbys
* @param applicationQueryId The query id of the persistent query that materialized the table
* @param storeName The state store name of the materialized table
* @param partition The partition of the topic
* @return a new FreshnessFilter, unless lag reporting is disabled.
*/
public static Optional<MaximumLagFilter> create(final Optional<LagReportingAgent> lagReportingAgent, final RoutingOptions routingOptions, final List<KsqlHostInfo> hosts, final String applicationQueryId, final String storeName, final int partition) {
if (!lagReportingAgent.isPresent()) {
return Optional.empty();
}
final QueryStateStoreId queryStateStoreId = QueryStateStoreId.of(applicationQueryId, storeName);
final ImmutableMap<KsqlHostInfo, Optional<LagInfoEntity>> lagByHost = hosts.stream().collect(ImmutableMap.toImmutableMap(Function.identity(), host -> lagReportingAgent.get().getLagInfoForHost(host, queryStateStoreId, partition)));
final OptionalLong maxEndOffset = lagByHost.values().stream().filter(Optional::isPresent).map(Optional::get).mapToLong(LagInfoEntity::getEndOffsetPosition).max();
return Optional.of(new MaximumLagFilter(routingOptions, lagByHost, maxEndOffset));
}
Aggregations