Skip to content

Commit 752fab0

Browse files
committed
Make PullFutureImpl extend SimpleForwardingListenableFuture
1 parent 73f20de commit 752fab0

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.cloud.pubsub.spi.v1.SubscriberSettings;
3232
import com.google.common.base.Function;
3333
import com.google.common.collect.Sets;
34+
import com.google.common.util.concurrent.ForwardingListenableFuture;
3435
import com.google.common.util.concurrent.FutureCallback;
3536
import com.google.common.util.concurrent.Futures;
3637
import com.google.common.util.concurrent.ListenableFuture;
@@ -64,11 +65,8 @@
6465

6566
import java.io.IOException;
6667
import java.util.Set;
67-
import java.util.concurrent.ExecutionException;
6868
import java.util.concurrent.Future;
6969
import java.util.concurrent.ScheduledExecutorService;
70-
import java.util.concurrent.TimeUnit;
71-
import java.util.concurrent.TimeoutException;
7270

7371
public class DefaultPubSubRpc implements PubSubRpc {
7472

@@ -93,43 +91,17 @@ protected ExecutorFactory executorFactory() {
9391
}
9492
}
9593

96-
private static final class PullFutureImpl implements PullFuture {
97-
98-
private final ListenableFuture<PullResponse> delegate;
94+
private static final class PullFutureImpl
95+
extends ForwardingListenableFuture.SimpleForwardingListenableFuture<PullResponse>
96+
implements PullFuture {
9997

10098
PullFutureImpl(ListenableFuture<PullResponse> delegate) {
101-
this.delegate = delegate;
102-
}
103-
104-
@Override
105-
public boolean cancel(boolean mayInterruptIfRunning) {
106-
return delegate.cancel(mayInterruptIfRunning);
107-
}
108-
109-
@Override
110-
public boolean isCancelled() {
111-
return delegate.isCancelled();
112-
}
113-
114-
@Override
115-
public boolean isDone() {
116-
return delegate.isDone();
117-
}
118-
119-
@Override
120-
public PullResponse get() throws InterruptedException, ExecutionException {
121-
return delegate.get();
122-
}
123-
124-
@Override
125-
public PullResponse get(long timeout, TimeUnit unit) throws InterruptedException,
126-
ExecutionException, TimeoutException {
127-
return delegate.get(timeout, unit);
99+
super(delegate);
128100
}
129101

130102
@Override
131103
public void addCallback(final PullCallback callback) {
132-
Futures.addCallback(delegate, new FutureCallback<PullResponse>() {
104+
Futures.addCallback(delegate(), new FutureCallback<PullResponse>() {
133105
@Override
134106
public void onSuccess(PullResponse result) {
135107
callback.success(result);

0 commit comments

Comments
 (0)