1 /* 2 * Copyright 2015 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; 18 19 /** 20 * A {@link ClientCall.Listener} which forwards all of its methods to another {@link 21 * ClientCall.Listener}. 22 */ 23 public abstract class ForwardingClientCallListener<RespT> 24 extends PartialForwardingClientCallListener<RespT> { 25 /** 26 * Returns the delegated {@code ClientCall.Listener}. 27 */ 28 @Override delegate()29 protected abstract ClientCall.Listener<RespT> delegate(); 30 31 @Override onMessage(RespT message)32 public void onMessage(RespT message) { 33 delegate().onMessage(message); 34 } 35 36 /** 37 * A simplified version of {@link ForwardingClientCallListener} where subclasses can pass in a 38 * {@link ClientCall.Listener} as the delegate. 39 */ 40 public abstract static class SimpleForwardingClientCallListener<RespT> 41 extends ForwardingClientCallListener<RespT> { 42 43 private final ClientCall.Listener<RespT> delegate; 44 SimpleForwardingClientCallListener(ClientCall.Listener<RespT> delegate)45 protected SimpleForwardingClientCallListener(ClientCall.Listener<RespT> delegate) { 46 this.delegate = delegate; 47 } 48 49 @Override delegate()50 protected ClientCall.Listener<RespT> delegate() { 51 return delegate; 52 } 53 } 54 } 55