Skip to content

Commit 15c6123

Browse files
committed
---
yaml --- r: 6259 b: refs/heads/tswast-patch-1 c: 7680281 h: refs/heads/master i: 6257: faaaee0 6255: 3d1444c
1 parent 54465d3 commit 15c6123

4 files changed

Lines changed: 122 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 494cd91d601b7063e28c30dabaca9f857fcc3f01
60+
refs/heads/tswast-patch-1: 7680281785c9ba3caaa8967ac2995261e53c38d4
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static java.nio.charset.StandardCharsets.UTF_8;
2323

2424
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
25+
import com.google.api.client.http.HttpRequest;
2526
import com.google.api.client.http.HttpRequestInitializer;
2627
import com.google.api.client.http.HttpTransport;
2728
import com.google.api.client.http.javanet.NetHttpTransport;
@@ -60,6 +61,8 @@ public abstract class ServiceOptions<
6061
private final AuthCredentials authCredentials;
6162
private final RetryParams retryParams;
6263
private final ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory;
64+
private final int connectTimeout;
65+
private final int readTimeout;
6366

6467
public interface HttpTransportFactory extends Serializable {
6568
HttpTransport create();
@@ -102,6 +105,8 @@ protected abstract static class Builder<
102105
private AuthCredentials authCredentials;
103106
private RetryParams retryParams;
104107
private ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory;
108+
private int connectTimeout = -1;
109+
private int readTimeout = -1;
105110

106111
protected Builder() {}
107112

@@ -121,35 +126,89 @@ protected B self() {
121126
return (B) this;
122127
}
123128

129+
/**
130+
* Sets project id.
131+
*
132+
* @return the builder.
133+
*/
124134
public B projectId(String projectId) {
125135
this.projectId = projectId;
126136
return self();
127137
}
128138

139+
/**
140+
* Sets service host.
141+
*
142+
* @return the builder.
143+
*/
129144
public B host(String host) {
130145
this.host = host;
131146
return self();
132147
}
133148

149+
/**
150+
* Sets the transport factory.
151+
*
152+
* @return the builder.
153+
*/
134154
public B httpTransportFactory(HttpTransportFactory httpTransportFactory) {
135155
this.httpTransportFactory = httpTransportFactory;
136156
return self();
137157
}
138158

159+
/**
160+
* Sets the service authentication credentials.
161+
*
162+
* @return the builder.
163+
*/
139164
public B authCredentials(AuthCredentials authCredentials) {
140165
this.authCredentials = authCredentials;
141166
return self();
142167
}
143168

169+
/**
170+
* Sets configuration parameters for request retries.
171+
*
172+
* @return the builder.
173+
*/
144174
public B retryParams(RetryParams retryParams) {
145175
this.retryParams = retryParams;
146176
return self();
147177
}
148178

179+
/**
180+
* Sets the factory for rpc services.
181+
*
182+
* @return the builder
183+
*/
149184
public B serviceRpcFactory(ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory) {
150185
this.serviceRpcFactory = serviceRpcFactory;
151186
return self();
152187
}
188+
189+
/**
190+
* Sets the timeout in milliseconds to establish a connection.
191+
*
192+
* @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a
193+
* negative number for the default value (20000).
194+
* @return the builder.
195+
*/
196+
public B connectTimeout(int connectTimeout) {
197+
this.connectTimeout = connectTimeout;
198+
return self();
199+
}
200+
201+
/**
202+
* Sets the timeout in milliseconds to read data from an established connection.
203+
*
204+
* @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a
205+
* negative number for the default value (20000).
206+
* @return the builder.
207+
*/
208+
public B readTimeout(int readTimeout) {
209+
this.readTimeout = readTimeout;
210+
return self();
211+
}
153212
}
154213

155214
protected ServiceOptions(Builder<ServiceRpcT, OptionsT, ?> builder) {
@@ -160,6 +219,8 @@ protected ServiceOptions(Builder<ServiceRpcT, OptionsT, ?> builder) {
160219
authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials());
161220
retryParams = builder.retryParams;
162221
serviceRpcFactory = builder.serviceRpcFactory;
222+
connectTimeout = builder.connectTimeout;
223+
readTimeout = builder.readTimeout;
163224
}
164225

