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

Update logging with latest generator and GAX. #1046

Merged
merged 5 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -33,6 +33,7 @@

package com.google.cloud.logging.spi.v2;

import com.google.api.gax.core.PageAccessor;
import com.google.api.gax.grpc.ApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.logging.v2.CreateSinkRequest;
Expand All @@ -48,33 +49,88 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

// Manually-added imports: add custom (non-generated) imports after this point.

// AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing.
/**
* Service Description:
*
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>
* <code>
* try (ConfigServiceV2Api configServiceV2Api = ConfigServiceV2Api.createWithDefaults()) {
* String projectName = "";

This comment was marked as spam.

This comment was marked as spam.

* ListSinksResponse response = configServiceV2Api.listSinks(projectName);
* }
* </code>
* </pre>
*
* <p>Note: close() needs to be called on the configServiceV2Api object to clean up resources such
* as threads. In the example above, try-with-resources is used, which automatically calls
* close().
*
* <p>The surface of this class includes several types of Java methods for each of the API's methods:
*
* <ol>
* <li> A "flattened" method. With this type of method, the fields of the request type have been
* converted into function parameters. It may be the case that not all fields are available
* as parameters, and not every API method will have a flattened method entry point.
* <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.
* </ol>
*
* <p>See the individual methods for example code.
*
* <p>Many parameters require resource names to be formatted in a particular way. To assist
* with these names, this class includes a format method for each type of name, and additionally
* a parse method to extract the individual identifiers contained within names that are
* returned.
*
* <p>This class can be customized by passing in a custom instance of ConfigServiceV2Settings to
* create(). For example:
*
* <pre>
* <code>
* ConfigServiceV2Settings configServiceV2Settings = ConfigServiceV2Settings.defaultBuilder()
* .provideChannelWith(myCredentials)
* .build();
* ConfigServiceV2Api configServiceV2Api = ConfigServiceV2Api.create(configServiceV2Settings);
* </code>
* </pre>
*

This comment was marked as spam.

This comment was marked as spam.

* <!-- manual edit -->
* <!-- end manual edit -->
*/
@javax.annotation.Generated("by GAPIC")
public class ConfigServiceV2Api implements AutoCloseable {
private final ConfigServiceV2Settings settings;
private final ManagedChannel channel;
private final ScheduledExecutorService executor;
private final List<AutoCloseable> closeables = new ArrayList<>();

private final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable;
private final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableCallable;
private final ApiCallable<ListSinksRequest, PageAccessor<LogSink>> listSinksPagedCallable;
private final ApiCallable<GetSinkRequest, LogSink> getSinkCallable;
private final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable;
private final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable;
private final ApiCallable<DeleteSinkRequest, Empty> deleteSinkCallable;

public final ConfigServiceV2Settings getSettings() {
return settings;
}

private static final PathTemplate PROJECT_PATH_TEMPLATE =
PathTemplate.create("projects/{project}");
PathTemplate.createWithoutUrlEncoding("projects/{project}");

private static final PathTemplate SINK_PATH_TEMPLATE =
PathTemplate.create("projects/{project}/sinks/{sink}");
PathTemplate.createWithoutUrlEncoding("projects/{project}/sinks/{sink}");

/**
* Formats a string containing the fully-qualified path to represent
Expand Down Expand Up @@ -137,8 +193,8 @@ public static final String parseSinkFromSinkName(String sinkName) {
* <!-- manual edit -->
* <!-- end manual edit -->
*/
public static final ConfigServiceV2Api defaultInstance() throws IOException {
return create(ConfigServiceV2Settings.defaultInstance());
public static final ConfigServiceV2Api createWithDefaults() throws IOException {
return create(ConfigServiceV2Settings.defaultBuilder().build());
}

/**
Expand All @@ -163,17 +219,24 @@ public static final ConfigServiceV2Api create(ConfigServiceV2Settings settings)
* <!-- end manual edit -->
*/
protected ConfigServiceV2Api(ConfigServiceV2Settings settings) throws IOException {
this.channel = settings.getChannel();

this.listSinksCallable = ApiCallable.create(settings.listSinksSettings(), settings);
this.listSinksIterableCallable =
ApiCallable.createIterable(settings.listSinksSettings(), settings);
this.getSinkCallable = ApiCallable.create(settings.getSinkSettings(), settings);
this.createSinkCallable = ApiCallable.create(settings.createSinkSettings(), settings);
this.updateSinkCallable = ApiCallable.create(settings.updateSinkSettings(), settings);
this.deleteSinkCallable = ApiCallable.create(settings.deleteSinkSettings(), settings);

if (settings.shouldAutoCloseChannel()) {
this.settings = settings;
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);

this.listSinksCallable =
ApiCallable.create(settings.listSinksSettings(), this.channel, this.executor);
this.listSinksPagedCallable =
ApiCallable.createPagedVariant(settings.listSinksSettings(), this.channel, this.executor);
this.getSinkCallable =
ApiCallable.create(settings.getSinkSettings(), this.channel, this.executor);
this.createSinkCallable =
ApiCallable.create(settings.createSinkSettings(), this.channel, this.executor);
this.updateSinkCallable =
ApiCallable.create(settings.updateSinkSettings(), this.channel, this.executor);
this.deleteSinkCallable =
ApiCallable.create(settings.deleteSinkSettings(), this.channel, this.executor);

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
new Closeable() {
@Override
Expand All @@ -182,6 +245,15 @@ public void close() throws IOException {
}
});
}
if (settings.getExecutorProvider().shouldAutoClose()) {
closeables.add(
new Closeable() {
@Override
public void close() throws IOException {
executor.shutdown();
}
});
}
}

