Skip to content

Commit 7af2cca

Browse files
committed
---
yaml --- r: 617 b: refs/heads/gh-pages c: 1c271b8 h: refs/heads/master i: 615: ad003bc v: v3
1 parent a6e46d0 commit 7af2cca

31 files changed

Lines changed: 216 additions & 248 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
refs/heads/master: 92537786d4fa0a9fb51215f27d3d0581f4fe3a65
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
4-
refs/heads/gh-pages: b5bef9f00ef96dc9f98e365579edd3da05957b74
4+
refs/heads/gh-pages: 1c271b82a31f004837b0e8c4d77dbe410d2f48ea

branches/gh-pages/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/target/
22
.settings
33
.idea
4-
.DS_Store
4+
*.iml

branches/gh-pages/findbugs-exclude.xml

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

branches/gh-pages/git-demo.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
1111
<excludeFolder url="file://$MODULE_DIR$/target" />
1212
</content>
13-
<orderEntry type="jdk" jdkName="1.7 (1)" jdkType="JavaSDK" />
13+
<orderEntry type="inheritedJdk" />
1414
<orderEntry type="sourceFolder" forTests="false" />
1515
<orderEntry type="library" name="Maven: com.google.http-client:google-http-client:1.19.0" level="project" />
1616
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
@@ -244,4 +244,4 @@
244244
</map>
245245
</option>
246246
</component>
247-
</module>
247+
</module>

branches/gh-pages/src/main/java/com/google/gcloud/AuthConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ protected HttpRequestInitializer httpRequestInitializer(
5757
}
5858
}
5959

60-
protected abstract HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
61-
Set<String> scopes);
60+
protected abstract HttpRequestInitializer httpRequestInitializer(
61+
HttpTransport transport, Set<String> scopes);
62+
6263