165226
private static AuthCredentials defaultAuthCredentials() {
@@ -277,33 +338,84 @@ protected static String getAppEngineProjectId() {
277338

278339
protected abstract Set<String> scopes();
279340

341+
/**
342+
* Returns the project id.
343+
*/
280344
public String projectId() {
281345
return projectId;
282346
}
283347

348+
/**
349+
* Returns the service host.
350+
*/
284351
public String host() {
285352
return host;
286353
}
287354

355+
/**
356+
* Returns the transport factory.
357+
*/
288358
public HttpTransportFactory httpTransportFactory() {
289359
return httpTransportFactory;
290360
}
291361

362+
/**
363+
* Returns the authentication credentials.
364+
*/
292365
public AuthCredentials authCredentials() {
293366
return authCredentials;
294367
}
295368

369+
/**
370+
* Returns configuration parameters for request retries.
371+
*/
296372
public RetryParams retryParams() {
297373
return retryParams != null ? retryParams : RetryParams.noRetries();
298374
}
299375

376+
/**
377+
* Returns the factory for rpc services.
378+
*/
300379
public ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFactory() {
301380
return serviceRpcFactory;
302381
}
303382

383+
/**
384+
* Returns a request initializer responsible for initializing requests according to service
385+
* options.
386+
*/
304387
public HttpRequestInitializer httpRequestInitializer() {
305388
HttpTransport httpTransport = httpTransportFactory.create();
306-
return authCredentials().httpRequestInitializer(httpTransport, scopes());
389+
final HttpRequestInitializer baseRequestInitializer =
390+
authCredentials().httpRequestInitializer(httpTransport, scopes());
391+
return new HttpRequestInitializer() {
392+
@Override
393+
public void initialize(HttpRequest httpRequest) throws IOException {
394+
baseRequestInitializer.initialize(httpRequest);
395+
if (connectTimeout >= 0) {
396+
httpRequest.setConnectTimeout(connectTimeout);
397+
}
398+
if (readTimeout >= 0) {
399+
httpRequest.setReadTimeout(readTimeout);
400+
}
401+
}
402+
};
403+
}
404+
405+
/**
406+
* Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a
407+
* negative number is the default value (20000).
408+
*/
409+
public int connectTimeout() {
410+
return connectTimeout;
411+
}
412+
413+
/**
414+
* Returns the timeout in milliseconds to read from an established connection. 0 is an infinite
415+
* timeout, a negative number is the default value (20000).
416+
*/
417+
public int readTimeout() {
418+
return readTimeout;
307419
}
308420

309421
protected int baseHashCode() {

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,15 @@ public static Builder builder() {
632632
* is only valid within a certain time period.
633633
* This is particularly useful if you don't want publicly
634634
* accessible blobs, but don't want to require users to explicitly log in.
635+
* <p>
636+
* Example usage of creating a signed URL that is valid for 2 weeks:
637+
* <pre> {@code
638+
* service.signUrl(BlobInfo.of("bucket", "name"), TimeUnit.DAYS.toSeconds(14));
639+
* }</pre>
635640
*
636641
* @param blobInfo the blob associated with the signed url
637642
* @param expirationTimeInSeconds the signed URL expiration (using epoch time)
643+
* @param options optional URL signing options
638644
* @see <a href="https://cloud.google.com/storage/docs/access-control#Signed-URLs">Signed-URLs</a>
639645
*/
640646
URL signUrl(BlobInfo blobInfo, long expirationTimeInSeconds, SignUrlOption... options);

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
133133
.totalRetryPeriodMillis(120000)
134134
.initialRetryDelayMillis(250)
135135
.build())
136+
.connectTimeout(60000)
137+
.readTimeout(60000)
136138
.build();
137139
return new RemoteGcsHelper(storageOptions);
138140
} catch (FileNotFoundException ex) {

0 commit comments

Comments
 (0)