From 6ee024f7542eda5e010c12852b7a1d387e9e5b39 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Mon, 30 Jan 2017 11:11:46 +1100 Subject: [PATCH] pr comment --- google-cloud-core/pom.xml | 2 +- .../cloud/logging/spi/DefaultLoggingRpc.java | 5 +- .../cloud/pubsub/spi/DefaultPubSubRpc.java | 50 ++++--------------- .../google/cloud/pubsub/spi/PubSubRpc.java | 1 - 4 files changed, 14 insertions(+), 44 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 6a5ca5b30f8e..47f215f24233 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.28-SNAPSHOT + 0.0.28 io.grpc diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java index b718a93733c6..1673151a315b 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java @@ -16,13 +16,14 @@ package com.google.cloud.logging.spi; +import com.google.api.gax.core.Function; +import com.google.api.gax.core.RpcFuture; import com.google.api.gax.grpc.ApiException; import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.ExecutorProvider; import com.google.api.gax.grpc.FixedChannelProvider; import com.google.api.gax.grpc.FixedExecutorProvider; import com.google.api.gax.grpc.ProviderManager; -import com.google.api.gax.grpc.RpcFuture; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.cloud.GrpcServiceOptions.ExecutorFactory; import com.google.cloud.NoCredentials; @@ -155,7 +156,7 @@ private static Future translate( } return from.catching( ApiException.class, - new RpcFuture.Function() { + new Function() { @Override public V apply(ApiException exception) { if (returnNullOnSet.contains(exception.getStatusCode().value())) { diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java index aac2504e4944..4af17e458aeb 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java @@ -16,14 +16,16 @@ package com.google.cloud.pubsub.spi; +import com.google.api.gax.core.ForwardingRpcFuture; +import com.google.api.gax.core.Function; +import com.google.api.gax.core.RpcFuture; +import com.google.api.gax.core.RpcFutureCallback; import com.google.api.gax.grpc.ApiException; import com.google.api.gax.grpc.ChannelProvider; import com.google.api.gax.grpc.ExecutorProvider; import com.google.api.gax.grpc.FixedChannelProvider; import com.google.api.gax.grpc.FixedExecutorProvider; import com.google.api.gax.grpc.ProviderManager; -import com.google.api.gax.grpc.RpcFuture; -import com.google.api.gax.grpc.RpcFutureCallback; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.cloud.GrpcServiceOptions.ExecutorFactory; import com.google.cloud.NoCredentials; @@ -65,11 +67,8 @@ import io.grpc.netty.NettyChannelBuilder; import java.io.IOException; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.joda.time.Duration; public class DefaultPubSubRpc implements PubSubRpc { @@ -107,48 +106,19 @@ protected ChannelProvider getChannelProvider() { } } - private static final class PullFutureImpl + private static final class PullFutureImpl extends ForwardingRpcFuture implements PullFuture { - - private final RpcFuture delegate; - PullFutureImpl(RpcFuture delegate) { - this.delegate = delegate; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return delegate.cancel(mayInterruptIfRunning); - } - - @Override - public PullResponse get() throws InterruptedException, ExecutionException { - return delegate.get(); - } - - @Override - public PullResponse get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, TimeoutException { - return delegate.get(timeout, unit); - } - - @Override - public boolean isCancelled() { - return delegate.isCancelled(); - } - - @Override - public boolean isDone() { - return delegate.isDone(); + super(delegate); } @Override public void addCallback(final PullCallback callback) { - delegate.addCallback( + addCallback( new RpcFutureCallback() { @Override - public void onSuccess(PullResponse result) { - callback.success(result); + public void onSuccess(PullResponse response) { + callback.success(response); } @Override @@ -211,7 +181,7 @@ private static RpcFuture translate( } return from.catching( ApiException.class, - new RpcFuture.Function() { + new Function() { @Override public V apply(ApiException exception) { if (returnNullOnSet.contains(exception.getStatusCode().value())) { diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/PubSubRpc.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/PubSubRpc.java index 172f2e8dcc5f..30a5688b01c5 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/PubSubRpc.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/PubSubRpc.java @@ -40,7 +40,6 @@ import com.google.pubsub.v1.PullResponse; import com.google.pubsub.v1.Subscription; import com.google.pubsub.v1.Topic; - import java.util.concurrent.Future; public interface PubSubRpc extends AutoCloseable {