Skip to content

Commit 9007293

Browse files
committed
---
yaml --- r: 4931 b: refs/heads/logging-alpha c: 3208eb3 h: refs/heads/master i: 4929: 91e2d01 4927: 8c3f093
1 parent 20a2eb8 commit 9007293

69 files changed

Lines changed: 16397 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: 20e5280d6f1182ff51b564d1b88885146d4f1379
15+
refs/heads/logging-alpha: 3208eb30efc7eee8f2b90ff7f36cd3d74167a398
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import com.google.cloud.ServiceOptions;
19+
import com.google.cloud.HttpServiceOptions;
20+
import com.google.common.collect.ImmutableSet;
2021
import com.google.cloud.bigquery.spi.BigQueryRpc;
2122
import com.google.cloud.bigquery.spi.BigQueryRpcFactory;
2223
import com.google.cloud.bigquery.spi.DefaultBigQueryRpc;
23-
import com.google.common.collect.ImmutableSet;
2424

2525
import java.util.Set;
2626

27-
public class BigQueryOptions extends ServiceOptions<BigQuery, BigQueryRpc, BigQueryOptions> {
27+
public class BigQueryOptions extends HttpServiceOptions<BigQuery, BigQueryRpc, BigQueryOptions> {
2828

2929
private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery";
3030
private static final Set<String> SCOPES = ImmutableSet.of(BIGQUERY_SCOPE);
31-
private static final long serialVersionUID = -215981591481708043L;
31+
private static final long serialVersionUID = -8592198255032667206L;
3232

3333
public static class DefaultBigqueryFactory implements BigQueryFactory {
3434

@@ -51,7 +51,7 @@ public BigQueryRpc create(BigQueryOptions options) {
5151
}
5252

5353
public static class Builder extends
54-
ServiceOptions.Builder<BigQuery, BigQueryRpc, BigQueryOptions, Builder> {
54+
HttpServiceOptions.Builder<BigQuery, BigQueryRpc, BigQueryOptions, Builder> {
5555

5656
private Builder() {
5757
}

branches/logging-alpha/gcloud-java-compute/src/main/java/com/google/cloud/compute/ComputeOptions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.compute;
1818

19+
import com.google.cloud.HttpServiceOptions;
1920
import com.google.cloud.ServiceOptions;
2021
import com.google.cloud.compute.spi.ComputeRpc;
2122
import com.google.cloud.compute.spi.ComputeRpcFactory;
@@ -24,7 +25,7 @@
2425

2526
import java.util.Set;
2627

27-
public class ComputeOptions extends ServiceOptions<Compute, ComputeRpc, ComputeOptions> {
28+
public class ComputeOptions extends HttpServiceOptions<Compute, ComputeRpc, ComputeOptions> {
2829

2930
private static final String COMPUTE_SCOPE = "https://www.googleapis.com/auth/compute";
3031
private static final Set<String> SCOPES = ImmutableSet.of(COMPUTE_SCOPE);
@@ -51,7 +52,7 @@ public ComputeRpc create(ComputeOptions options) {
5152
}
5253

5354
public static class Builder extends
54-
ServiceOptions.Builder<Compute, ComputeRpc, ComputeOptions, Builder> {
55+
HttpServiceOptions.Builder<Compute, ComputeRpc, ComputeOptions, Builder> {
5556

5657
private Builder() {
5758
}

branches/logging-alpha/gcloud-java-core/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,15 @@
9898
<version>3.4</version>
9999
<scope>test</scope>
100100
</dependency>
101+
<dependency>
102+
<groupId>com.google.protobuf</groupId>
103+
<artifactId>protobuf-java</artifactId>
104+
<version>3.0.0-beta-1</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>com.google.api</groupId>
108+
<artifactId>gax</artifactId>
109+
<version>0.0.13</version>
110+
</dependency>
101111
</dependencies>
102112
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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;
18+
19+
import java.util.concurrent.Future;
20+
21+
/**
22+
* Interface for asynchronously consuming Google Cloud paginated results.
23+
*
24+
* <p>Use {@code AsyncPage} to iterate through all values (also in next pages):
25+
* <pre> {@code
26+
* AsyncPage<T> page = ...; // get an AsyncPage<T> instance
27+
* Iterator<T> iterator = page.iterateAll();
28+
* while (iterator.hasNext()) {
29+
* T value = iterator.next();
30+
* // do something with value
31+
* }}</pre>
32+
*
33+
* <p>Or handle pagination explicitly:
34+
* <pre> {@code
35+
* AsyncPage<T> page = ...; // get a AsyncPage<T> instance
36+
* while (page != null) {
37+
* for (T value : page.values()) {
38+
* // do something with value
39+
* }
40+
* page = page.nextPageAsync().get();
41+
* }}</pre>
42+
*
43+
* @param <T> the value type that the page holds
44+
*/
45+
public interface AsyncPage<T> extends Page<T> {
46+
47+
/**
48+
* Returns a {@link Future} object for the next page. {@link Future#get()} returns {@code null} if
49+
* the last page has been reached.
50+
*/
51+
Future<AsyncPage<T>> nextPageAsync();
52+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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;
18+
19+
import com.google.common.base.Throwables;
20+
import com.google.common.util.concurrent.Futures;
21+
import com.google.common.util.concurrent.Uninterruptibles;
22+
23+
import java.io.Serializable;
24+
import java.util.concurrent.ExecutionException;
25+
import java.util.concurrent.Future;
26+
27+
/**
28+
* Base implementation for asynchronously consuming Google Cloud paginated results.
29+
*
30+
* @param <T> the value type that the page holds
31+
*/
32+
public class AsyncPageImpl<T> extends PageImpl<T> implements AsyncPage<T> {
33+
34+
private static final long serialVersionUID = -6009473188630364906L;
35+
36+
private final NextPageFetcher<T> asyncPageFetcher;
37+
38+
/**
39+
* Interface for asynchronously fetching the next page of results from the service.
40+
*
41+
* @param <T> the value type that the page holds
42+
*/
43+
public interface NextPageFetcher<T> extends Serializable {
44+
Future<AsyncPage<T>> nextPage();
45+
}
46+
47+
private static class SyncNextPageFetcher<T> implements PageImpl.NextPageFetcher<T> {
48+
49+
private static final long serialVersionUID = -4124568632363525351L;
50+
51+
private final NextPageFetcher<T> asyncPageFetcher;
52+
53+
private SyncNextPageFetcher(NextPageFetcher<T> asyncPageFetcher) {
54+
this.asyncPageFetcher = asyncPageFetcher;
55+
}
56+
57+
@Override
58+
public Page<T> nextPage() {
59+
try {
60+
return asyncPageFetcher != null
61+
? Uninterruptibles.getUninterruptibly(asyncPageFetcher.nextPage()) : null;
62+
} catch (ExecutionException ex) {
63+
throw Throwables.propagate(ex.getCause());
64+
}
65+
}
66+
}
67+
68+
/**
69+
* Creates an {@code AsyncPageImpl} object.
70+
*/
71+
public AsyncPageImpl(NextPageFetcher<T> asyncPageFetcher, String cursor, Iterable<T> results) {
72+
super(new SyncNextPageFetcher<T>(asyncPageFetcher), cursor, results);
73+
this.asyncPageFetcher = asyncPageFetcher;
74+
}
75+
76+
@Override
77+
public Future<AsyncPage<T>> nextPageAsync() {
78+
if (nextPageCursor() == null || asyncPageFetcher == null) {
79+
return Futures.immediateCheckedFuture(null);
80+
}
81+
return asyncPageFetcher.nextPage();
82+
}
83+
}

branches/logging-alpha/gcloud-java-core/src/main/java/com/google/cloud/BaseServiceException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.api.client.googleapis.json.GoogleJsonError;
2020
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
21+
import com.google.api.gax.grpc.ApiException;
2122
import com.google.common.base.MoreObjects;
2223

2324
import java.io.IOException;
@@ -167,6 +168,16 @@ public BaseServiceException(int code, String message, String reason, boolean ide
167168
this.debugInfo = null;
168169
}
169170

171+
public BaseServiceException(ApiException apiException, boolean idempotent) {
172+
super(apiException.getMessage(), apiException);
173+
this.code = apiException.getStatusCode().value();
174+
this.reason = apiException.getStatusCode().name();
175+
this.idempotent = idempotent;
176+
this.retryable = apiException.isRetryable();
177+
this.location = null;
178+
this.debugInfo = null;
179+
}
180+
170181
protected Set<Error> retryableErrors() {
171182
return Collections.emptySet();
172183
}

0 commit comments

Comments
 (0)