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