Search in sources :

Example 1 with BatchingConfig

use of com.google.api.codegen.config.BatchingConfig in project toolkit by googleapis.

the class BatchingTransformer method generateBatchingConfig.

public BatchingConfigView generateBatchingConfig(MethodContext context) {
    BatchingConfig batchingConfig = context.getMethodConfig().getBatching();
    BatchingConfigView.Builder batchingConfigView = BatchingConfigView.newBuilder();
    batchingConfigView.elementCountThreshold(batchingConfig.getElementCountThreshold());
    batchingConfigView.elementCountLimit(batchingConfig.getElementCountLimit());
    batchingConfigView.requestByteThreshold(batchingConfig.getRequestByteThreshold());
    batchingConfigView.requestByteLimit(batchingConfig.getRequestByteLimit());
    batchingConfigView.delayThresholdMillis(batchingConfig.getDelayThresholdMillis());
    batchingConfigView.flowControlElementLimit(batchingConfig.getFlowControlElementLimit());
    batchingConfigView.flowControlByteLimit(batchingConfig.getFlowControlByteLimit());
    batchingConfigView.flowControlLimitExceededBehavior(batchingConfig.getFlowControlLimitConfig().toString());
    return batchingConfigView.build();
}
Also used : BatchingConfigView(com.google.api.codegen.viewmodel.BatchingConfigView) BatchingConfig(com.google.api.codegen.config.BatchingConfig)

Example 2 with BatchingConfig

use of com.google.api.codegen.config.BatchingConfig in project toolkit by googleapis.

the class BatchingTransformer method generateDescriptorClass.

private BatchingDescriptorClassView generateDescriptorClass(MethodContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getMethodModel();
    BatchingConfig batching = context.getMethodConfig().getBatching();
    FieldModel batchedField = batching.getBatchedField();
    FieldModel subresponseField = batching.getSubresponseField();
    BatchingDescriptorClassView.Builder desc = BatchingDescriptorClassView.newBuilder();
    desc.name(context.getNamer().getBatchingDescriptorConstName(context.getMethodModel()));
    desc.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
    desc.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
    desc.batchedFieldTypeName(context.getTypeTable().getAndSaveNicknameFor(batchedField));
    desc.partitionKeys(generatePartitionKeys(context));
    desc.discriminatorFieldCopies(generateDiscriminatorFieldCopies(context));
    desc.batchedFieldGetFunction(namer.getFieldGetFunctionName(batchedField));
    desc.batchedFieldSetFunction(namer.getFieldSetFunctionName(batchedField));
    desc.batchedFieldCountGetFunction(namer.getFieldCountGetFunctionName(batchedField));
    if (subresponseField != null) {
        desc.subresponseTypeName(context.getTypeTable().getAndSaveNicknameFor(subresponseField));
        desc.subresponseByIndexGetFunction(namer.getByIndexGetFunctionName(subresponseField));
        desc.subresponseSetFunction(namer.getFieldSetFunctionName(subresponseField));
    }
    return desc.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) BatchingDescriptorClassView(com.google.api.codegen.viewmodel.BatchingDescriptorClassView) BatchingConfig(com.google.api.codegen.config.BatchingConfig) FieldModel(com.google.api.codegen.config.FieldModel)

Example 3 with BatchingConfig

use of com.google.api.codegen.config.BatchingConfig in project toolkit by googleapis.

the class TestCaseTransformer method createMockResponseAdditionalSubTrees.

private Iterable<InitCodeNode> createMockResponseAdditionalSubTrees(MethodContext context) {
    List<InitCodeNode> additionalSubTrees = new ArrayList<>();
    if (context.getMethodConfig().isPageStreaming()) {
        // Initialize one resource element if it is page-streaming.
        PageStreamingConfig config = context.getMethodConfig().getPageStreaming();
        if (config.getResourcesFieldConfig().getFieldPath().size() == 1) {
            String resourceFieldName = config.getResourcesFieldName();
            additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
        } else {
            // Initialize all the objects between the response type and the resource element.
            List<FieldModel> fieldGetters = Lists.reverse(config.getResourcesFieldConfig().getFieldPath());
            InitCodeNode initCodeNode = null;
            for (FieldModel field : fieldGetters) {
                if (config.getResourcesField().isRepeated()) {
                    initCodeNode = InitCodeNode.createSingletonList(config.getResourcesFieldName());
                } else {
                    initCodeNode = InitCodeNode.create(config.getResourcesFieldName());
                }
                InitCodeLineType lineType = field.isRepeated() ? ListInitLine : StructureInitLine;
                initCodeNode = InitCodeNode.createWithChildren(field.getSimpleName(), lineType, initCodeNode);
            }
            additionalSubTrees.add(initCodeNode);
        }
        // Set the initial value of the page token to empty, in order to indicate that no more pages
        // are available
        String responseTokenName = config.getResponseTokenField().getSimpleName();
        additionalSubTrees.add(InitCodeNode.createWithValue(responseTokenName, InitValueConfig.createWithValue(InitValue.createLiteral(""))));
    }
    if (context.getMethodConfig().isBatching()) {
        // Initialize one batching element if it is batching.
        BatchingConfig config = context.getMethodConfig().getBatching();
        if (config.getSubresponseField() != null) {
            String subResponseFieldName = config.getSubresponseField().getSimpleName();
            additionalSubTrees.add(InitCodeNode.createSingletonList(subResponseFieldName));
        }
    }
    if (context.getMethodConfig().isGrpcStreaming()) {
        GrpcStreamingConfig streamingConfig = context.getMethodConfig().getGrpcStreaming();
        if (streamingConfig.hasResourceField()) {
            String resourceFieldName = streamingConfig.getResourcesField().getSimpleName();
            additionalSubTrees.add(InitCodeNode.createSingletonList(resourceFieldName));
        }
    }
    return additionalSubTrees;
}
Also used : InitCodeNode(com.google.api.codegen.metacode.InitCodeNode) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) ArrayList(java.util.ArrayList) BatchingConfig(com.google.api.codegen.config.BatchingConfig) InitCodeLineType(com.google.api.codegen.metacode.InitCodeLineType) FieldModel(com.google.api.codegen.config.FieldModel) GrpcStreamingConfig(com.google.api.codegen.config.GrpcStreamingConfig)

