1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.google.api.generator.gapic.model; 16 17 import com.google.auto.value.AutoValue; 18 import com.google.common.collect.ImmutableList; 19 import java.util.List; 20 import javax.annotation.Nullable; 21 22 @AutoValue 23 public abstract class GapicBatchingSettings { 24 public enum FlowControlLimitExceededBehavior { 25 THROW_EXCEPTION, 26 BLOCK, 27 IGNORE 28 }; 29 30 // Threshold fields. protoPakkage()31 public abstract String protoPakkage(); 32 serviceName()33 public abstract String serviceName(); 34 methodName()35 public abstract String methodName(); 36 elementCountThreshold()37 public abstract int elementCountThreshold(); 38 requestByteThreshold()39 public abstract long requestByteThreshold(); 40 delayThresholdMillis()41 public abstract long delayThresholdMillis(); 42 43 @Nullable flowControlElementLimit()44 public abstract Integer flowControlElementLimit(); 45 46 @Nullable flowControlByteLimit()47 public abstract Integer flowControlByteLimit(); 48 flowControlLimitExceededBehavior()49 public abstract FlowControlLimitExceededBehavior flowControlLimitExceededBehavior(); 50 51 // Batch descriptor fields. batchedFieldName()52 public abstract String batchedFieldName(); 53 discriminatorFieldNames()54 public abstract ImmutableList<String> discriminatorFieldNames(); 55 56 @Nullable subresponseFieldName()57 public abstract String subresponseFieldName(); 58 matches(Service service, Method method)59 public boolean matches(Service service, Method method) { 60 return protoPakkage().equals(service.protoPakkage()) 61 && serviceName().equals(service.name()) 62 && methodName().equals(method.name()); 63 } 64 builder()65 public static Builder builder() { 66 return new AutoValue_GapicBatchingSettings.Builder() 67 .setFlowControlLimitExceededBehavior(FlowControlLimitExceededBehavior.IGNORE); 68 } 69 70 @AutoValue.Builder 71 public abstract static class Builder { setProtoPakkage(String protoPakkage)72 public abstract Builder setProtoPakkage(String protoPakkage); 73 setServiceName(String serviceName)74 public abstract Builder setServiceName(String serviceName); 75 setMethodName(String methodName)76 public abstract Builder setMethodName(String methodName); 77 setElementCountThreshold(int elementCountThreshold)78 public abstract Builder setElementCountThreshold(int elementCountThreshold); 79 setRequestByteThreshold(long requestByteThreshold)80 public abstract Builder setRequestByteThreshold(long requestByteThreshold); 81 setDelayThresholdMillis(long delalyThresholdMillis)82 public abstract Builder setDelayThresholdMillis(long delalyThresholdMillis); 83 setFlowControlElementLimit(Integer flowControlElementLimit)84 public abstract Builder setFlowControlElementLimit(Integer flowControlElementLimit); 85 setFlowControlByteLimit(Integer flowControlByteLimit)86 public abstract Builder setFlowControlByteLimit(Integer flowControlByteLimit); 87 setFlowControlLimitExceededBehavior( FlowControlLimitExceededBehavior behavior)88 public abstract Builder setFlowControlLimitExceededBehavior( 89 FlowControlLimitExceededBehavior behavior); 90 setBatchedFieldName(String batchedFieldName)91 public abstract Builder setBatchedFieldName(String batchedFieldName); 92 setDiscriminatorFieldNames(List<String> discriminatorFieldNames)93 public abstract Builder setDiscriminatorFieldNames(List<String> discriminatorFieldNames); 94 setSubresponseFieldName(String subresponseFieldName)95 public abstract Builder setSubresponseFieldName(String subresponseFieldName); 96 build()97 public abstract GapicBatchingSettings build(); 98 } 99 } 100