use of io.pravega.controller.stream.api.grpc.v1.Controller.StreamsInScopeWithTagRequest in project pravega by pravega.
the class ControllerImpl method listStreamsForTag.
@Override
public AsyncIterator<Stream> listStreamsForTag(String scopeName, String tag) {
Exceptions.checkNotClosed(closed.get(), this);
long traceId = LoggerHelpers.traceEnter(log, LIST_STREAMS_IN_SCOPE_FOR_TAG, scopeName);
long requestId = requestIdGenerator.get();
try {
final Function<ContinuationToken, CompletableFuture<Map.Entry<ContinuationToken, Collection<Stream>>>> function = token -> this.retryConfig.runAsync(() -> {
RPCAsyncCallback<StreamsInScopeResponse> callback = new RPCAsyncCallback<>(requestId, LIST_STREAMS_IN_SCOPE_FOR_TAG, scopeName);
ScopeInfo scopeInfo = ScopeInfo.newBuilder().setScope(scopeName).build();
StreamsInScopeWithTagRequest request = StreamsInScopeWithTagRequest.newBuilder().setScope(scopeInfo).setContinuationToken(token).setTag(tag).build();
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, LIST_STREAMS_IN_SCOPE_FOR_TAG, scopeName).listStreamsInScopeForTag(request, callback);
return callback.getFuture().thenApplyAsync(x -> {
switch(x.getStatus()) {
case SCOPE_NOT_FOUND:
log.warn(requestId, "Scope not found: {}", scopeName);
throw new NoSuchScopeException();
case FAILURE:
log.warn(requestId, "Internal Server Error while trying to list streams in scope: {} with tag: {}", scopeName, tag);
throw new RuntimeException("Failure while trying to list streams with tag");
case SUCCESS:
// compatibility reasons
default:
List<Stream> result = x.getStreamsList().stream().map(y -> new StreamImpl(y.getScope(), y.getStream())).collect(Collectors.toList());
return new AbstractMap.SimpleEntry<>(x.getContinuationToken(), result);
}
}, this.executor);
}, this.executor);
return new ContinuationTokenAsyncIterator<>(function, ContinuationToken.newBuilder().build());
} finally {
LoggerHelpers.traceLeave(log, LIST_STREAMS_IN_SCOPE_FOR_TAG, traceId);
}
}
Aggregations