Skip to content

Commit

Permalink
Update spi classes with GAX 0.0.21 (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinfan authored and mziccard committed Oct 28, 2016
1 parent 0221851 commit 201eda8
Show file tree
Hide file tree
Showing 65 changed files with 2,083 additions and 2,002 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.21</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.UnaryCallSettings;
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 UnaryCallSettings.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 UnaryCallSettings.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.UnaryCallable;
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 UnaryCallable<GetGroupRequest, ErrorGroup> getGroupCallable;
private final UnaryCallable<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);
UnaryCallable.create(settings.getGroupSettings(), this.channel, this.executor);
this.updateGroupCallable =
ApiCallable.create(settings.updateGroupSettings(), this.channel, this.executor);
UnaryCallable.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 UnaryCallable<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 UnaryCallable<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.UnaryCallSettings;
import com.google.auth.Credentials;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -74,14 +74,6 @@ public class ErrorGroupServiceSettings extends ServiceApiSettings {
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();

/** The default connection settings of the service. */
public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS =
ConnectionSettings.newBuilder()
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
.setPort(DEFAULT_SERVICE_PORT)
.provideCredentialsWith(DEFAULT_SERVICE_SCOPES)
.build();

private final SimpleCallSettings<GetGroupRequest, ErrorGroup> getGroupSettings;
private final SimpleCallSettings<UpdateGroupRequest, ErrorGroup> updateGroupSettings;

Expand Down Expand Up @@ -140,7 +132,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<UnaryCallSettings.Builder> unaryMethodSettingsBuilders;

private final SimpleCallSettings.Builder<GetGroupRequest, ErrorGroup> getGroupSettings;
private final SimpleCallSettings.Builder<UpdateGroupRequest, ErrorGroup> updateGroupSettings;
Expand Down Expand Up @@ -177,15 +169,15 @@ public static class Builder extends ServiceApiSettings.Builder {
}

private Builder() {
super(DEFAULT_CONNECTION_SETTINGS);
super(s_getDefaultConnectionSettingsBuilder().build());

getGroupSettings = SimpleCallSettings.newBuilder(ErrorGroupServiceGrpc.METHOD_GET_GROUP);

updateGroupSettings =
SimpleCallSettings.newBuilder(ErrorGroupServiceGrpc.METHOD_UPDATE_GROUP);

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

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

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

private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() {
return ConnectionSettings.newBuilder()
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
.setPort(DEFAULT_SERVICE_PORT)
.provideCredentialsWith(DEFAULT_SERVICE_SCOPES);
}

@Override
protected ConnectionSettings getDefaultConnectionSettings() {
return DEFAULT_CONNECTION_SETTINGS;
protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() {
return s_getDefaultConnectionSettingsBuilder();
}

@Override
Expand Down Expand Up @@ -262,11 +261,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(UnaryCallSettings.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.UnaryCallable;
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,12 @@ 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 UnaryCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGroupStatsCallable;
private final UnaryCallable<ListGroupStatsRequest, ListGroupStatsPagedResponse>
listGroupStatsPagedCallable;
private final ApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable;
private final ApiCallable<
ListEventsRequest, PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent>>
listEventsPagedCallable;
private final ApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable;
private final UnaryCallable<ListEventsRequest, ListEventsResponse> listEventsCallable;
private final UnaryCallable<ListEventsRequest, ListEventsPagedResponse> listEventsPagedCallable;
private final UnaryCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable;

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

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

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
Expand Down Expand Up @@ -195,13 +192,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 +232,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 +250,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 UnaryCallable<ListGroupStatsRequest, ListGroupStatsPagedResponse>
listGroupStatsPagedCallable() {
return listGroupStatsPagedCallable;
}
Expand Down Expand Up @@ -297,7 +292,8 @@ public final ErrorStatsServiceSettings getSettings() {
* }
* </code></pre>
*/
public final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGroupStatsCallable() {
public final UnaryCallable<ListGroupStatsRequest, ListGroupStatsResponse>
listGroupStatsCallable() {
return listGroupStatsCallable;
}

Expand All @@ -323,8 +319,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 +349,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,17 +367,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>>
listEventsPagedCallable() {
public final UnaryCallable<ListEventsRequest, ListEventsPagedResponse> listEventsPagedCallable() {
return listEventsPagedCallable;
}

Expand Down Expand Up @@ -416,7 +408,7 @@ public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent
* }
* </code></pre>
*/
public final ApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable() {
public final UnaryCallable<ListEventsRequest, ListEventsResponse> listEventsCallable() {
return listEventsCallable;
}

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

Expand Down
Loading

0 comments on commit 201eda8

Please sign in to comment.