1 /* 2 * Copyright 2018 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.util; 18 19 import io.grpc.LoadBalancer; 20 import io.grpc.LoadBalancerProvider; 21 import io.grpc.NameResolver.ConfigOrError; 22 import java.util.Map; 23 24 /** 25 * Provider for the "round_robin" balancing policy. 26 */ 27 // Make it package-private so that it cannot be directly referenced by users. Java service loader 28 // requires the provider to be public, but we can hide it under a package-private class. 29 final class SecretRoundRobinLoadBalancerProvider { SecretRoundRobinLoadBalancerProvider()30 private SecretRoundRobinLoadBalancerProvider() { 31 } 32 33 public static final class Provider extends LoadBalancerProvider { 34 35 private static final String NO_CONFIG = "no service config"; 36 37 38 @Override isAvailable()39 public boolean isAvailable() { 40 return true; 41 } 42 43 @Override getPriority()44 public int getPriority() { 45 return 5; 46 } 47 48 @Override getPolicyName()49 public String getPolicyName() { 50 return "round_robin"; 51 } 52 53 @Override newLoadBalancer(LoadBalancer.Helper helper)54 public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) { 55 return new RoundRobinLoadBalancer(helper); 56 } 57 58 @Override parseLoadBalancingPolicyConfig( Map<String, ?> rawLoadBalancingPolicyConfig)59 public ConfigOrError parseLoadBalancingPolicyConfig( 60 Map<String, ?> rawLoadBalancingPolicyConfig) { 61 return ConfigOrError.fromConfig(NO_CONFIG); 62 } 63 } 64 } 65