use of io.grpc.serviceconfig.MethodConfig.RetryPolicy in project gapic-generator-java by googleapis.
the class RetrySettingsComposer method createRetrySettingsExprs.
private static List<Expr> createRetrySettingsExprs(String settingsName, GapicRetrySettings settings, VariableExpr settingsVarExpr, VariableExpr definitionsVarExpr) {
Expr settingsBuilderExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("RetrySettings")).setMethodName("newBuilder").build();
RetryPolicy retryPolicy = settings.retryPolicy();
if (settings.kind().equals(GapicRetrySettings.Kind.FULL)) {
Preconditions.checkState(retryPolicy.hasInitialBackoff(), String.format("initialBackoff not found for setting %s", settingsName));
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("setInitialRetryDelay").setArguments(createDurationOfMillisExpr(toValExpr(retryPolicy.getInitialBackoff()))).build();
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("setRetryDelayMultiplier").setArguments(toValExpr(retryPolicy.getBackoffMultiplier())).build();
Preconditions.checkState(retryPolicy.hasMaxBackoff(), String.format("maxBackoff not found for setting %s", settingsName));
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("setMaxRetryDelay").setArguments(createDurationOfMillisExpr(toValExpr(retryPolicy.getMaxBackoff()))).build();
}
if (!settings.kind().equals(GapicRetrySettings.Kind.NONE)) {
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("setInitialRpcTimeout").setArguments(createDurationOfMillisExpr(toValExpr(settings.timeout()))).build();
}
// This will always be done, no matter the type of the retry settings object.
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("setRpcTimeoutMultiplier").setArguments(ValueExpr.withValue(PrimitiveValue.builder().setType(TypeNode.DOUBLE).setValue("1.0").build())).build();
if (!settings.kind().equals(GapicRetrySettings.Kind.NONE)) {
for (String setterMethodName : Arrays.asList("setMaxRpcTimeout", "setTotalTimeout")) {
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName(setterMethodName).setArguments(createDurationOfMillisExpr(toValExpr(settings.timeout()))).build();
}
}
settingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(settingsBuilderExpr).setMethodName("build").setReturnType(settingsVarExpr.type()).build();
Expr settingsAssignExpr = AssignmentExpr.builder().setVariableExpr(settingsVarExpr).setValueExpr(settingsBuilderExpr).build();
Expr definitionsPutExpr = MethodInvocationExpr.builder().setExprReferenceExpr(definitionsVarExpr).setMethodName("put").setArguments(ValueExpr.withValue(StringObjectValue.withValue(settingsName)), settingsVarExpr).build();
return Arrays.asList(settingsAssignExpr, definitionsPutExpr);
}
Aggregations