1 /* 2 * Copyright 2019 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 com.google.common.base.MoreObjects; 20 import io.grpc.Attributes; 21 import io.grpc.Channel; 22 import io.grpc.ChannelLogger; 23 import io.grpc.EquivalentAddressGroup; 24 import io.grpc.ExperimentalApi; 25 import io.grpc.LoadBalancer; 26 import io.grpc.LoadBalancer.Subchannel; 27 import io.grpc.LoadBalancer.SubchannelStateListener; 28 import java.util.List; 29 30 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771") 31 public abstract class ForwardingSubchannel extends LoadBalancer.Subchannel { 32 /** 33 * Returns the underlying Subchannel. 34 */ delegate()35 protected abstract Subchannel delegate(); 36 37 @Override start(SubchannelStateListener listener)38 public void start(SubchannelStateListener listener) { 39 delegate().start(listener); 40 } 41 42 @Override shutdown()43 public void shutdown() { 44 delegate().shutdown(); 45 } 46 47 @Override requestConnection()48 public void requestConnection() { 49 delegate().requestConnection(); 50 } 51 52 @Override getAllAddresses()53 public List<EquivalentAddressGroup> getAllAddresses() { 54 return delegate().getAllAddresses(); 55 } 56 57 @Override getAttributes()58 public Attributes getAttributes() { 59 return delegate().getAttributes(); 60 } 61 62 @Override asChannel()63 public Channel asChannel() { 64 return delegate().asChannel(); 65 } 66 67 @Override getChannelLogger()68 public ChannelLogger getChannelLogger() { 69 return delegate().getChannelLogger(); 70 } 71 72 @Override getInternalSubchannel()73 public Object getInternalSubchannel() { 74 return delegate().getInternalSubchannel(); 75 } 76 77 @Override updateAddresses(List<EquivalentAddressGroup> addrs)78 public void updateAddresses(List<EquivalentAddressGroup> addrs) { 79 delegate().updateAddresses(addrs); 80 } 81 82 @Override toString()83 public String toString() { 84 return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString(); 85 } 86 } 87