Skip to content

Commit

Permalink
Update spi classes with GAX 0.0.19
Browse files Browse the repository at this point in the history
- Add grpc streaming support
- Rename ApiCallable to UnaryApiCallable
- Rename ApiCallSettings to UnaryApiCallSettings
  • Loading branch information
shinfan committed Oct 19, 2016
1 parent 8c9aca4 commit dd88e23
Show file tree
Hide file tree
Showing 55 changed files with 1,870 additions and 980 deletions.
2 changes: 1 addition & 1 deletion google-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>0.0.18</version>
<version>0.0.19</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.api.gax.core.ConnectionSettings;
import com.google.api.gax.core.RetrySettings;
import com.google.api.gax.grpc.ApiCallSettings;
import com.google.api.gax.grpc.UnaryApiCallSettings;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.spi.ServiceRpcFactory;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -226,7 +226,7 @@ protected ExecutorFactory<ScheduledExecutorService> executorFactory() {
/**
* Returns a builder for API call settings.
*/
protected ApiCallSettings.Builder apiCallSettings() {
protected UnaryApiCallSettings.Builder apiCallSettings() {
// todo(mziccard): specify timeout these settings:
// retryParams().retryMaxAttempts(), retryParams().retryMinAttempts()
final RetrySettings.Builder builder = RetrySettings.newBuilder()
Expand All @@ -237,7 +237,7 @@ protected ApiCallSettings.Builder apiCallSettings() {
.setInitialRetryDelay(Duration.millis(retryParams().initialRetryDelayMillis()))
.setRetryDelayMultiplier(retryParams().retryDelayBackoffFactor())
.setMaxRetryDelay(Duration.millis(retryParams().maxRetryDelayMillis()));
return ApiCallSettings.newBuilder().setRetrySettingsBuilder(builder);
return UnaryApiCallSettings.newBuilder().setRetrySettingsBuilder(builder);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.google.cloud.errorreporting.spi.v1beta1;

import com.google.api.gax.grpc.ApiCallable;
import com.google.api.gax.grpc.UnaryApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup;
import com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest;
Expand Down Expand Up @@ -54,8 +54,8 @@
* <li> A "request object" method. This type of method only takes one parameter, a request object,
* which must be constructed before the call. Not every API method will have a request object
* method.
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
* ApiCallable object, which can be used to initiate calls to the service.
* <li> A "callable" method. This type of method takes no parameters and returns an immutable API
* callable object, which can be used to initiate calls to the service.
* </ol>
*
* <p>See the individual methods for example code.
Expand Down Expand Up @@ -83,8 +83,8 @@ public class ErrorGroupServiceApi implements AutoCloseable {
private final ScheduledExecutorService executor;
private final List<AutoCloseable> closeables = new ArrayList<>();

private final ApiCallable<GetGroupRequest, ErrorGroup> getGroupCallable;
private final ApiCallable<UpdateGroupRequest, ErrorGroup> updateGroupCallable;
private final UnaryApiCallable<GetGroupRequest, ErrorGroup> getGroupCallable;
private final UnaryApiCallable<UpdateGroupRequest, ErrorGroup> updateGroupCallable;

private static final PathTemplate GROUP_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}/groups/{group}");
Expand Down Expand Up @@ -130,9 +130,9 @@ protected ErrorGroupServiceApi(ErrorGroupServiceSettings settings) throws IOExce
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);

this.getGroupCallable =
ApiCallable.create(settings.getGroupSettings(), this.channel, this.executor);
UnaryApiCallable.create(settings.getGroupSettings(), this.channel, this.executor);
this.updateGroupCallable =
ApiCallable.create(settings.updateGroupSettings(), this.channel, this.executor);
UnaryApiCallable.create(settings.updateGroupSettings(), this.channel, this.executor);

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
Expand Down Expand Up @@ -226,7 +226,7 @@ private final ErrorGroup getGroup(GetGroupRequest request) {
* }
* </code></pre>
*/
public final ApiCallable<GetGroupRequest, ErrorGroup> getGroupCallable() {
public final UnaryApiCallable<GetGroupRequest, ErrorGroup> getGroupCallable() {
return getGroupCallable;
}

Expand Down Expand Up @@ -292,7 +292,7 @@ private final ErrorGroup updateGroup(UpdateGroupRequest request) {
* }
* </code></pre>
*/
public final ApiCallable<UpdateGroupRequest, ErrorGroup> updateGroupCallable() {
public final UnaryApiCallable<UpdateGroupRequest, ErrorGroup> updateGroupCallable() {
return updateGroupCallable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import com.google.api.gax.core.ConnectionSettings;
import com.google.api.gax.core.RetrySettings;
import com.google.api.gax.grpc.ApiCallSettings;
import com.google.api.gax.grpc.ServiceApiSettings;
import com.google.api.gax.grpc.SimpleCallSettings;
import com.google.api.gax.grpc.UnaryApiCallSettings;
import com.google.auth.Credentials;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -140,7 +140,7 @@ private ErrorGroupServiceSettings(Builder settingsBuilder) throws IOException {

/** Builder for ErrorGroupServiceSettings. */
public static class Builder extends ServiceApiSettings.Builder {
private final ImmutableList<ApiCallSettings.Builder> methodSettingsBuilders;
private final ImmutableList<UnaryApiCallSettings.Builder> unaryMethodSettingsBuilders;

private final SimpleCallSettings.Builder<GetGroupRequest, ErrorGroup> getGroupSettings;
private final SimpleCallSettings.Builder<UpdateGroupRequest, ErrorGroup> updateGroupSettings;
Expand Down Expand Up @@ -184,8 +184,8 @@ private Builder() {
updateGroupSettings =
SimpleCallSettings.newBuilder(ErrorGroupServiceGrpc.METHOD_UPDATE_GROUP);

methodSettingsBuilders =
ImmutableList.<ApiCallSettings.Builder>of(getGroupSettings, updateGroupSettings);
unaryMethodSettingsBuilders =
ImmutableList.<UnaryApiCallSettings.Builder>of(getGroupSettings, updateGroupSettings);
}

private static Builder createDefault() {
Expand All @@ -210,8 +210,8 @@ private Builder(ErrorGroupServiceSettings settings) {
getGroupSettings = settings.getGroupSettings.toBuilder();
updateGroupSettings = settings.updateGroupSettings.toBuilder();

methodSettingsBuilders =
ImmutableList.<ApiCallSettings.Builder>of(getGroupSettings, updateGroupSettings);
unaryMethodSettingsBuilders =
ImmutableList.<UnaryApiCallSettings.Builder>of(getGroupSettings, updateGroupSettings);
}

@Override
Expand Down Expand Up @@ -262,11 +262,14 @@ public Builder setClientLibHeader(String name, String version) {
}

/**
* Applies the given settings to all of the API methods in this service. Only values that are
* non-null will be applied, so this method is not capable of un-setting any values.
* Applies the given settings to all of the unary API methods in this service. Only values that
* are non-null will be applied, so this method is not capable of un-setting any values.
*
* <p>Note: This method does not support applying settings to streaming methods.
*/
public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception {
super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings);
public Builder applyToAllApiMethods(UnaryApiCallSettings.Builder apiCallSettings)
throws Exception {
super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*/
package com.google.cloud.errorreporting.spi.v1beta1;

import com.google.api.gax.core.PagedListResponse;
import com.google.api.gax.grpc.ApiCallable;
import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse;
import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse;

import com.google.api.gax.grpc.UnaryApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest;
import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsResponse;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorEvent;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats;
import com.google.devtools.clouderrorreporting.v1beta1.ListEventsRequest;
import com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse;
import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest;
Expand Down Expand Up @@ -62,8 +62,8 @@
* <li> A "request object" method. This type of method only takes one parameter, a request object,
* which must be constructed before the call. Not every API method will have a request object
* method.
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
* ApiCallable object, which can be used to initiate calls to the service.
* <li> A "callable" method. This type of method takes no parameters and returns an immutable API
* callable object, which can be used to initiate calls to the service.
* </ol>
*
* <p>See the individual methods for example code.
Expand Down Expand Up @@ -91,16 +91,14 @@ public class ErrorStatsServiceApi implements AutoCloseable {
private final ScheduledExecutorService executor;
private final List<AutoCloseable> closeables = new ArrayList<>();

private final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGroupStatsCallable;
private final ApiCallable<
ListGroupStatsRequest,
PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>>
private final UnaryApiCallable<ListGroupStatsRequest, ListGroupStatsResponse>
listGroupStatsCallable;
private final UnaryApiCallable<ListGroupStatsRequest, ListGroupStatsPagedResponse>
listGroupStatsPagedCallable;
private final ApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable;
private final ApiCallable<
ListEventsRequest, PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent>>
private final UnaryApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable;
private final UnaryApiCallable<ListEventsRequest, ListEventsPagedResponse>
listEventsPagedCallable;
private final ApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable;
private final UnaryApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable;

private static final PathTemplate PROJECT_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}");
Expand Down Expand Up @@ -139,16 +137,17 @@ protected ErrorStatsServiceApi(ErrorStatsServiceSettings settings) throws IOExce
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);

this.listGroupStatsCallable =
ApiCallable.create(settings.listGroupStatsSettings(), this.channel, this.executor);
UnaryApiCallable.create(settings.listGroupStatsSettings(), this.channel, this.executor);
this.listGroupStatsPagedCallable =
ApiCallable.createPagedVariant(
UnaryApiCallable.createPagedVariant(
settings.listGroupStatsSettings(), this.channel, this.executor);
this.listEventsCallable =
ApiCallable.create(settings.listEventsSettings(), this.channel, this.executor);
UnaryApiCallable.create(settings.listEventsSettings(), this.channel, this.executor);
this.listEventsPagedCallable =
ApiCallable.createPagedVariant(settings.listEventsSettings(), this.channel, this.executor);
UnaryApiCallable.createPagedVariant(
settings.listEventsSettings(), this.channel, this.executor);
this.deleteEventsCallable =
ApiCallable.create(settings.deleteEventsSettings(), this.channel, this.executor);
UnaryApiCallable.create(settings.deleteEventsSettings(), this.channel, this.executor);

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
Expand Down Expand Up @@ -195,13 +194,14 @@ public final ErrorStatsServiceSettings getSettings() {
* href="https://support.google.com/cloud/answer/6158840"&gt;Google Cloud Platform project
* ID&lt;/a&gt;.
* <p>Example: &lt;code&gt;projects/my-project-123&lt;/code&gt;.
* @param timeRange [Required] List data for the given time range. The service is tuned for
* retrieving data up to (approximately) 'now'. Retrieving data for arbitrary time periods in
* the past can result in higher response times or in returning incomplete results.
* @param timeRange [Required] List data for the given time range. Only
* &lt;code&gt;ErrorGroupStats&lt;/code&gt; with a non-zero count in the given time range are
* returned, unless the request contains an explicit group_id list. If a group_id list is
* given, also &lt;code&gt;ErrorGroupStats&lt;/code&gt; with zero occurrences are returned.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>
listGroupStats(String projectName, QueryTimeRange timeRange) {
public final ListGroupStatsPagedResponse listGroupStats(
String projectName, QueryTimeRange timeRange) {
PROJECT_PATH_TEMPLATE.validate(projectName, "listGroupStats");
ListGroupStatsRequest request =
ListGroupStatsRequest.newBuilder()
Expand Down Expand Up @@ -234,8 +234,7 @@ public final ErrorStatsServiceSettings getSettings() {
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>
listGroupStats(ListGroupStatsRequest request) {
public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest request) {
return listGroupStatsPagedCallable().call(request);
}

Expand All @@ -253,17 +252,15 @@ public final ErrorStatsServiceSettings getSettings() {
* .setProjectName(formattedProjectName)
* .setTimeRange(timeRange)
* .build();
* ListenableFuture&lt;PagedListResponse&lt;ListGroupStatsRequest,ListGroupStatsResponse,ErrorGroupStats&gt;&gt; future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request);
* ListenableFuture&lt;ListGroupStatsPagedResponse&gt; future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request);
* // Do something
* for (ErrorGroupStats element : future.get().iterateAllElements()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final ApiCallable<
ListGroupStatsRequest,
PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>>
public final UnaryApiCallable<ListGroupStatsRequest, ListGroupStatsPagedResponse>
listGroupStatsPagedCallable() {
return listGroupStatsPagedCallable;
}
Expand Down Expand Up @@ -297,7 +294,8 @@ public final ErrorStatsServiceSettings getSettings() {
* }
* </code></pre>
*/
public final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGroupStatsCallable() {
public final UnaryApiCallable<ListGroupStatsRequest, ListGroupStatsResponse>
listGroupStatsCallable() {
return listGroupStatsCallable;
}

Expand All @@ -323,8 +321,7 @@ public final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGrou
* @param groupId [Required] The group for which events shall be returned.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent> listEvents(
String projectName, String groupId) {
public final ListEventsPagedResponse listEvents(String projectName, String groupId) {
PROJECT_PATH_TEMPLATE.validate(projectName, "listEvents");
ListEventsRequest request =
ListEventsRequest.newBuilder().setProjectName(projectName).setGroupId(groupId).build();
Expand Down Expand Up @@ -354,8 +351,7 @@ public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent> listEvents(
ListEventsRequest request) {
public final ListEventsPagedResponse listEvents(ListEventsRequest request) {
return listEventsPagedCallable().call(request);
}

Expand All @@ -373,16 +369,15 @@ public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent
* .setProjectName(formattedProjectName)
* .setGroupId(groupId)
* .build();
* ListenableFuture&lt;PagedListResponse&lt;ListEventsRequest,ListEventsResponse,ErrorEvent&gt;&gt; future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request);
* ListenableFuture&lt;ListEventsPagedResponse&gt; future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request);
* // Do something
* for (ErrorEvent element : future.get().iterateAllElements()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final ApiCallable<
ListEventsRequest, PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent>>
public final UnaryApiCallable<ListEventsRequest, ListEventsPagedResponse>
listEventsPagedCallable() {
return listEventsPagedCallable;
}
Expand Down Expand Up @@ -416,7 +411,7 @@ public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent
* }
* </code></pre>
*/
public final ApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable() {
public final UnaryApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable() {
return listEventsCallable;
}

Expand Down Expand Up @@ -486,7 +481,7 @@ private final DeleteEventsResponse deleteEvents(DeleteEventsRequest request) {
* }
* </code></pre>
*/
public final ApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable() {
public final UnaryApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable() {
return deleteEventsCallable;
}

Expand Down
Loading

0 comments on commit dd88e23

Please sign in to comment.