Skip to content

Commit 20d2bf9

Browse files
authored
---
yaml --- r: 9211 b: refs/heads/master c: c96f1f3 h: refs/heads/master i: 9209: 3c6ddb2 9207: 4433082
1 parent 2b4dbdd commit 20d2bf9

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3dc830ea7d536c808eed3cdea8ea77c59f725719
2+
refs/heads/master: c96f1f3c92150fc037f1249841d9c0601612d701
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: c44712253909b883eff39836632d6fa5763aa5af
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import com.google.cloud.pubsub.v1.AckReplyConsumer;
3333
import com.google.cloud.pubsub.v1.MessageReceiver;
3434
import com.google.cloud.pubsub.v1.Subscriber;
35-
import com.google.cloud.pubsub.v1.stub.SubscriberStubSettings;
3635
import com.google.cloud.pubsub.v1.stub.GrpcSubscriberStub;
3736
import com.google.cloud.pubsub.v1.stub.SubscriberStub;
37+
import com.google.cloud.pubsub.v1.stub.SubscriberStubSettings;
3838
import com.google.common.util.concurrent.MoreExecutors;
3939
import com.google.pubsub.v1.AcknowledgeRequest;
4040
import com.google.pubsub.v1.ProjectSubscriptionName;
@@ -45,7 +45,8 @@
4545
import java.io.FileInputStream;
4646
import java.util.ArrayList;
4747
import java.util.List;
48-
import java.util.concurrent.Executor;
48+
import java.util.concurrent.ExecutorService;
49+
import java.util.concurrent.Executors;
4950

5051
/** This class contains snippets for the {@link Subscriber} interface. */
5152
public class SubscriberSnippets {
@@ -56,29 +57,26 @@ public class SubscriberSnippets {
5657

5758
private final ApiFuture<Void> done;
5859

59-
private final Executor executor;
60-
6160
public SubscriberSnippets(
6261
ProjectSubscriptionName subscriptionName,
6362
MessageReceiver receiver,
64-
ApiFuture<Void> done,
65-
Executor executor) {
63+
ApiFuture<Void> done) {
6664
this.subscriptionName = subscriptionName;
6765
this.receiver = receiver;
6866
this.done = done;
69-
this.executor = executor;
7067
}
7168

7269
// [TARGET startAsync()]
7370
public void startAndWait() throws Exception {
7471
Subscriber subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
72+
ExecutorService pool = Executors.newCachedThreadPool();
7573
subscriber.addListener(
7674
new Subscriber.Listener() {
7775
public void failed(Subscriber.State from, Throwable failure) {
7876
// Handle error.
7977
}
8078
},
81-
executor);
79+
pool);
8280
subscriber.startAsync();
8381

8482
// Wait for a stop signal.
@@ -97,6 +95,7 @@ public void failed(Subscriber.State from, Throwable failure) {
9795
// }
9896
// at the end of main() to previent the main thread from exiting.
9997
done.get();
98+
pool.shutdown();
10099
subscriber.stopAsync().awaitTerminated();
101100
}
102101

trunk/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public void onFailure(Throwable t) {
108108
new SubscriberSnippets(
109109
subscriptionName,
110110
new MessageReceiverSnippets(queue).messageReceiver(),
111-
done,
112-
MoreExecutors.directExecutor());
111+
done);
113112
new Thread(
114113
new Runnable() {
115114
@Override

0 commit comments

Comments
 (0)