Skip to content

Commit 94a4444

Browse files
committed
Merge pull request #91 from jboynes/no_returns
Replace CR characters with newlines
2 parents 0cd6f98 + 3d83517 commit 94a4444

File tree

12 files changed

+1249
-12
lines changed

12 files changed

+1249
-12
lines changed
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud;public abstract class BaseService<O extends ServiceOptions> implements Service<O> { private final O options; protected BaseService(O options) { this.options = options; } @Override public O options() { return options; }}
1+
/*
2+
* Copyright 2015 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.gcloud;
18+
19+
public abstract class BaseService<O extends ServiceOptions> implements Service<O> {
20+
21+
private final O options;
22+
23+
protected BaseService(O options) {
24+
this.options = options;
25+
}
26+
27+
@Override
28+
public O options() {
29+
return options;
30+
}
31+
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud;public interface Service<O extends ServiceOptions> { O options();}
1+
/*
2+
* Copyright 2015 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.gcloud;
18+
19+
public interface Service<O extends ServiceOptions> {
20+
O options();
21+
}
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.gcloud.ServiceOptions;import java.io.Serializable;/** * A base interface for all service RPC factories. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */public interface ServiceRpcFactory<S, O extends ServiceOptions> extends Serializable { S create(O options);}
1+
/*
2+
* Copyright 2015 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.gcloud.spi;
18+
19+
import com.google.gcloud.ServiceOptions;
20+
21+
import java.io.Serializable;
22+
23+
/**
24+
* A base interface for all service RPC factories.
25+
* Loading of a factory implementation is done via {@link java.util.ServiceLoader}.
26+
*/
27+
public interface ServiceRpcFactory<S, O extends ServiceOptions> extends Serializable {
28+
29+
S create(O options);
30+
}
Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,117 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.datastore.DatastoreV1.AllocateIdsRequest;import com.google.api.services.datastore.DatastoreV1.AllocateIdsResponse;import com.google.api.services.datastore.DatastoreV1.BeginTransactionRequest;import com.google.api.services.datastore.DatastoreV1.BeginTransactionResponse;import com.google.api.services.datastore.DatastoreV1.CommitRequest;import com.google.api.services.datastore.DatastoreV1.CommitResponse;import com.google.api.services.datastore.DatastoreV1.LookupRequest;import com.google.api.services.datastore.DatastoreV1.LookupResponse;import com.google.api.services.datastore.DatastoreV1.RollbackRequest;import com.google.api.services.datastore.DatastoreV1.RollbackResponse;import com.google.api.services.datastore.DatastoreV1.RunQueryRequest;import com.google.api.services.datastore.DatastoreV1.RunQueryResponse;/** * Provides access to the remote Datastore service. */public interface DatastoreRpc { public class DatastoreRpcException extends Exception { /** * The reason for the exception. * * @see <a href="https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes">Google Cloud Datastore error codes</a> */ public enum Reason { ABORTED(true, "Request aborted", 409), DEADLINE_EXCEEDED(true, "Deadline exceeded", 403), FAILED_PRECONDITION(false, "Invalid request", 412), INTERNAL(false, "Server returned an error", 500), INVALID_ARGUMENT(false, "Request parameter has an invalid value", 400), PERMISSION_DENIED(false, "Unauthorized request", 403), RESOURCE_EXHAUSTED(false, "Quota exceeded", 402), UNAVAILABLE(true, "Could not reach service", 503); private final boolean retryable; private final String description; private final int httpStatus; private Reason(boolean retryable, String description, int httpStatus) { this.retryable = retryable; this.description = description; this.httpStatus = httpStatus; } public boolean retryable() { return retryable; } public String description() { return description; } public int httpStatus() { return httpStatus; } } private final String reason; private final int httpStatus; private final boolean retryable; public DatastoreRpcException(Reason reason) { this(reason.name(), reason.httpStatus, reason.retryable, reason.description); } public DatastoreRpcException(String reason, int httpStatus, boolean retryable, String message) { super(message); this.reason = reason; this.httpStatus = httpStatus; this.retryable = retryable; } public String reason() { return reason; } public int httpStatus() { return httpStatus; } public boolean retryable() { return retryable; } } AllocateIdsResponse allocateIds(AllocateIdsRequest request) throws DatastoreRpcException; BeginTransactionResponse beginTransaction(BeginTransactionRequest request) throws DatastoreRpcException; CommitResponse commit(CommitRequest request) throws DatastoreRpcException; LookupResponse lookup(LookupRequest request) throws DatastoreRpcException; RollbackResponse rollback(RollbackRequest request) throws DatastoreRpcException; RunQueryResponse runQuery(RunQueryRequest request) throws DatastoreRpcException;}
1+
/*
2+
* Copyright 2015 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+
package com.google.gcloud.spi;
17+
18+
import com.google.api.services.datastore.DatastoreV1.AllocateIdsRequest;
19+
import com.google.api.services.datastore.DatastoreV1.AllocateIdsResponse;
20+
import com.google.api.services.datastore.DatastoreV1.BeginTransactionRequest;
21+
import com.google.api.services.datastore.DatastoreV1.BeginTransactionResponse;
22+
import com.google.api.services.datastore.DatastoreV1.CommitRequest;
23+
import com.google.api.services.datastore.DatastoreV1.CommitResponse;
24+
import com.google.api.services.datastore.DatastoreV1.LookupRequest;
25+
import com.google.api.services.datastore.DatastoreV1.LookupResponse;
26+
import com.google.api.services.datastore.DatastoreV1.RollbackRequest;
27+
import com.google.api.services.datastore.DatastoreV1.RollbackResponse;
28+
import com.google.api.services.datastore.DatastoreV1.RunQueryRequest;
29+
import com.google.api.services.datastore.DatastoreV1.RunQueryResponse;
30+
31+
/**
32+
* Provides access to the remote Datastore service.
33+
*/
34+
public interface DatastoreRpc {
35+
36+
public class DatastoreRpcException extends Exception {
37+
38+
/**
39+
* The reason for the exception.
40+
*
41+
* @see <a href="https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes">Google Cloud Datastore error codes</a>
42+
*/
43+
public enum Reason {
44+
45+
ABORTED(true, "Request aborted", 409),
46+
DEADLINE_EXCEEDED(true, "Deadline exceeded", 403),
47+
FAILED_PRECONDITION(false, "Invalid request", 412),
48+
INTERNAL(false, "Server returned an error", 500),
49+
INVALID_ARGUMENT(false, "Request parameter has an invalid value", 400),
50+
PERMISSION_DENIED(false, "Unauthorized request", 403),
51+
RESOURCE_EXHAUSTED(false, "Quota exceeded", 402),
52+
UNAVAILABLE(true, "Could not reach service", 503);
53+
54+
private final boolean retryable;
55+
private final String description;
56+
private final int httpStatus;
57+
58+
private Reason(boolean retryable, String description, int httpStatus) {
59+
this.retryable = retryable;
60+
this.description = description;
61+
this.httpStatus = httpStatus;
62+
}
63+
64+
public boolean retryable() {
65+
return retryable;
66+
}
67+
68+
public String description() {
69+
return description;
70+
}
71+
72+
public int httpStatus() {
73+
return httpStatus;
74+
}
75+
}
76+
77+
private final String reason;
78+
private final int httpStatus;
79+
private final boolean retryable;
80+
81+
public DatastoreRpcException(Reason reason) {
82+
this(reason.name(), reason.httpStatus, reason.retryable, reason.description);
83+
}
84+
85+
public DatastoreRpcException(String reason, int httpStatus, boolean retryable, String message) {
86+
super(message);
87+
this.reason = reason;
88+
this.httpStatus = httpStatus;
89+
this.retryable = retryable;
90+
}
91+
92+
public String reason() {
93+
return reason;
94+
}
95+
96+
public int httpStatus() {
97+
return httpStatus;
98+
}
99+
100+
public boolean retryable() {
101+
return retryable;
102+
}
103+
}
104+
105+
AllocateIdsResponse allocateIds(AllocateIdsRequest request) throws DatastoreRpcException;
106+
107+
BeginTransactionResponse beginTransaction(BeginTransactionRequest request)
108+
throws DatastoreRpcException;
109+
110+
CommitResponse commit(CommitRequest request) throws DatastoreRpcException;
111+
112+
LookupResponse lookup(LookupRequest request) throws DatastoreRpcException;
113+
114+
RollbackResponse rollback(RollbackRequest request) throws DatastoreRpcException;
115+
116+
RunQueryResponse runQuery(RunQueryRequest request) throws DatastoreRpcException;
117+
}

0 commit comments

Comments
 (0)