@Override public boolean shouldRetry( Throwable prevThrowable, com.google.longrunning.Operation prevResponse) { if (prevResponse != null) { return !prevResponse.getDone(); } if (prevThrowable instanceof SpannerException) { SpannerException spannerException = (SpannerException) prevThrowable; return spannerException.getErrorCode() != ErrorCode.NOT_FOUND && spannerException.isRetryable(); } return false; } },
static <R, M> Operation<R, M> create( SpannerRpc rpc, com.google.longrunning.Operation proto, Parser<R, M> parser, ApiClock clock) { M metadata = proto.hasMetadata() ? parser.parseMetadata(proto.getMetadata()) : null; String name = proto.getName(); if (proto.getDone()) { if (proto.getResultCase() == ResultCase.ERROR) { return Operation.<R, M>failed(rpc, name, proto.getError(), metadata, parser, clock); } else { return Operation.<R, M>successful( rpc, name, metadata, parser.parseResult(proto.getResponse()), parser, clock); } } else { return Operation.<R, M>pending(rpc, name, metadata, parser, clock); } }
@Override public boolean isDone() { return operation.getDone(); }
@Override public boolean isDone() { return operation.getDone(); }
@Override public boolean shouldRetry( Throwable prevThrowable, com.google.longrunning.Operation prevResponse) { if (prevResponse != null) { return !prevResponse.getDone(); } if (prevThrowable instanceof SpannerException) { SpannerException spannerException = (SpannerException) prevThrowable; return spannerException.getErrorCode() != ErrorCode.NOT_FOUND && spannerException.isRetryable(); } return false; } },
/** * Waits for an operation like cluster resizing to complete. * @param operationName The fully qualified name of the operation * @param maxSeconds The maximum amount of seconds to wait for the operation to complete. * @throws InterruptedException if a user interrupts the process, usually with a ^C. */ public void waitForOperation(String operationName, int maxSeconds) throws InterruptedException { long endTimeMillis = TimeUnit.SECONDS.toMillis(maxSeconds) + System.currentTimeMillis(); GetOperationRequest request = GetOperationRequest.newBuilder().setName(operationName).build(); do { Thread.sleep(500); Operation response = client.getOperation(request); if (response.getDone()) { switch (response.getResultCase()) { case RESPONSE: return; case ERROR: throw new RuntimeException("Cluster could not be resized: " + response.getError()); case RESULT_NOT_SET: throw new IllegalStateException( "System returned invalid response for Operation check: " + response); } } } while (System.currentTimeMillis() < endTimeMillis); throw new IllegalStateException( String.format("Waited %d seconds and cluster was not resized yet.", maxSeconds)); }
if (currentOperationState.getDone()) { switch (currentOperationState.getResultCase()) { case RESPONSE:
getDone()); switch (resultCase_) { case 4:
public Builder mergeFrom(com.google.longrunning.Operation other) { if (other == com.google.longrunning.Operation.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.hasMetadata()) { mergeMetadata(other.getMetadata()); } if (other.getDone() != false) { setDone(other.getDone()); } switch (other.getResultCase()) { case ERROR: { mergeError(other.getError()); break; } case RESPONSE: { mergeResponse(other.getResponse()); break; } case RESULT_NOT_SET: { break; } } onChanged(); return this; }
public Builder mergeFrom(com.google.longrunning.Operation other) { if (other == com.google.longrunning.Operation.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); } if (other.hasMetadata()) { mergeMetadata(other.getMetadata()); } if (other.getDone() != false) { setDone(other.getDone()); } switch (other.getResultCase()) { case ERROR: { mergeError(other.getError()); break; } case RESPONSE: { mergeResponse(other.getResponse()); break; } case RESULT_NOT_SET: { break; } } onChanged(); return this; }
getDone()); switch (resultCase_) { case 4:
static <R, M> Operation<R, M> create( SpannerRpc rpc, com.google.longrunning.Operation proto, Parser<R, M> parser, ApiClock clock) { M metadata = proto.hasMetadata() ? parser.parseMetadata(proto.getMetadata()) : null; String name = proto.getName(); if (proto.getDone()) { if (proto.getResultCase() == ResultCase.ERROR) { return Operation.<R, M>failed(rpc, name, proto.getError(), metadata, parser, clock); } else { return Operation.<R, M>successful( rpc, name, metadata, parser.parseResult(proto.getResponse()), parser, clock); } } else { return Operation.<R, M>pending(rpc, name, metadata, parser, clock); } }