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 2020 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.rls;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.base.Converter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.grpc.internal.JsonUtil;
import io.grpc.lookup.v1.RouteLookupRequest;
import io.grpc.lookup.v1.RouteLookupResponse;
import io.grpc.rls.RlsProtoData.ExtraKeys;
import io.grpc.rls.RlsProtoData.GrpcKeyBuilder;
import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name;
import io.grpc.rls.RlsProtoData.NameMatcher;
import io.grpc.rls.RlsProtoData.RouteLookupConfig;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
/**
* RlsProtoConverters is a collection of {@link Converter} between RouteLookupService proto / json
* messages to internal representation in {@link RlsProtoData}.
*/
final class RlsProtoConverters {
private static final long MAX_AGE_NANOS = MINUTES.toNanos(5);
private static final long MAX_CACHE_SIZE = 5 * 1024 * 1024; // 5MiB
private static final long DEFAULT_LOOKUP_SERVICE_TIMEOUT = SECONDS.toNanos(10);
private static final ImmutableList EXTRA_KEY_NAMES =
ImmutableList.of("host", "service", "method");
/**
* RouteLookupRequestConverter converts between {@link RouteLookupRequest} and {@link
* RlsProtoData.RouteLookupRequest}.
*/
static final class RouteLookupRequestConverter
extends Converter {
@Override
protected RlsProtoData.RouteLookupRequest doForward(RouteLookupRequest routeLookupRequest) {
return RlsProtoData.RouteLookupRequest.create(
ImmutableMap.copyOf(routeLookupRequest.getKeyMapMap()));
}
@Override
protected RouteLookupRequest doBackward(RlsProtoData.RouteLookupRequest routeLookupRequest) {
return
RouteLookupRequest.newBuilder()
.setTargetType("grpc")
.putAllKeyMap(routeLookupRequest.keyMap())
.build();
}
}
/**
* RouteLookupResponseConverter converts between {@link RouteLookupResponse} and {@link
* RlsProtoData.RouteLookupResponse}.
*/
static final class RouteLookupResponseConverter
extends Converter {
@Override
protected RlsProtoData.RouteLookupResponse doForward(RouteLookupResponse routeLookupResponse) {
return
RlsProtoData.RouteLookupResponse.create(
ImmutableList.copyOf(routeLookupResponse.getTargetsList()),
routeLookupResponse.getHeaderData());
}
@Override
protected RouteLookupResponse doBackward(RlsProtoData.RouteLookupResponse routeLookupResponse) {
return RouteLookupResponse.newBuilder()
.addAllTargets(routeLookupResponse.targets())
.setHeaderData(routeLookupResponse.getHeaderData())
.build();
}
}
/**
* RouteLookupConfigConverter converts between json map to {@link RouteLookupConfig}.
*/
static final class RouteLookupConfigConverter
extends Converter