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();
}
}
Aggregations