Search in sources :

Example 1 with OperationIteratorToken

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 "";
        }
    };
}
Also used : TokenizableIterator(build.buildfarm.common.TokenizableIterator) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) OperationIteratorToken(build.buildfarm.v1test.OperationIteratorToken) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) IOException(java.io.IOException)

Example 2 with OperationIteratorToken

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 "";
        }
    };
}
Also used : TokenizableIterator(build.buildfarm.common.TokenizableIterator) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) OperationIteratorToken(build.buildfarm.v1test.OperationIteratorToken) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation)

Aggregations

TokenizableIterator (build.buildfarm.common.TokenizableIterator)2 OperationIteratorToken (build.buildfarm.v1test.OperationIteratorToken)2 QueuedOperation (build.buildfarm.v1test.QueuedOperation)2 Operation (com.google.longrunning.Operation)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 IOException (java.io.IOException)1