Skip to content

Commit f9dccb8

Browse files
committed
---
yaml --- r: 1053 b: refs/heads/master c: 03dbc8c h: refs/heads/master i: 1051: d6eb242 v: v3
1 parent 67aac07 commit f9dccb8

41 files changed

Lines changed: 1372 additions & 478 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: 291486dd5a8d97b96b417e0884ce64a4e1699b18
2+
refs/heads/master: 03dbc8cfdeb123783209b4543e9aeae7dcc329b6
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/README.md

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
99

1010
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
1111
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs)
12-
- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html)
1312

1413
This client supports the following Google Cloud Platform services:
1514

1615
- [Google Cloud Datastore] (#google-cloud-datastore)
1716
- [Google Cloud Storage] (#google-cloud-storage)
1817

19-
<!---
20-
- [Google Cloud Storage] (https://cloud.google.com/storage/)
21-
--->
22-
2318
> Note: This client is a work-in-progress, and may occasionally
2419
> make backwards-incompatible changes.
2520
@@ -30,32 +25,39 @@ Add this to your pom.xml file
3025
<dependency>
3126
<groupId>com.google.gcloud</groupId>
3227
<artifactId>gcloud-java</artifactId>
33-
<version>0.0.9</version>
28+
<version>0.0.10</version>
3429
</dependency>
3530
```
3631

37-
<!---
3832
Example Applications
3933
--------------------
4034

41-
- `java-datastore-sample`_ - A sample using Cloud Datastore
42-
.. _java-datastore-sample: https://github.com/GoogleCloudPlatform/java-datastore-sample
43-
--->
35+
- [`DatastoreExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java) - A simple command line interface for the Cloud Datastore
36+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/DatastoreExample.html).
37+
- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
38+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).
39+
40+
Authentication
41+
--------------
42+
43+
There are multiple ways to authenticate to use Google Cloud services.
44+
45+
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
46+
2. When using `gcloud-java` libraries elsewhere, there are two options:
47+
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). Supply a path to the downloaded JSON credentials file when building the options supplied to datastore/storage constructor.
48+
* If running locally for development/testing, you can use use [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK authentication, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already. Then login using the SDK (`gcloud auth login` in command line), and set your current project using `gcloud config set project PROJECT_ID`.
4449

4550
Google Cloud Datastore
4651
----------------------
4752

48-
[Google Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
49-
storing non-relational data. Cloud Datastore automatically scales with
50-
your users and supports ACID transactions, high availability of reads and
51-
writes, strong consistency for reads and ancestor queries, and eventual
52-
consistency for all other queries.
53+
- [API Documentation][datastore-api]
54+
- [Official Documentation][cloud-datastore-docs]
55+
56+
*Follow the [activation instructions][cloud-datastore-activation] to use the Google Cloud Datastore API with your project.*
5357

54-
See the [Google Cloud Datastore docs][cloud-datastore-activation] for more details on how to activate
55-
Cloud Datastore for your project.
58+
#### Preview
5659

57-
See the ``gcloud-java`` API [datastore documentation][datastore-api] to learn how to interact
58-
with the Cloud Datastore using this Client Library.
60+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
5961

6062
```java
6163
import com.google.gcloud.datastore.Datastore;
@@ -66,8 +68,7 @@ import com.google.gcloud.datastore.Entity;
6668
import com.google.gcloud.datastore.Key;
6769
import com.google.gcloud.datastore.KeyFactory;
6870

69-
DatastoreOptions options = DatastoreOptions.builder().projectId(PROJECT_ID).build();
70-
Datastore datastore = DatastoreFactory.instance().get(options);
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);
@@ -90,35 +91,36 @@ if (entity == null) {
9091
Google Cloud Storage
9192
----------------------
9293

93-
[Google Cloud Storage][cloud-storage] is a durable and highly available
94-
object storage service. Google Cloud Storage is almost infinitely scalable
95-
and guarantees consistency: when a write succeeds, the latest copy of the
96-
object will be returned to any GET, globally.
94+
- [API Documentation][storage-api]
95+
- [Official Documentation][cloud-storage-docs]
9796

98-
See the [Google Cloud Storage docs][cloud-storage-activation] for more details on how to activate
99-
Cloud Storage for your project.
97+
*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.*
10098

101-
See the ``gcloud-java`` API [storage documentation][storage-api] to learn how to interact
102-
with the Cloud Storage using this Client Library.
99+
#### Preview
100+
101+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
103102

104103
```java
105104
import static java.nio.charset.StandardCharsets.UTF_8;
106105

107106
import com.google.gcloud.storage.Blob;
107+
import com.google.gcloud.storage.BlobId;
108108
import com.google.gcloud.storage.Storage;
109109
import com.google.gcloud.storage.StorageFactory;
110110
import com.google.gcloud.storage.StorageOptions;
111111

112112
import java.nio.ByteBuffer;
113113
import java.nio.channels.WritableByteChannel;
114114

115-
StorageOptions options = StorageOptions.builder().projectId(PROJECT_ID).build();
115+
StorageOptions options = StorageOptions.builder().projectId("project").build();
116116
Storage storage = StorageFactory.instance().get(options);
117-
Blob blob = new Blob(storage, "bucket", "blob_name");
118-
if (!blob.exists()) {
119-
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));
117+
BlobId blobId = BlobId.of("bucket", "blob_name");
118+
Blob blob = Blob.load(storage, blobId);
119+
if (blob == null) {
120+
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
121+
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
120122
} else {
121-
System.out.println("Updating content for " + blob.info().name());
123+
System.out.println("Updating content for " + blobId.name());
122124
byte[] prevContent = blob.content();
123125
System.out.println(new String(prevContent, UTF_8));
124126
WritableByteChannel channel = blob.writer();
@@ -127,27 +129,18 @@ if (!blob.exists()) {
127129
}
128130
```
129131

132+
Java Versions
133+
-------------
134+
135+
Java 7 or above is required for using this client.
136+
130137
Testing
131138
-------
132139

133140
This library provides tools to help write tests for code that uses gcloud-java services.
134141

135142
See [TESTING] to read more about using our testing helpers.
136143

137-
Contributing
138-
------------
139-
140-
Contributions to this library are always welcome and highly encouraged.
141-
142-
See [CONTRIBUTING] for more information on how to get started.
143-
144-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
145-
146-
Java Versions
147-
-------------
148-
149-
Java 7 or above is required for using this client.
150-
151144
Versioning
152145
----------
153146

@@ -157,6 +150,15 @@ It is currently in major version zero (``0.y.z``), which means that anything
157150
may change at any time and the public API should not be considered
158151
stable.
159152

153+
Contributing
154+
------------
155+
156+
Contributions to this library are always welcome and highly encouraged.
157+
158+
See [CONTRIBUTING] for more information on how to get started.
159+
160+
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
161+
160162
License
161163
-------
162164

trunk/gcloud-java-core/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ This module provides common functionality required by service-specific modules o
55

66
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
77
[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
8+
[![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)
89

910
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
1011
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html)
11-
- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html)
1212

1313
Quickstart
1414
----------
@@ -17,22 +17,22 @@ Add this to your pom.xml file
1717
<dependency>
1818
<groupId>com.google.gcloud</groupId>
1919
<artifactId>gcloud-java-core</artifactId>
20-
<version>0.0.9</version>
20+
<version>0.0.10</version>
2121
</dependency>
2222
```
2323

24+
Java Versions
25+
-------------
26+
27+
Java 7 or above is required for using this client.
28+
2429
Contributing
2530
------------
2631

2732
Contributions to this library are always welcome and highly encouraged.
2833

2934
See [CONTRIBUTING] for more information on how to get started.
3035

31-
Java Versions
32-
-------------
33-
34-
Java 7 or above is required for using this client.
35-
3636
Versioning
3737
----------
3838

trunk/gcloud-java-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>com.google.gcloud</groupId>
1313
<artifactId>gcloud-java-pom</artifactId>
14-
<version>0.0.10-SNAPSHOT</version>
14+
<version>0.0.11-SNAPSHOT</version>
1515
</parent>
1616
<dependencies>
1717
<dependency>

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.IOException;
3535
import java.io.InputStream;
3636
import java.io.InputStreamReader;
37+
import java.io.ObjectStreamException;
3738
import java.io.Serializable;
3839
import java.lang.reflect.Method;
3940
import java.net.HttpURLConnection;
@@ -62,6 +63,7 @@ public abstract class ServiceOptions<
6263
private final ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory;
6364
private final int connectTimeout;
6465
private final int readTimeout;
66+
private final Clock clock;
6567

6668
public interface HttpTransportFactory extends Serializable {
6769
HttpTransport create();
@@ -91,7 +93,44 @@ public HttpTransport create() {
9193
}
9294
}
9395

96+
/**
97+
* A class providing access to the current time in milliseconds. This class is mainly used for
98+
* testing and will be replaced by Java8's {@code java.time.Clock}.
99+
*
100+
* Implementations should implement {@code Serializable} wherever possible and must document
101+
* whether or not they do support serialization.
102+
*/
103+
public static abstract class Clock {
94104

105+
private static ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock();
106+
107+
/**
108+
* Returns current time in milliseconds according to this clock.
109+
*/
110+
public abstract long millis();
111+
112+
/**
113+
* Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time
114+
* in milliseconds.
115+
*/
116+
public static ServiceOptions.Clock defaultClock() {
117+
return DEFAULT_TIME_SOURCE;
118+
}
119+
120+
private static class DefaultClock extends ServiceOptions.Clock implements Serializable {
121+
122+
private static final long serialVersionUID = -5077300394286703864L;
123+
124+
@Override
125+
public long millis() {
126+
return System.currentTimeMillis();
127+
}
128+
129+
private Object readResolve() throws ObjectStreamException {
130+
return DEFAULT_TIME_SOURCE;
131+
}
132+
}
133+
}
95134

96135
protected abstract static class Builder<
97136
ServiceRpcT,
@@ -106,6 +145,7 @@ protected abstract static class Builder<
106145
private ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory;
107146
private int connectTimeout = -1;
108147
private int readTimeout = -1;
148+
private Clock clock;
109149

110150
protected Builder() {}
111151

@@ -125,6 +165,18 @@ protected B self() {
125165
return (B) this;
126166
}
127167

168+
/**
169+
* Sets the service's clock. The clock is mainly used for testing purpose. {@link Clock} will be
170+
* replaced by Java8's {@code java.time.Clock}.
171+
*
172+
* @param clock the clock to set
173+
* @return the builder.
174+
*/
175+
public B clock(Clock clock) {
176+
this.clock = clock;
177+
return self();
178+
}
179+
128180
/**
129181
* Sets project id.
130182
*
@@ -221,6 +273,7 @@ protected ServiceOptions(Builder<ServiceRpcT, OptionsT, ?> builder) {
221273
serviceRpcFactory = builder.serviceRpcFactory;
222274
connectTimeout = builder.connectTimeout;
223275
readTimeout = builder.readTimeout;
276+
clock = firstNonNull(builder.clock, Clock.defaultClock());
224277
}
225278

226279
private static AuthCredentials defaultAuthCredentials() {
@@ -419,9 +472,17 @@ public int readTimeout() {
419472
return readTimeout;
420473
}
421474

475+
/**
476+
* Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to
477+
* get current time.
478+
*/
479+
public Clock clock() {
480+
return clock;
481+
}
482+
422483
protected int baseHashCode() {
423484
return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams,
424-
serviceRpcFactory);
485+
serviceRpcFactory, connectTimeout, readTimeout, clock);
425486
}
426487

427488
protected boolean baseEquals(ServiceOptions<?, ?> other) {
@@ -430,7 +491,10 @@ protected boolean baseEquals(ServiceOptions<?, ?> other) {
430491
&& Objects.equals(httpTransportFactory, other.httpTransportFactory)
431492
&& Objects.equals(authCredentials, other.authCredentials)
432493
&& Objects.equals(retryParams, other.retryParams)
433-
&& Objects.equals(serviceRpcFactory, other.serviceRpcFactory);
494+
&& Objects.equals(serviceRpcFactory, other.serviceRpcFactory)
495+
&& Objects.equals(connectTimeout, other.connectTimeout)
496+
&& Objects.equals(readTimeout, other.readTimeout)
497+
&& Objects.equals(clock, clock);
434498
}
435499

436500
public abstract Builder<ServiceRpcT, OptionsT, ?> toBuilder();

0 commit comments

Comments
 (0)