Skip to content

Commit dc5a4d1

Browse files
committed
---
yaml --- r: 3877 b: refs/heads/pubsub-alpha c: 9879a16 h: refs/heads/master i: 3875: a862147
1 parent ea9494d commit dc5a4d1

14 files changed

Lines changed: 514 additions & 33 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 36a62ef856d199f8efd09501b5ba65c422c01f23
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
5-
refs/heads/pubsub-alpha: 6bc34ff43eca99a95472d3d4e014cc062fdef200
5+
refs/heads/pubsub-alpha: 9879a16ee47bda2df53b39d344a1eedd078193ff
66
refs/heads/update-datastore: 47aae517c2cb33f1dccd909adaced73ec9d0f4df
77
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
88
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/cloud/AsyncPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
* for (T value : page.values()) {
3838
* // do something with value
3939
* }
40-
* page = page.nextPage().get();
40+
* page = page.nextPageAsync().get();
4141
* }}</pre>
4242
*
4343
* @param <T> the value type that the page holds
4444
*/
4545
public interface AsyncPage<T> extends Page<T> {
4646

4747
/**
48-
* Returns a {@link Future} object for the next page.
48+
* Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if
49+
* the last page has been reached.
4950
*/
5051
Future<AsyncPage<T>> nextPageAsync();
5152
}

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/cloud/AsyncPageImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud;
1818

1919
import com.google.common.base.Throwables;
20+
import com.google.common.util.concurrent.Futures;
2021
import com.google.common.util.concurrent.Uninterruptibles;
2122

2223
import java.io.Serializable;
@@ -47,7 +48,7 @@ private static class SyncNextPageFetcher<T> implements PageImpl.NextPageFetcher<
4748

4849
private static final long serialVersionUID = -4124568632363525351L;
4950

50-
private NextPageFetcher<T> asyncPageFetcher;
51+
private final NextPageFetcher<T> asyncPageFetcher;
5152

5253
private SyncNextPageFetcher(NextPageFetcher<T> asyncPageFetcher) {
5354
this.asyncPageFetcher = asyncPageFetcher;
@@ -75,7 +76,7 @@ public AsyncPageImpl(NextPageFetcher<T> asyncPageFetcher, String cursor, Iterabl
7576
@Override
7677
public Future<AsyncPage<T>> nextPageAsync() {
7778
if (nextPageCursor() == null || asyncPageFetcher == null) {
78-
return null;
79+
return Futures.immediateCheckedFuture(null);
7980
}
8081
return asyncPageFetcher.nextPage();
8182
}

branches/pubsub-alpha/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/PubSub.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ public static PullOption maxConcurrentCallbacks(int maxConcurrency) {
194194

195195
Future<AsyncPage<Subscription>> listSubscriptionsAsync(ListOption... options);
196196

197-
Page<Subscription> listSubscriptions(String topic, ListOption... options);
197+
Page<SubscriptionId> listSubscriptions(String topic, ListOption... options);
198198

199-
Future<AsyncPage<Subscription>> listSubscriptionsAsync(String topic, ListOption... options);
199+
Future<AsyncPage<SubscriptionId>> listSubscriptionsAsync(String topic, ListOption... options);
200200

201201
Iterator<ReceivedMessage> pull(String subscription, PullOption... options);
202202

branches/pubsub-alpha/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/PubSubImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ public Future<AsyncPage<Subscription>> listSubscriptionsAsync(ListOption... opti
185185
}
186186

187187
@Override
188-
public Page<Subscription> listSubscriptions(String topic, ListOption... options) {
188+
public Page<SubscriptionId> listSubscriptions(String topic, ListOption... options) {
189189
return null;
190190
}
191191

192192
@Override
193-
public Future<AsyncPage<Subscription>> listSubscriptionsAsync(String topic,
193+
public Future<AsyncPage<SubscriptionId>> listSubscriptionsAsync(String topic,
194194
ListOption... options) {
195195
return null;
196196
}

branches/pubsub-alpha/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/Subscription.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,20 @@ private Builder(Subscription subscription) {
5050
}
5151

5252
@Override
53-
public Builder topic(String name) {
54-
delegate.topic(name);
53+
public Builder topic(TopicId topic) {
54+
delegate.topic(topic);
55+
return this;
56+
}
57+
58+
@Override
59+
public Builder topic(String project, String topic) {
60+
delegate.topic(project, topic);
61+
return this;
62+
}
63+
64+
@Override
65+
public Builder topic(String topic) {
66+
delegate.topic(topic);
5567
return this;
5668
}
5769

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.pubsub;
18+
19+
import static com.google.cloud.pubsub.spi.v1.SubscriberApi.parseProjectFromSubscriptionName;
20+
import static com.google.cloud.pubsub.spi.v1.SubscriberApi.parseSubscriptionFromSubscriptionName;
21+
import static com.google.common.base.Preconditions.checkNotNull;
22+
23+
import com.google.common.base.MoreObjects;
24+
25+
import java.io.Serializable;
26+
import java.util.Objects;
27+
28+
/**
29+
* Identity for a Google PubSub subscription. {@code SubscriptionId} objects are returned by the
30+
* {@link PubSub#listSubscriptions(String, PubSub.ListOption...)} and
31+
* {@link PubSub#listSubscriptionsAsync(String, PubSub.ListOption...)} methods as a topic may have
32+
* subscriptions from different projects.
33+
*/
34+
public class SubscriptionId implements Serializable {
35+
36+
private static final long serialVersionUID = 6507142968866856283L;
37+
38+
private final String project;
39+
private final String subscription;
40+
41+
SubscriptionId(String project, String subscription) {
42+
this.project = checkNotNull(project);
43+
this.subscription = checkNotNull(subscription);
44+
}
45+
46+
/**
47+
* Returns the name of the project where the subscription resides.
48+
*/
49+
public String project() {
50+
return project;
51+
}
52+
53+
/**
54+
* Returns the name of the subscription.
55+
*/
56+
public String subscription() {
57+
return subscription;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return MoreObjects.toStringHelper(this)
63+
.add("project", project)
64+
.add("subscription", subscription).toString();
65+
}
66+
67+
@Override
68+
public final int hashCode() {
69+
return Objects.hash(project, subscription);
70+
}
71+
72+
@Override
73+
public final boolean equals(Object obj) {
74+
if (obj == this) {
75+
return true;
76+
}
77+
if (!(obj instanceof SubscriptionId)) {
78+
return false;
79+
}
80+
SubscriptionId other = (SubscriptionId) obj;
81+
return Objects.equals(project, other.project)
82+
&& Objects.equals(subscription, other.subscription);
83+
}
84+
85+
static SubscriptionId fromPb(String pb) {
86+
return new SubscriptionId(parseProjectFromSubscriptionName(pb),
87+
parseSubscriptionFromSubscriptionName(pb));
88+
}
89+
}

0 commit comments

Comments
 (0)