6364
public static AuthConfig createForAppEngine() {
6465
return new AppEngineAuthConfig();
@@ -68,8 +69,7 @@ public static AuthConfig createForComputeEngine() throws IOException, GeneralSec
6869
final ComputeCredential cred = getComputeCredential();
6970
return new AuthConfig() {
7071
@Override
71-
protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
72-
Set<String> scopes) {
72+
protected HttpRequestInitializer httpRequestInitializer(HttpTransport ts, Set<String> sc) {
7373
return cred;
7474
}
7575
};

branches/gh-pages/src/main/java/com/google/gcloud/ExceptionHandler.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class ExceptionHandler implements Serializable {
2727
private final ImmutableList<Interceptor> interceptors;
2828
private final ImmutableSet<Class<? extends Exception>> retriableExceptions;
2929
private final ImmutableSet<Class<? extends Exception>> nonRetriableExceptions;
30-
private final Set<RetryInfo> retryInfo = Sets.newHashSet();
30+
private final Set<RetryInfo> retryInfos = Sets.newHashSet();
3131

3232
public interface Interceptor extends Serializable {
3333

@@ -38,7 +38,7 @@ enum RetryResult {
3838

3939
private final boolean booleanValue;
4040

41-
RetryResult(boolean booleanValue) {
41+
private RetryResult(boolean booleanValue) {
4242
this.booleanValue = booleanValue;
4343
}
4444

@@ -55,7 +55,7 @@ boolean booleanValue() {
5555
* ({@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}),
5656
* or evaluation should proceed ({@code null}).
5757
*/
58-
RetryResult beforeEval(Exception exception);
58+
RetryResult shouldRetry(Exception exception);
5959

6060
/**
6161
* This method is called after the evaluation and could alter its result.
@@ -66,7 +66,7 @@ boolean booleanValue() {
6666
* ({@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}),
6767
* or evaluation should proceed ({@code null}).
6868
*/
69-
RetryResult afterEval(Exception exception, RetryResult retryResult);
69+
RetryResult shouldRetry(Exception exception, RetryResult retryResult);
7070
}
7171

7272
/**
@@ -173,30 +173,31 @@ private ExceptionHandler(Builder builder) {
173173
Sets.intersection(retriableExceptions, nonRetriableExceptions).isEmpty(),
174174
"Same exception was found in both retriable and non-retriable sets");
175175
for (Class<? extends Exception> exception : retriableExceptions) {
176-
addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.RETRY), retryInfo);
176+
addToRetryInfos(retryInfos, new RetryInfo(exception, Interceptor.RetryResult.RETRY));
177177
}
178178
for (Class<? extends Exception> exception : nonRetriableExceptions) {
179-
addRetryInfo(new RetryInfo(exception, Interceptor.RetryResult.ABORT), retryInfo);
179+
addToRetryInfos(retryInfos, new RetryInfo(exception, Interceptor.RetryResult.ABORT));
180180
}
181181
}
182182

183-
private static void addRetryInfo(RetryInfo retryInfo, Set<RetryInfo> dest) {
184-
for (RetryInfo current : dest) {
183+
private static void addToRetryInfos(Set<RetryInfo> retryInfos, RetryInfo retryInfo) {
184+
for (RetryInfo current : retryInfos) {
185185
if (current.exception.isAssignableFrom(retryInfo.exception)) {
186-
addRetryInfo(retryInfo, current.children);
186+
addToRetryInfos(current.children, retryInfo);
187187
return;
188188
}
189189
if (retryInfo.exception.isAssignableFrom(current.exception)) {
190190
retryInfo.children.add(current);
191191
}
192192
}
193-
dest.removeAll(retryInfo.children);
194-
dest.add(retryInfo);
193+
retryInfos.removeAll(retryInfo.children);
194+
retryInfos.add(retryInfo);
195195
}
196196

197-
private static RetryInfo findMostSpecificRetryInfo(Set<RetryInfo> retryInfo,
197+
198+
private static RetryInfo findMostSpecificRetryInfo(Set<RetryInfo> retryInfos,
198199
Class<? extends Exception> exception) {
199-
for (RetryInfo current : retryInfo) {
200+
for (RetryInfo current : retryInfos) {
200201
if (current.exception.isAssignableFrom(exception)) {
201202
RetryInfo match = findMostSpecificRetryInfo(current.children, exception);
202203
return match == null ? current : match;
@@ -222,10 +223,10 @@ void verifyCaller(Callable<?> callable) {
222223
Method callMethod = getCallableMethod(callable.getClass());
223224
for (Class<?> exceptionOrError : callMethod.getExceptionTypes()) {
224225
Preconditions.checkArgument(Exception.class.isAssignableFrom(exceptionOrError),
225-
"Callable method exceptions must be derived from Exception");
226+
"Callable method exceptions must be dervied from Exception");
226227
@SuppressWarnings("unchecked") Class<? extends Exception> exception =
227228
(Class<? extends Exception>) exceptionOrError;
228-
Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfo, exception) != null,
229+
Preconditions.checkArgument(findMostSpecificRetryInfo(retryInfos, exception) != null,
229230
"Declared exception '" + exception + "' is not covered by exception handler");
230231
}
231232
}
@@ -240,16 +241,16 @@ public Set<Class<? extends Exception>> getNonRetriableExceptions() {
240241

241242
boolean shouldRetry(Exception ex) {
242243
for (Interceptor interceptor : interceptors) {
243-
Interceptor.RetryResult retryResult = interceptor.beforeEval(ex);
244+
Interceptor.RetryResult retryResult = interceptor.shouldRetry(ex);
244245
if (retryResult != null) {
245246
return retryResult.booleanValue();
246247
}
247248
}
248-
RetryInfo retryInfo = findMostSpecificRetryInfo(this.retryInfo, ex.getClass());
249+
RetryInfo retryInfo = findMostSpecificRetryInfo(retryInfos, ex.getClass());
249250
Interceptor.RetryResult retryResult =
250251
retryInfo == null ? Interceptor.RetryResult.ABORT : retryInfo.retry;
251252
for (Interceptor interceptor : interceptors) {
252-
retryResult = firstNonNull(interceptor.afterEval(ex, retryResult), retryResult);
253+
retryResult = firstNonNull(interceptor.shouldRetry(ex, retryResult), retryResult);
253254
}
254255
return retryResult.booleanValue();
255256
}

branches/gh-pages/src/main/java/com/google/gcloud/RetryHelper.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package com.google.gcloud;
22

3-
import static com.google.common.base.Preconditions.checkNotNull;
4-
import static java.lang.Math.max;
5-
import static java.lang.Math.min;
6-
import static java.lang.Math.pow;
7-
import static java.lang.Math.random;
8-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
9-
103
import com.google.common.annotations.VisibleForTesting;
114
import com.google.common.base.MoreObjects;
125
import com.google.common.base.MoreObjects.ToStringHelper;
@@ -15,9 +8,12 @@
158
import java.io.InterruptedIOException;
169
import java.nio.channels.ClosedByInterruptException;
1710
import java.util.concurrent.Callable;
18-
import java.util.logging.Level;
1911
import java.util.logging.Logger;
2012

13+
import static com.google.common.base.Preconditions.checkNotNull;
14+
import static java.lang.Math.*;
15+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
16+
2117
/**
2218
* Utility class for retrying operations.
2319
* For more details about the parameters, see {@link RetryParams}.
@@ -68,7 +64,7 @@ public static final class RetryInterruptedException extends RetryHelperException
6864
RetryInterruptedException() {}
6965

7066
/**
71-
* Sets the caller thread interrupt flag and throws {@code RetryInterruptedException}.
67+
* Sets the caller thread interrupt flag and throws {@code RetryInteruptedException}.
7268
*/
7369
public static void propagate() throws RetryInterruptedException {
7470
Thread.currentThread().interrupt();
@@ -148,11 +144,9 @@ static Context getContext() {
148144
@Override
149145
public String toString() {
150146
ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
151-
toStringHelper.add("params", params);
152147
toStringHelper.add("stopwatch", stopwatch);
153148
toStringHelper.add("attemptNumber", attemptNumber);
154149
toStringHelper.add("callable", callable);
155-
toStringHelper.add("exceptionHandler", exceptionHandler);
156150
return toStringHelper.toString();
157151
}
158152

@@ -163,7 +157,7 @@ private V doRetry() throws RetryHelperException {
163157
Exception exception;
164158
try {
165159
V value = callable.call();
166-
if (attemptNumber > 1 && log.isLoggable(Level.FINE)) {
160+
if (attemptNumber > 1) {
167161
log.fine(this + ": attempt #" + attemptNumber + " succeeded");
168162
}
169163
return value;
@@ -184,14 +178,11 @@ private V doRetry() throws RetryHelperException {
184178
throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception);
185179
}
186180
long sleepDurationMillis = getSleepDuration(params, attemptNumber);
187-
if (log.isLoggable(Level.FINE)) {
188-
log.fine(this + ": Attempt #" + attemptNumber + " failed [" + exception + "], sleeping for "
189-
+ sleepDurationMillis + " ms");
190-
}
181+
log.fine(this + ": Attempt #" + attemptNumber + " failed [" + exception + "], sleeping for "
182+
+ sleepDurationMillis + " ms");
191183
try {
192184
Thread.sleep(sleepDurationMillis);
193185
} catch (InterruptedException e) {
194-
// propagate as RetryInterruptedException
195186
RetryInterruptedException.propagate();
196187
}
197188
}

branches/gh-pages/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import static com.google.common.base.MoreObjects.firstNonNull;
5-
import static java.nio.charset.StandardCharsets.UTF_8;
65

76
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
87
import com.google.api.client.http.HttpRequestInitializer;
@@ -12,7 +11,6 @@
1211
import java.io.BufferedReader;
1312
import java.io.IOException;
1413
import java.io.InputStreamReader;
15-
import java.lang.reflect.Method;
1614
import java.net.URL;
1715
import java.net.URLConnection;
1816
import java.util.Set;
@@ -123,29 +121,10 @@ protected static String googleCloudProjectId() {
123121
URLConnection connection = url.openConnection();
124122
connection.setRequestProperty("X-Google-Metadata-Request", "True");
125123
try (BufferedReader reader =
126-
new BufferedReader(new InputStreamReader(connection.getInputStream(), UTF_8))) {
124+
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
127125
return reader.readLine();
128126
}
129-
} catch (IOException ignore) {
130-
// return null if can't determine
131-
return null;
132-
}
133-
}
134-
135-
protected static String getAppEngineProjectId() {
136-
// TODO(ozarov): An alternative to reflection would be to depend on AE api jar:
137-
// http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0
138-
try {
139-
Class<?> factoryClass =
140-
Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory");
141-
Method method = factoryClass.getMethod("getAppIdentityService");
142-
Object appIdentityService = method.invoke(null);
143-
method = appIdentityService.getClass().getMethod("getServiceAccountName");
144-
String serviceAccountName = (String) method.invoke(appIdentityService);
145-
int indexOfAtSign = serviceAccountName.indexOf('@');
146-
return serviceAccountName.substring(0, indexOfAtSign);
147-
} catch (Exception ignore) {
148-
// return null if can't determine
127+
} catch (IOException e) {
149128
return null;
150129
}
151130
}

branches/gh-pages/src/main/java/com/google/gcloud/datastore/BaseEntity.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ abstract class BaseEntity extends Serializable<DatastoreV1.Entity> {
2828

2929
private final transient ImmutableSortedMap<String, Value<?>> properties;
3030

31-
abstract static class Builder<B extends Builder<B>> {
31+
protected abstract static class Builder<B extends Builder<B>> {
3232

33-
final Map<String, Value<?>> properties;
33+
protected final Map<String, Value<?>> properties;
3434

35-
Builder() {
35+
protected Builder() {
3636
properties = new HashMap<>();
3737
}
3838

39-
Builder(BaseEntity entity) {
39+
protected Builder(BaseEntity entity) {
4040
properties = new HashMap<>(entity.properties());
4141
}
4242

4343
@SuppressWarnings("unchecked")
44-
B self() {
44+
protected B self() {
4545
return (B) this;
4646
}
4747

@@ -124,7 +124,7 @@ public B setNull(String name) {
124124
public abstract BaseEntity build();
125125
}
126126

127-
BaseEntity(ImmutableSortedMap<String, Value<?>> properties) {
127+
protected BaseEntity(ImmutableSortedMap<String, Value<?>> properties) {
128128
this.properties = properties;
129129
}
130130

@@ -153,49 +153,41 @@ public boolean isNull(String name) {
153153
return getValue(name) instanceof NullValue;
154154
}
155155

156-
@SuppressWarnings("unchecked")
157156
public String getString(String name) {
158-
return ((Value<String>) getValue(name)).get();
157+
return ((StringValue) getValue(name)).get();
159158
}
160159

161-
@SuppressWarnings("unchecked")
162160
public long getLong(String name) {
163-
return ((Value<Long>) getValue(name)).get();
161+
return ((LongValue) getValue(name)).get();
164162
}
165163

166-
@SuppressWarnings("unchecked")
167164
public double getDouble(String name) {
168-
return ((Value<Double>) getValue(name)).get();
165+
return ((DoubleValue) getValue(name)).get();
169166
}
170167

171-
@SuppressWarnings("unchecked")
172168
public boolean getBoolean(String name) {
173-
return ((Value<Boolean>) getValue(name)).get();
169+
return ((BooleanValue) getValue(name)).get();
174170
}
175171

176-
@SuppressWarnings("unchecked")
177172
public DateTime getDateTime(String name) {
178-
return ((Value<DateTime>) getValue(name)).get();
173+
return ((DateTimeValue) getValue(name)).get();
179174
}
180175

181-
@SuppressWarnings("unchecked")
182176
public Key getKey(String name) {
183-
return ((Value<Key>) getValue(name)).get();
177+
return ((KeyValue) getValue(name)).get();
184178
}
185179

186180
@SuppressWarnings("unchecked")
187181
public <T extends PartialEntity> T getEntity(String name) {
188-
return (T) ((Value<PartialEntity>) getValue(name)).get();
182+
return (T) ((EntityValue) getValue(name)).get();
189183
}
190184

191-
@SuppressWarnings("unchecked")
192185
public List<? extends Value<?>> getList(String name) {
193-
return ((Value<List<? extends Value<?>>>) getValue(name)).get();
186+
return ((ListValue) getValue(name)).get();
194187
}
195188

196-
@SuppressWarnings("unchecked")
197189
public Blob getBlob(String name) {
198-
return ((Value<Blob>) getValue(name)).get();
190+
return ((BlobValue) getValue(name)).get();
199191
}
200192

201193
/**

0 commit comments

Comments
 (0)