use of io.pravega.common.util.ContinuationTokenAsyncIterator in project pravega by pravega.
the class ControllerImpl method listStreams.
@Override
public AsyncIterator<Stream> listStreams(String scopeName) {
Exceptions.checkNotClosed(closed.get(), this);
long traceId = LoggerHelpers.traceEnter(log, "listStreams", 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, "listStreams", scopeName);
ScopeInfo scopeInfo = ScopeInfo.newBuilder().setScope(scopeName).build();
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, LIST_STREAMS_IN_SCOPE, scopeName).listStreamsInScope(StreamsInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(token).build(), 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: {}", scopeName);
throw new RuntimeException("Failure while trying to list streams");
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, "listStreams", traceId);
}
}
use of io.pravega.common.util.ContinuationTokenAsyncIterator 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);
}
}
use of io.pravega.common.util.ContinuationTokenAsyncIterator in project pravega by pravega.
the class ControllerImpl method listKeyValueTables.
@Override
public AsyncIterator<KeyValueTableInfo> listKeyValueTables(String scopeName) {
Exceptions.checkNotClosed(closed.get(), this);
long traceId = LoggerHelpers.traceEnter(log, "listKeyValueTables", scopeName);
long requestId = requestIdGenerator.get();
try {
final Function<ContinuationToken, CompletableFuture<Map.Entry<ContinuationToken, Collection<KeyValueTableInfo>>>> function = token -> this.retryConfig.runAsync(() -> {
RPCAsyncCallback<KVTablesInScopeResponse> callback = new RPCAsyncCallback<>(requestId, "listKeyValueTables", scopeName);
ScopeInfo scopeInfo = ScopeInfo.newBuilder().setScope(scopeName).build();
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, LIST_KEY_VALUE_TABLES, scopeName).listKeyValueTables(KVTablesInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(token).build(), 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: {}", scopeName);
throw new RuntimeException("Failure while trying to list streams");
case SUCCESS:
// compatibility reasons
default:
List<KeyValueTableInfo> kvtList = x.getKvtablesList().stream().map(y -> new KeyValueTableInfo(y.getScope(), y.getKvtName())).collect(Collectors.toList());
return new AbstractMap.SimpleEntry<>(x.getContinuationToken(), kvtList);
}
}, this.executor);
}, this.executor);
return new ContinuationTokenAsyncIterator<>(function, ContinuationToken.newBuilder().build());
} finally {
LoggerHelpers.traceLeave(log, "listKeyValueTables", traceId);
}
}
Aggregations