Skip to content

Commit 3a81b35

Browse files
committed
---
yaml --- r: 1103 b: refs/heads/master c: 855a9d1 h: refs/heads/master i: 1101: c26809e 1099: 95bafd1 1095: ba8714b 1087: 286899b v: v3
1 parent d863d0b commit 3a81b35

57 files changed

Lines changed: 775 additions & 872 deletions

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
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: 736a0f573ebbd6b2b656d93f0c8ac254fc3c24c8
2+
refs/heads/master: 855a9d1290ab2fe726ad6847cedde5dd02eefd47
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ Here is a code snippet showing a simple usage example from within Compute/App En
6161

6262
```java
6363
import com.google.gcloud.datastore.Datastore;
64+
import com.google.gcloud.datastore.DatastoreFactory;
6465
import com.google.gcloud.datastore.DatastoreOptions;
6566
import com.google.gcloud.datastore.DateTime;
6667
import com.google.gcloud.datastore.Entity;
6768
import com.google.gcloud.datastore.Key;
6869
import com.google.gcloud.datastore.KeyFactory;
6970

70-
Datastore datastore = DatastoreOptions.getDefaultInstance().service();
71+
Datastore datastore = DatastoreFactory.instance().get(DatastoreOptions.getDefaultInstance());
7172
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
7273
Key key = keyFactory.newKey(keyName);
7374
Entity entity = datastore.get(key);
@@ -105,13 +106,14 @@ import static java.nio.charset.StandardCharsets.UTF_8;
105106
import com.google.gcloud.storage.Blob;
106107
import com.google.gcloud.storage.BlobId;
107108
import com.google.gcloud.storage.Storage;
109+
import com.google.gcloud.storage.StorageFactory;
108110
import com.google.gcloud.storage.StorageOptions;
109111

110112
import java.nio.ByteBuffer;
111113
import java.nio.channels.WritableByteChannel;
112114

113115
StorageOptions options = StorageOptions.builder().projectId("project").build();
114-
Storage storage = options.service();
116+
Storage storage = StorageFactory.instance().get(options);
115117
BlobId blobId = BlobId.of("bucket", "blob_name");
116118
Blob blob = Blob.load(storage, blobId);
117119
if (blob == null) {

trunk/TESTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can test against a temporary local datastore by following these steps:
1818
.projectId(PROJECT_ID)
1919
.host("http://localhost:8080")
2020
.build();
21-
Datastore localDatastore = options.service();
21+
Datastore localDatastore = DatastoreFactory.instance().get(options);
2222
```
2323
3. Run your tests.
2424

@@ -35,7 +35,7 @@ You can test against a remote datastore emulator as well. To do this, set the `
3535
.projectId(PROJECT_ID)
3636
.host("http://<hostname of machine>:<port>")
3737
.build();
38-
Datastore localDatastore = options.service();
38+
Datastore localDatastore = DatastoreFactory.instance().get(options);
3939
```
4040

4141
Note that the remote datastore must be running before your tests are run.
@@ -52,7 +52,7 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i
5252
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
5353
```java
5454
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
55-
Storage storage = gcsHelper.options().service();
55+
Storage storage = StorageFactory.instance().get(gcsHelper.options());
5656
String bucket = RemoteGcsHelper.generateBucketName();
5757
storage.create(BucketInfo.of(bucket));
5858
```

