Search in sources :

Example 1 with OperationTimedPollAlgorithm

use of com.google.api.gax.longrunning.OperationTimedPollAlgorithm in project gapic-generator-java by googleapis.

the class RetrySettingsComposer method createLroSettingsBuilderExpr.

public static Expr createLroSettingsBuilderExpr(Service service, GapicServiceConfig serviceConfig, Method method, VariableExpr builderVarExpr, VariableExpr retryableCodeDefsVarExpr, VariableExpr retryParamDefsVarExpr, TypeNode operationResponseTransformer, TypeNode operationMetadataTransformer) {
    Preconditions.checkState(method.hasLro(), String.format("Tried to create LRO settings initialization for non-LRO method %s", method.name()));
    String codeName = serviceConfig.getRetryCodeName(service, method);
    String retryParamName = serviceConfig.getRetryParamsName(service, method);
    String settingsGetterMethodName = String.format("%sOperationSettings", JavaStyle.toLowerCamelCase(method.name()));
    Function<String, ValueExpr> strValExprFn = s -> ValueExpr.withValue(StringObjectValue.withValue(s));
    // Argument for setInitialCallSettings.
    Expr unaryCallSettingsExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("UnaryCallSettings")).setGenerics(Arrays.asList(method.inputType().reference(), FIXED_TYPESTORE.get("OperationSnapshot").reference())).setMethodName("newUnaryCallSettingsBuilder").build();
    unaryCallSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(unaryCallSettingsExpr).setMethodName("setRetryableCodes").setArguments(MethodInvocationExpr.builder().setExprReferenceExpr(retryableCodeDefsVarExpr).setMethodName("get").setArguments(strValExprFn.apply(codeName)).build()).build();
    unaryCallSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(unaryCallSettingsExpr).setMethodName("setRetrySettings").setArguments(MethodInvocationExpr.builder().setExprReferenceExpr(retryParamDefsVarExpr).setMethodName("get").setArguments(strValExprFn.apply(retryParamName)).build()).build();
    unaryCallSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(unaryCallSettingsExpr).setMethodName("build").build();
    Expr builderSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderVarExpr).setMethodName(settingsGetterMethodName).build();
    builderSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderSettingsExpr).setMethodName("setInitialCallSettings").setArguments(unaryCallSettingsExpr).build();
    Function<TypeNode, VariableExpr> classFieldRefFn = t -> VariableExpr.builder().setVariable(Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()).setStaticReferenceType(t).build();
    builderSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderSettingsExpr).setMethodName("setResponseTransformer").setArguments(MethodInvocationExpr.builder().setStaticReferenceType(operationResponseTransformer).setMethodName("create").setArguments(classFieldRefFn.apply(method.lro().responseType())).build()).build();
    builderSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderSettingsExpr).setMethodName("setMetadataTransformer").setArguments(MethodInvocationExpr.builder().setStaticReferenceType(operationMetadataTransformer).setMethodName("create").setArguments(classFieldRefFn.apply(method.lro().metadataType())).build()).build();
    Expr lroRetrySettingsExpr = createLroRetrySettingsExpr(service, method, serviceConfig);
    Expr pollAlgoExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("OperationTimedPollAlgorithm")).setMethodName("create").setArguments(lroRetrySettingsExpr).build();
    builderSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(builderSettingsExpr).setMethodName("setPollingAlgorithm").setArguments(pollAlgoExpr).build();
    return builderSettingsExpr;
}
Also used : BlockStatement(com.google.api.generator.engine.ast.BlockStatement) Arrays(java.util.Arrays) TypeNode(com.google.api.generator.engine.ast.TypeNode) GapicLroRetrySettings(com.google.api.generator.gapic.model.GapicLroRetrySettings) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) ProtoOperationTransformers(com.google.api.gax.grpc.ProtoOperationTransformers) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) FlowController(com.google.api.gax.batching.FlowController) RetryPolicy(io.grpc.serviceconfig.MethodConfig.RetryPolicy) Variable(com.google.api.generator.engine.ast.Variable) Function(java.util.function.Function) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) Durations(com.google.protobuf.util.Durations) ArrayList(java.util.ArrayList) RetrySettings(com.google.api.gax.retrying.RetrySettings) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) Expr(com.google.api.generator.engine.ast.Expr) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) Lists(com.google.common.collect.Lists) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Map(java.util.Map) Code(com.google.rpc.Code) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BatchingSettings(com.google.api.gax.batching.BatchingSettings) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) Collectors(java.util.stream.Collectors) GapicRetrySettings(com.google.api.generator.gapic.model.GapicRetrySettings) Service(com.google.api.generator.gapic.model.Service) Duration(com.google.protobuf.Duration) List(java.util.List) OperationTimedPollAlgorithm(com.google.api.gax.longrunning.OperationTimedPollAlgorithm) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) Optional(java.util.Optional) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) Expr(com.google.api.generator.engine.ast.Expr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Aggregations

BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)1 FlowController (com.google.api.gax.batching.FlowController)1 ProtoOperationTransformers (com.google.api.gax.grpc.ProtoOperationTransformers)1 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)1 OperationTimedPollAlgorithm (com.google.api.gax.longrunning.OperationTimedPollAlgorithm)1 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 StatusCode (com.google.api.gax.rpc.StatusCode)1 UnaryCallSettings (com.google.api.gax.rpc.UnaryCallSettings)1 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 BlockStatement (com.google.api.generator.engine.ast.BlockStatement)1 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)1 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)1 Expr (com.google.api.generator.engine.ast.Expr)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)1 PrimitiveValue (com.google.api.generator.engine.ast.PrimitiveValue)1 StringObjectValue (com.google.api.generator.engine.ast.StringObjectValue)1 TypeNode (com.google.api.generator.engine.ast.TypeNode)1 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)1