All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.topicus.jdbc.shaded.com.google.api.gax.rpc.OperationCallableImpl Maven / Gradle / Ivy

/*
 * Copyright 2016, Google LLC All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google LLC nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package nl.topicus.jdbc.shaded.com.google.api.gax.rpc;

import static nl.topicus.jdbc.shaded.com.google.common.base.Preconditions.checkNotNull;

import nl.topicus.jdbc.shaded.com.google.api.core.ApiFunction;
import nl.topicus.jdbc.shaded.com.google.api.core.ApiFuture;
import nl.topicus.jdbc.shaded.com.google.api.gax.longrunning.OperationFuture;
import nl.topicus.jdbc.shaded.com.google.api.gax.longrunning.OperationFutureImpl;
import nl.topicus.jdbc.shaded.com.google.api.gax.longrunning.OperationSnapshot;
import nl.topicus.jdbc.shaded.com.google.api.gax.retrying.RetryingExecutor;
import nl.topicus.jdbc.shaded.com.google.api.gax.retrying.RetryingFuture;

/**
 * An OperationCallableImpl is an immutable object which is capable of initiating RPC calls to
 * long-running API methods and returning a {@link OperationFuture} to manage the polling of the
 * Operation and getting the response.
 *
 * 

Package-private for internal use. */ class OperationCallableImpl extends OperationCallable { private final UnaryCallable initialCallable; private final RetryingExecutor executor; private final LongRunningClient longRunningClient; private final ApiFunction responseTransformer; private final ApiFunction metadataTransformer; OperationCallableImpl( UnaryCallable initialCallable, RetryingExecutor executor, LongRunningClient longRunningClient, OperationCallSettings operationCallSettings) { this.initialCallable = checkNotNull(initialCallable); this.executor = checkNotNull(executor); this.longRunningClient = checkNotNull(longRunningClient); this.responseTransformer = operationCallSettings.getResponseTransformer(); this.metadataTransformer = operationCallSettings.getMetadataTransformer(); } /** * Initiates an operation asynchronously. If the {@link TransportChannel} encapsulated in the * given {@link ApiCallContext} is null, a channel must have already been bound at construction * time. * * @param request The request to initiate the operation. * @param context {@link ApiCallContext} to make the call with * @return {@link OperationFuture} for the call result */ @Override public OperationFuture futureCall( RequestT request, ApiCallContext context) { return futureCall(initialCallable.futureCall(request, context)); } OperationFutureImpl futureCall(ApiFuture initialFuture) { RecheckingCallable callable = new RecheckingCallable<>( new OperationCheckingCallable(longRunningClient, initialFuture), executor); RetryingFuture pollingFuture = callable.futureCall(null, null); return new OperationFutureImpl<>( pollingFuture, initialFuture, responseTransformer, metadataTransformer); } /** * Creates a new {@link OperationFuture} to watch an operation that has been initiated previously. * Note: This is not type-safe at static time; the result type can only be checked once the * operation finishes. * * @param operationName The name of the operation to resume. * @param context {@link ApiCallContext} to make the call with * @return {@link OperationFuture} for the call result. */ @Override public OperationFuture resumeFutureCall( String operationName, ApiCallContext context) { return futureCall(longRunningClient.getOperationCallable().futureCall(operationName, context)); } /** * Sends a cancellation request to the server for the operation with name {@code operationName}. * * @param operationName The name of the operation to cancel. * @param context {@link ApiCallContext} to make the call with * @return the future which completes once the operation is canceled on the server side. */ @Override public ApiFuture cancel(String operationName, ApiCallContext context) { return longRunningClient.cancelOperationCallable().futureCall(operationName, context); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy