use of org.apache.kafka.streams.processor.internals.namedtopology.NamedTopologyStoreQueryParameters in project kafka by apache.
the class StreamThreadStateStoreProvider method stores.
@SuppressWarnings("unchecked")
public <T> List<T> stores(final StoreQueryParameters storeQueryParams) {
final StreamThread.State state = streamThread.state();
if (state == StreamThread.State.DEAD) {
return Collections.emptyList();
}
final String storeName = storeQueryParams.storeName();
final QueryableStoreType<T> queryableStoreType = storeQueryParams.queryableStoreType();
final String topologyName = storeQueryParams instanceof NamedTopologyStoreQueryParameters ? ((NamedTopologyStoreQueryParameters) storeQueryParams).topologyName() : null;
if (storeQueryParams.staleStoresEnabled() ? state.isAlive() : state == StreamThread.State.RUNNING) {
final Collection<Task> tasks = storeQueryParams.staleStoresEnabled() ? streamThread.allTasks().values() : streamThread.activeTasks();
if (storeQueryParams.partition() != null) {
for (final Task task : tasks) {
if (task.id().partition() == storeQueryParams.partition() && (topologyName == null || topologyName.equals(task.id().topologyName())) && task.getStore(storeName) != null && storeName.equals(task.getStore(storeName).name())) {
final T typedStore = validateAndCastStores(task.getStore(storeName), queryableStoreType, storeName, task.id());
return Collections.singletonList(typedStore);
}
}
return Collections.emptyList();
} else {
final List<T> list = new ArrayList<>();
for (final Task task : tasks) {
final StateStore store = task.getStore(storeName);
if (store == null) {
// then this task doesn't have that store
} else {
final T typedStore = validateAndCastStores(store, queryableStoreType, storeName, task.id());
list.add(typedStore);
}
}
return list;
}
} else {
throw new InvalidStateStoreException("Cannot get state store " + storeName + " because the stream thread is " + state + ", not RUNNING" + (storeQueryParams.staleStoresEnabled() ? " or REBALANCING" : ""));
}
}
Aggregations