Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2019 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.internal;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import io.grpc.CallOptions;
import io.grpc.InternalConfigSelector;
import io.grpc.LoadBalancer.PickSubchannelArgs;
import io.grpc.MethodDescriptor;
import io.grpc.Status.Code;
import io.grpc.internal.RetriableStream.Throttle;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
/**
* {@link ManagedChannelServiceConfig} is a fully parsed and validated representation of service
* configuration data.
*/
final class ManagedChannelServiceConfig {
@Nullable
private final MethodInfo defaultMethodConfig;
private final Map serviceMethodMap;
private final Map serviceMap;
@Nullable
private final Throttle retryThrottling;
@Nullable
private final Object loadBalancingConfig;
@Nullable
private final Map healthCheckingConfig;
ManagedChannelServiceConfig(
@Nullable MethodInfo defaultMethodConfig,
Map serviceMethodMap,
Map serviceMap,
@Nullable Throttle retryThrottling,
@Nullable Object loadBalancingConfig,
@Nullable Map healthCheckingConfig) {
this.defaultMethodConfig = defaultMethodConfig;
this.serviceMethodMap = Collections.unmodifiableMap(new HashMap<>(serviceMethodMap));
this.serviceMap = Collections.unmodifiableMap(new HashMap<>(serviceMap));
this.retryThrottling = retryThrottling;
this.loadBalancingConfig = loadBalancingConfig;
this.healthCheckingConfig =
healthCheckingConfig != null
? Collections.unmodifiableMap(new HashMap<>(healthCheckingConfig))
: null;
}
/** Returns an empty {@link ManagedChannelServiceConfig}. */
static ManagedChannelServiceConfig empty() {
return
new ManagedChannelServiceConfig(
null,
new HashMap(),
new HashMap(),
/* retryThrottling= */ null,
/* loadBalancingConfig= */ null,
/* healthCheckingConfig= */ null);
}
/**
* Parses the Channel level config values (e.g. excludes load balancing)
*/
static ManagedChannelServiceConfig fromServiceConfig(
Map serviceConfig,
boolean retryEnabled,
int maxRetryAttemptsLimit,
int maxHedgedAttemptsLimit,
@Nullable Object loadBalancingConfig) {
Throttle retryThrottling = null;
if (retryEnabled) {
retryThrottling = ServiceConfigUtil.getThrottlePolicy(serviceConfig);
}
Map serviceMethodMap = new HashMap<>();
Map serviceMap = new HashMap<>();
Map healthCheckingConfig =
ServiceConfigUtil.getHealthCheckedService(serviceConfig);
// Try and do as much validation here before we swap out the existing configuration. In case
// the input is invalid, we don't want to lose the existing configuration.
List