Example 4 with BatchingConfig

use of com.google.api.codegen.config.BatchingConfig in project toolkit by googleapis.

the class BatchingTransformer method generateDescriptors.

public List<BatchingDescriptorView> generateDescriptors(InterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    ImmutableList.Builder<BatchingDescriptorView> descriptors = ImmutableList.builder();
    for (MethodModel method : context.getBatchingMethods()) {
        BatchingConfig batching = context.getMethodConfig(method).getBatching();
        BatchingDescriptorView.Builder descriptor = BatchingDescriptorView.newBuilder();
        descriptor.methodName(context.getNamer().getMethodKey(method));
        descriptor.batchedFieldName(namer.getFieldName(batching.getBatchedField()));
        descriptor.discriminatorFieldNames(generateDiscriminatorFieldNames(batching));
        if (batching.hasSubresponseField()) {
            descriptor.subresponseFieldName(namer.getFieldName(batching.getSubresponseField()));
        }
        descriptor.byteLengthFunctionName(namer.getByteLengthFunctionName(batching.getBatchedField()));
        descriptors.add(descriptor.build());
    }
    return descriptors.build();
}
Also used : BatchingDescriptorView(com.google.api.codegen.viewmodel.BatchingDescriptorView) MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList) BatchingConfig(com.google.api.codegen.config.BatchingConfig)

Example 5 with BatchingConfig

use of com.google.api.codegen.config.BatchingConfig in project toolkit by googleapis.

the class BatchingTransformer method generateDiscriminatorFieldCopies.

private List<FieldCopyView> generateDiscriminatorFieldCopies(MethodContext context) {
    List<FieldCopyView> fieldCopies = new ArrayList<>();
    BatchingConfig batching = context.getMethodConfig().getBatching();
    for (GenericFieldSelector fieldSelector : batching.getDiscriminatorFields()) {
        FieldModel selectedType = fieldSelector.getLastField();
        FieldCopyView fieldCopy = FieldCopyView.newBuilder().fieldGetFunction(context.getNamer().getFieldGetFunctionName(selectedType)).fieldSetFunction(context.getNamer().getFieldSetFunctionName(selectedType)).build();
        fieldCopies.add(fieldCopy);
    }
    return fieldCopies;
}
Also used : FieldCopyView(com.google.api.codegen.viewmodel.FieldCopyView) ArrayList(java.util.ArrayList) BatchingConfig(com.google.api.codegen.config.BatchingConfig) GenericFieldSelector(com.google.api.codegen.config.GenericFieldSelector) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

BatchingConfig (com.google.api.codegen.config.BatchingConfig)6 FieldModel (com.google.api.codegen.config.FieldModel)4 ArrayList (java.util.ArrayList)3 GenericFieldSelector (com.google.api.codegen.config.GenericFieldSelector)2 MethodModel (com.google.api.codegen.config.MethodModel)2 GrpcStreamingConfig (com.google.api.codegen.config.GrpcStreamingConfig)1 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)1 InitCodeLineType (com.google.api.codegen.metacode.InitCodeLineType)1 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)1 BatchingConfigView (com.google.api.codegen.viewmodel.BatchingConfigView)1 BatchingDescriptorClassView (com.google.api.codegen.viewmodel.BatchingDescriptorClassView)1 BatchingDescriptorView (com.google.api.codegen.viewmodel.BatchingDescriptorView)1 BatchingPartitionKeyView (com.google.api.codegen.viewmodel.BatchingPartitionKeyView)1 FieldCopyView (com.google.api.codegen.viewmodel.FieldCopyView)1 ImmutableList (com.google.common.collect.ImmutableList)1