// ----- listSinks -----
Expand All @@ -195,9 +267,10 @@ public void close() throws IOException {
*
* @param projectName Required. The resource name of the project containing the sinks.
* Example: `"projects/my-logging-project"`, `"projects/01234567890"`.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Iterable<LogSink> listSinks(String projectName) {
public final PageAccessor<LogSink> listSinks(String projectName) {
PROJECT_PATH_TEMPLATE.validate(projectName);
ListSinksRequest request = ListSinksRequest.newBuilder().setProjectName(projectName).build();
return listSinks(request);
}
Expand All @@ -210,10 +283,10 @@ public final Iterable<LogSink> listSinks(String projectName) {
* <!-- end manual edit -->
*
* @param request The request object containing all of the parameters for the API call.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Iterable<LogSink> listSinks(ListSinksRequest request) {
return listSinksIterableCallable().call(request);
public final PageAccessor<LogSink> listSinks(ListSinksRequest request) {
return listSinksPagedCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
Expand All @@ -222,10 +295,9 @@ public final Iterable<LogSink> listSinks(ListSinksRequest request) {
*

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableCallable() {
return listSinksIterableCallable;
public final ApiCallable<ListSinksRequest, PageAccessor<LogSink>> listSinksPagedCallable() {
return listSinksPagedCallable;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
Expand All @@ -234,7 +306,6 @@ public final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableC
*
* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable() {
return listSinksCallable;
Expand All @@ -251,11 +322,11 @@ public final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable(
*
* @param sinkName The resource name of the sink to return.
* Example: `"projects/my-project-id/sinks/my-sink-id"`.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final LogSink getSink(String sinkName) {
SINK_PATH_TEMPLATE.validate(sinkName);
GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(sinkName).build();

return getSink(request);
}

Expand All @@ -267,7 +338,7 @@ public final LogSink getSink(String sinkName) {
* <!-- end manual edit -->
*
* @param request The request object containing all of the parameters for the API call.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
private LogSink getSink(GetSinkRequest request) {
return getSinkCallable().call(request);
Expand All @@ -279,7 +350,6 @@ private LogSink getSink(GetSinkRequest request) {
*
* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<GetSinkRequest, LogSink> getSinkCallable() {
return getSinkCallable;
Expand All @@ -300,12 +370,13 @@ public final ApiCallable<GetSinkRequest, LogSink> getSinkCallable() {
* The new sink must be provided in the request.
* @param sink The new sink, which must not have an identifier that already
* exists.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final LogSink createSink(String projectName, LogSink sink) {
PROJECT_PATH_TEMPLATE.validate(projectName);

CreateSinkRequest request =
CreateSinkRequest.newBuilder().setProjectName(projectName).setSink(sink).build();

return createSink(request);
}

Expand All @@ -317,7 +388,7 @@ public final LogSink createSink(String projectName, LogSink sink) {
* <!-- end manual edit -->
*
* @param request The request object containing all of the parameters for the API call.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public LogSink createSink(CreateSinkRequest request) {
return createSinkCallable().call(request);
Expand All @@ -329,7 +400,6 @@ public LogSink createSink(CreateSinkRequest request) {
*
* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable() {
return createSinkCallable;
Expand All @@ -353,12 +423,13 @@ public final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable() {
* @param sink The updated sink, whose name must be the same as the sink
* identifier in `sinkName`. If `sinkName` does not exist, then
* this method creates a new sink.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final LogSink updateSink(String sinkName, LogSink sink) {
SINK_PATH_TEMPLATE.validate(sinkName);

UpdateSinkRequest request =
UpdateSinkRequest.newBuilder().setSinkName(sinkName).setSink(sink).build();

return updateSink(request);
}

Expand All @@ -370,7 +441,7 @@ public final LogSink updateSink(String sinkName, LogSink sink) {
* <!-- end manual edit -->
*
* @param request The request object containing all of the parameters for the API call.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public LogSink updateSink(UpdateSinkRequest request) {
return updateSinkCallable().call(request);
Expand All @@ -382,7 +453,6 @@ public LogSink updateSink(UpdateSinkRequest request) {
*
* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable() {
return updateSinkCallable;
Expand All @@ -399,11 +469,11 @@ public final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable() {
*
* @param sinkName The resource name of the sink to delete.
* Example: `"projects/my-project-id/sinks/my-sink-id"`.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteSink(String sinkName) {
SINK_PATH_TEMPLATE.validate(sinkName);
DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName).build();

deleteSink(request);
}

Expand All @@ -415,7 +485,7 @@ public final void deleteSink(String sinkName) {
* <!-- end manual edit -->
*
* @param request The request object containing all of the parameters for the API call.
* @throws ApiException if the remote call fails
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
private void deleteSink(DeleteSinkRequest request) {
deleteSinkCallable().call(request);
Expand All @@ -427,7 +497,6 @@ private void deleteSink(DeleteSinkRequest request) {
*
* <!-- manual edit -->
* <!-- end manual edit -->
* @throws ApiException if the remote call fails
*/
public final ApiCallable<DeleteSinkRequest, Empty> deleteSinkCallable() {
return deleteSinkCallable;
Expand Down
Loading