Search in sources :

Example 1 with HttpJsonLongRunningClient

use of com.google.api.gax.httpjson.HttpJsonLongRunningClient in project gapic-generator-java by googleapis.

the class HttpJsonServiceStubClassComposer method createLongRunningClient.

@Override
protected List<Statement> createLongRunningClient(Service service, TypeStore typeStore) {
    Method pollingMethod = service.operationPollingMethod();
    if (pollingMethod != null) {
        Expr thisExpr = ValueExpr.withValue(ThisObjectValue.withType(typeStore.get(getTransportContext().classNames().getTransportServiceStubClassName(service))));
        VariableExpr callable = VariableExpr.withVariable(Variable.builder().setName(pollingMethod.name().toLowerCase() + "Callable").setType(TypeNode.withReference(ConcreteReference.withClazz(UnaryCallable.class))).build());
        VariableExpr methodDescriptor = VariableExpr.withVariable(Variable.builder().setName(pollingMethod.name().toLowerCase() + "MethodDescriptor").setType(TypeNode.withReference(ConcreteReference.withClazz(ApiMethodDescriptor.class))).build());
        TypeNode httpJsonLongRunningClientType = TypeNode.withReference(ConcreteReference.builder().setClazz(HttpJsonLongRunningClient.class).setGenerics(Arrays.asList(pollingMethod.inputType().reference(), pollingMethod.outputType().reference())).build());
        NewObjectExpr HttpJsonLongRunningClient = NewObjectExpr.builder().setType(httpJsonLongRunningClientType).setArguments(Arrays.asList(callable, MethodInvocationExpr.builder().setExprReferenceExpr(methodDescriptor).setMethodName("getOperationSnapshotFactory").build(), MethodInvocationExpr.builder().setExprReferenceExpr(methodDescriptor).setMethodName("getPollingRequestFactory").build())).build();
        AssignmentExpr assignLongRunningClient = AssignmentExpr.builder().setVariableExpr(VariableExpr.builder().setExprReferenceExpr(thisExpr).setVariable(Variable.builder().setName("longRunningClient").setType(TypeNode.withReference(ConcreteReference.withClazz(LongRunningClient.class))).build()).build()).setValueExpr(HttpJsonLongRunningClient).build();
        return Arrays.asList(ExprStatement.withExpr(assignLongRunningClient));
    } else {
        return Collections.emptyList();
    }
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) HttpJsonLongRunningClient(com.google.api.gax.httpjson.HttpJsonLongRunningClient) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Method(com.google.api.generator.gapic.model.Method) TypeNode(com.google.api.generator.engine.ast.TypeNode) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr)

Aggregations

HttpJsonLongRunningClient (com.google.api.gax.httpjson.HttpJsonLongRunningClient)1 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)1 Expr (com.google.api.generator.engine.ast.Expr)1 LambdaExpr (com.google.api.generator.engine.ast.LambdaExpr)1 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)1 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)1 TypeNode (com.google.api.generator.engine.ast.TypeNode)1 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1 Method (com.google.api.generator.gapic.model.Method)1