Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CR characters with newlines #91

Merged
merged 1 commit into from
Jun 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
/* * 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; }}
/*
* 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;
}
}
22 changes: 21 additions & 1 deletion gcloud-java-core/src/main/java/com/google/gcloud/Service.java
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/* * 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();}
/*
* 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();
}
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
/* * 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);}
/*
* 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);
}
Original file line number Diff line number Diff line change
@@ -1 +1,117 @@
/* * 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;}
/*
* 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;
}
Loading