use of build.buildfarm.v1test.OperationIteratorToken in project bazel-buildfarm by bazelbuild.
the class ShardInstance method createOperationsIterator.
@Override
protected TokenizableIterator<Operation> createOperationsIterator(String pageToken) {
Iterator<Operation> iter;
iter = Iterables.transform(backplane.getOperations(), (operationName) -> {
try {
return backplane.getOperation(operationName);
} catch (IOException e) {
throw Status.fromThrowable(e).asRuntimeException();
}
}).iterator();
OperationIteratorToken token;
if (!pageToken.isEmpty()) {
try {
token = OperationIteratorToken.parseFrom(BaseEncoding.base64().decode(pageToken));
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException();
}
boolean paged = false;
while (iter.hasNext() && !paged) {
paged = iter.next().getName().equals(token.getOperationName());
}
} else {
token = null;
}
return new TokenizableIterator<Operation>() {
private OperationIteratorToken nextToken = token;
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public Operation next() {
Operation operation = iter.next();
nextToken = OperationIteratorToken.newBuilder().setOperationName(operation.getName()).build();
return operation;
}
@Override
public String toNextPageToken() {
if (hasNext()) {
return BaseEncoding.base64().encode(nextToken.toByteArray());
}
return "";
}
};
}
use of build.buildfarm.v1test.OperationIteratorToken in project bazel-buildfarm by bazelbuild.
the class MemoryInstance method createOperationsIterator.
@Override
protected TokenizableIterator<Operation> createOperationsIterator(String pageToken) {
Iterator<Operation> iter = outstandingOperations.iterator();
final OperationIteratorToken token;
if (!pageToken.isEmpty()) {
try {
token = OperationIteratorToken.parseFrom(BaseEncoding.base64().decode(pageToken));
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException();
}
boolean paged = false;
while (iter.hasNext() && !paged) {
paged = iter.next().getName().equals(token.getOperationName());
}
} else {
token = null;
}
return new TokenizableIterator<Operation>() {
private OperationIteratorToken nextToken = token;
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public Operation next() {
Operation operation = iter.next();
nextToken = OperationIteratorToken.newBuilder().setOperationName(operation.getName()).build();
return operation;
}
@Override
public String toNextPageToken() {
if (hasNext()) {
return BaseEncoding.base64().encode(nextToken.toByteArray());
}
return "";
}
};
}
Aggregations