trunk/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 39 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import java.io.IOException;
3333
import java.io.InputStream;
34+
import java.io.ObjectInputStream;
35+
import java.io.ObjectStreamException;
3436
import java.io.Serializable;
3537
import java.security.GeneralSecurityException;
3638
import java.security.PrivateKey;
@@ -40,91 +42,35 @@
4042
/**
4143
* Credentials for accessing Google Cloud services.
4244
*/
43-
public abstract class AuthCredentials implements Restorable<AuthCredentials> {
45+
public abstract class AuthCredentials implements Serializable {
4446

45-
private static class AppEngineAuthCredentials extends AuthCredentials {
46-
47-
private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials();
48-
private static final AppEngineAuthCredentialsState STATE =
49-
new AppEngineAuthCredentialsState();
50-
51-
private static class AppEngineAuthCredentialsState
52-
implements RestorableState<AuthCredentials>, Serializable {
47+
private static final long serialVersionUID = 236297804453464604L;
5348

54-
private static final long serialVersionUID = 3558563960848658928L;
55-
56-
@Override
57-
public AuthCredentials restore() {
58-
return INSTANCE;
59-
}
49+
private static class AppEngineAuthCredentials extends AuthCredentials {
6050

61-
@Override
62-
public int hashCode() {
63-
return getClass().getName().hashCode();
64-
}
51+
private static final long serialVersionUID = 7931300552744202954L;
6552

66-
@Override
67-
public boolean equals(Object obj) {
68-
return obj instanceof AppEngineAuthCredentialsState;
69-
}
70-
}
53+
private static final AuthCredentials INSTANCE = new AppEngineAuthCredentials();
7154

7255
@Override
7356
protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
7457
Set<String> scopes) {
7558
return new AppIdentityCredential(scopes);
7659
}
7760

78-
@Override
79-
public RestorableState<AuthCredentials> capture() {
80-
return STATE;
61+
private Object readResolve() throws ObjectStreamException {
62+
return INSTANCE;
8163
}
8264
}
8365

8466
public static class ServiceAccountAuthCredentials extends AuthCredentials {
8567

68+
private static final long serialVersionUID = 8007708734318445901L;
8669
private final String account;
8770
private final PrivateKey privateKey;
8871

8972
private static final AuthCredentials NO_CREDENTIALS = new ServiceAccountAuthCredentials();
9073

91-
private static class ServiceAccountAuthCredentialsState
92-
implements RestorableState<AuthCredentials>, Serializable {
93-
94-
private static final long serialVersionUID = -7302180782414633639L;
95-
96-
private final String account;
97-
private final PrivateKey privateKey;
98-
99-
private ServiceAccountAuthCredentialsState(String account, PrivateKey privateKey) {
100-
this.account = account;
101-
this.privateKey = privateKey;
102-
}
103-
104-
@Override
105-
public AuthCredentials restore() {
106-
if (account == null && privateKey == null) {
107-
return NO_CREDENTIALS;
108-
}
109-
return new ServiceAccountAuthCredentials(account, privateKey);
110-
}
111-
112-
@Override
113-
public int hashCode() {
114-
return Objects.hash(account, privateKey);
115-
}
116-
117-
@Override
118-
public boolean equals(Object obj) {
119-
if (!(obj instanceof ServiceAccountAuthCredentialsState)) {
120-
return false;
121-
}
122-
ServiceAccountAuthCredentialsState other = (ServiceAccountAuthCredentialsState) obj;
123-
return Objects.equals(account, other.account)
124-
&& Objects.equals(privateKey, other.privateKey);
125-
}
126-
}
127-
12874
ServiceAccountAuthCredentials(String account, PrivateKey privateKey) {
12975
this.account = checkNotNull(account);
13076
this.privateKey = checkNotNull(privateKey);
@@ -158,94 +104,59 @@ public PrivateKey privateKey() {
158104
}
159105

160106
@Override
161-
public RestorableState<AuthCredentials> capture() {
162-
return new ServiceAccountAuthCredentialsState(account, privateKey);
107+
public int hashCode() {
108+
return Objects.hash(account, privateKey);
109+
}
110+
111+
@Override
112+
public boolean equals(Object obj) {
113+
if (!(obj instanceof ServiceAccountAuthCredentials)) {
114+
return false;
115+
}
116+
ServiceAccountAuthCredentials other = (ServiceAccountAuthCredentials) obj;
117+
return Objects.equals(account, other.account)
118+
&& Objects.equals(privateKey, other.privateKey);
163119
}
164120
}
165121

166122
private static class ComputeEngineAuthCredentials extends AuthCredentials {
167123

168-
private ComputeCredential computeCredential;
124+
private static final long serialVersionUID = -5217355402127260144L;
169125

170-
private static final ComputeEngineAuthCredentialsState STATE =
171-
new ComputeEngineAuthCredentialsState();
172-
173-
private static class ComputeEngineAuthCredentialsState
174-
implements RestorableState<AuthCredentials>, Serializable {
175-
176-
private static final long serialVersionUID = -6168594072854417404L;
177-
178-
@Override
179-
public AuthCredentials restore() {
180-
try {
181-
return new ComputeEngineAuthCredentials();
182-
} catch (IOException | GeneralSecurityException e) {
183-
throw new IllegalStateException(
184-
"Could not restore " + ComputeEngineAuthCredentials.class.getSimpleName(), e);
185-
}
186-
}
187-
188-
@Override
189-
public int hashCode() {
190-
return getClass().getName().hashCode();
191-
}
192-
193-
@Override
194-
public boolean equals(Object obj) {
195-
return obj instanceof ComputeEngineAuthCredentialsState;
196-
}
197-
}
126+
private transient ComputeCredential computeCredential;
198127

199128
ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException {
200129
computeCredential = getComputeCredential();
201130
}
202131

132+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
133+
in.defaultReadObject();
134+
try {
135+
computeCredential = getComputeCredential();
136+
} catch (GeneralSecurityException e) {
137+
throw new IOException(e);
138+
}
139+
}
140+
203141
@Override
204142
protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
205143
Set<String> scopes) {
206144
return computeCredential;
207145
}
208-
209-
@Override
210-
public RestorableState<AuthCredentials> capture() {
211-
return STATE;
212-
}
213146
}
214147

215148
private static class ApplicationDefaultAuthCredentials extends AuthCredentials {
216149

217-
private GoogleCredentials googleCredentials;
218-
219-
private static final ApplicationDefaultAuthCredentialsState STATE =
220-
new ApplicationDefaultAuthCredentialsState();
221-
222-
private static class ApplicationDefaultAuthCredentialsState
223-
implements RestorableState<AuthCredentials>, Serializable {
224-
225-
private static final long serialVersionUID = -8839085552021212257L;
150+
private static final long serialVersionUID = -8306873864136099893L;
226151

227-
@Override
228-
public AuthCredentials restore() {
229-
try {
230-
return new ApplicationDefaultAuthCredentials();
231-
} catch (IOException e) {
232-
throw new IllegalStateException(
233-
"Could not restore " + ApplicationDefaultAuthCredentials.class.getSimpleName(), e);
234-
}
235-
}
236-
237-
@Override
238-
public int hashCode() {
239-
return getClass().getName().hashCode();
240-
}
152+
private transient GoogleCredentials googleCredentials;
241153

242-
@Override
243-
public boolean equals(Object obj) {
244-
return obj instanceof ApplicationDefaultAuthCredentialsState;
245-
}
154+
ApplicationDefaultAuthCredentials() throws IOException {
155+
googleCredentials = GoogleCredentials.getApplicationDefault();
246156
}
247157

248-
ApplicationDefaultAuthCredentials() throws IOException {
158+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
159+
in.defaultReadObject();
249160
googleCredentials = GoogleCredentials.getApplicationDefault();
250161
}
251162

@@ -254,11 +165,6 @@ protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
254165
Set<String> scopes) {
255166
return new HttpCredentialsAdapter(googleCredentials);
256167
}
257-
258-
@Override
259-
public RestorableState<AuthCredentials> capture() {
260-
return STATE;
261-
}
262168
}
263169

264170
protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport,

trunk/gcloud-java-core/src/main/java/com/google/gcloud/BaseService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.gcloud;
1818

19-
public abstract class BaseService<OptionsT extends ServiceOptions<?, ?, OptionsT>>
19+
public abstract class BaseService<OptionsT extends ServiceOptions<?, OptionsT>>
2020
implements Service<OptionsT> {
2121

2222
private final OptionsT options;

trunk/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

trunk/gcloud-java-core/src/main/java/com/google/gcloud/RestorableState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Implementations of this class must implement {@link java.io.Serializable} to ensure that the
2424
* state of a the object can be correctly serialized.
2525
*/
26-
public interface RestorableState<T extends Restorable<T>> {
26+
public interface RestorableState<T> {
2727

2828
/**
2929
* Returns an object whose internal state reflects the one saved in the invocation object.

trunk/gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ public double getRetryDelayBackoffFactor() {
251251
}
252252

253253
/**
254-
* Returns the totalRetryPeriodMillis. Default value is
255-
* {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}.
254+
* Returns the totalRetryPeriodMillis. Default value is {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}.
256255
*/
257256
public long getTotalRetryPeriodMillis() {
258257
return totalRetryPeriodMillis;

trunk/gcloud-java-core/src/main/java/com/google/gcloud/Service.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
package com.google.gcloud;
1818

19-
public interface Service<OptionsT extends ServiceOptions<?, ?, OptionsT>> {
19+
public interface Service<OptionsT extends ServiceOptions<?, OptionsT>> {
2020
OptionsT options();
2121
}

0 commit comments

Comments
 (0)