com.google.cloud.monitoring.v3.stub.GrpcAlertPolicyServiceStub Maven / Gradle / Ivy
Show all versions of google-cloud-monitoring Show documentation
/*
* Copyright 2024 Google LLC
*
* 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
*
* https://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.cloud.monitoring.v3.stub;
import static com.google.cloud.monitoring.v3.AlertPolicyServiceClient.ListAlertPoliciesPagedResponse;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.longrunning.stub.GrpcOperationsStub;
import com.google.monitoring.v3.AlertPolicy;
import com.google.monitoring.v3.CreateAlertPolicyRequest;
import com.google.monitoring.v3.DeleteAlertPolicyRequest;
import com.google.monitoring.v3.GetAlertPolicyRequest;
import com.google.monitoring.v3.ListAlertPoliciesRequest;
import com.google.monitoring.v3.ListAlertPoliciesResponse;
import com.google.monitoring.v3.UpdateAlertPolicyRequest;
import com.google.protobuf.Empty;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* gRPC stub implementation for the AlertPolicyService service API.
*
* This class is for advanced usage and reflects the underlying API directly.
*/
@Generated("by gapic-generator-java")
public class GrpcAlertPolicyServiceStub extends AlertPolicyServiceStub {
private static final MethodDescriptor
listAlertPoliciesMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.monitoring.v3.AlertPolicyService/ListAlertPolicies")
.setRequestMarshaller(
ProtoUtils.marshaller(ListAlertPoliciesRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ListAlertPoliciesResponse.getDefaultInstance()))
.build();
private static final MethodDescriptor
getAlertPolicyMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.monitoring.v3.AlertPolicyService/GetAlertPolicy")
.setRequestMarshaller(
ProtoUtils.marshaller(GetAlertPolicyRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(AlertPolicy.getDefaultInstance()))
.build();
private static final MethodDescriptor
createAlertPolicyMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.monitoring.v3.AlertPolicyService/CreateAlertPolicy")
.setRequestMarshaller(
ProtoUtils.marshaller(CreateAlertPolicyRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(AlertPolicy.getDefaultInstance()))
.build();
private static final MethodDescriptor
deleteAlertPolicyMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.monitoring.v3.AlertPolicyService/DeleteAlertPolicy")
.setRequestMarshaller(
ProtoUtils.marshaller(DeleteAlertPolicyRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
.build();
private static final MethodDescriptor
updateAlertPolicyMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.monitoring.v3.AlertPolicyService/UpdateAlertPolicy")
.setRequestMarshaller(
ProtoUtils.marshaller(UpdateAlertPolicyRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(AlertPolicy.getDefaultInstance()))
.build();
private final UnaryCallable
listAlertPoliciesCallable;
private final UnaryCallable
listAlertPoliciesPagedCallable;
private final UnaryCallable getAlertPolicyCallable;
private final UnaryCallable createAlertPolicyCallable;
private final UnaryCallable deleteAlertPolicyCallable;
private final UnaryCallable updateAlertPolicyCallable;
private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
private final GrpcStubCallableFactory callableFactory;
public static final GrpcAlertPolicyServiceStub create(AlertPolicyServiceStubSettings settings)
throws IOException {
return new GrpcAlertPolicyServiceStub(settings, ClientContext.create(settings));
}
public static final GrpcAlertPolicyServiceStub create(ClientContext clientContext)
throws IOException {
return new GrpcAlertPolicyServiceStub(
AlertPolicyServiceStubSettings.newBuilder().build(), clientContext);
}
public static final GrpcAlertPolicyServiceStub create(
ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
return new GrpcAlertPolicyServiceStub(
AlertPolicyServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of GrpcAlertPolicyServiceStub, using the given settings. This is
* protected so that it is easy to make a subclass, but otherwise, the static factory methods
* should be preferred.
*/
protected GrpcAlertPolicyServiceStub(
AlertPolicyServiceStubSettings settings, ClientContext clientContext) throws IOException {
this(settings, clientContext, new GrpcAlertPolicyServiceCallableFactory());
}
/**
* Constructs an instance of GrpcAlertPolicyServiceStub, using the given settings. This is
* protected so that it is easy to make a subclass, but otherwise, the static factory methods
* should be preferred.
*/
protected GrpcAlertPolicyServiceStub(
AlertPolicyServiceStubSettings settings,
ClientContext clientContext,
GrpcStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
GrpcCallSettings
listAlertPoliciesTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(listAlertPoliciesMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings getAlertPolicyTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(getAlertPolicyMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings createAlertPolicyTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(createAlertPolicyMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings deleteAlertPolicyTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(deleteAlertPolicyMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings updateAlertPolicyTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(updateAlertPolicyMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add(
"alert_policy.name", String.valueOf(request.getAlertPolicy().getName()));
return builder.build();
})
.build();
this.listAlertPoliciesCallable =
callableFactory.createUnaryCallable(
listAlertPoliciesTransportSettings,
settings.listAlertPoliciesSettings(),
clientContext);
this.listAlertPoliciesPagedCallable =
callableFactory.createPagedCallable(
listAlertPoliciesTransportSettings,
settings.listAlertPoliciesSettings(),
clientContext);
this.getAlertPolicyCallable =
callableFactory.createUnaryCallable(
getAlertPolicyTransportSettings, settings.getAlertPolicySettings(), clientContext);
this.createAlertPolicyCallable =
callableFactory.createUnaryCallable(
createAlertPolicyTransportSettings,
settings.createAlertPolicySettings(),
clientContext);
this.deleteAlertPolicyCallable =
callableFactory.createUnaryCallable(
deleteAlertPolicyTransportSettings,
settings.deleteAlertPolicySettings(),
clientContext);
this.updateAlertPolicyCallable =
callableFactory.createUnaryCallable(
updateAlertPolicyTransportSettings,
settings.updateAlertPolicySettings(),
clientContext);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
public GrpcOperationsStub getOperationsStub() {
return operationsStub;
}
@Override
public UnaryCallable
listAlertPoliciesCallable() {
return listAlertPoliciesCallable;
}
@Override
public UnaryCallable
listAlertPoliciesPagedCallable() {
return listAlertPoliciesPagedCallable;
}
@Override
public UnaryCallable getAlertPolicyCallable() {
return getAlertPolicyCallable;
}
@Override
public UnaryCallable createAlertPolicyCallable() {
return createAlertPolicyCallable;
}
@Override
public UnaryCallable deleteAlertPolicyCallable() {
return deleteAlertPolicyCallable;
}
@Override
public UnaryCallable updateAlertPolicyCallable() {
return updateAlertPolicyCallable;
}
@Override
public final void close() {
try {
backgroundResources.close();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
}
@Override
public void shutdown() {
backgroundResources.shutdown();
}
@Override
public boolean isShutdown() {
return backgroundResources.isShutdown();
}
@Override
public boolean isTerminated() {
return backgroundResources.isTerminated();
}
@Override
public void shutdownNow() {
backgroundResources.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return backgroundResources.awaitTermination(duration, unit);
}
}