• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ServerCall.Listener} which forwards all of its methods to another {@link
21  * ServerCall.Listener} of matching parameterized types.
22  */
23 public abstract class ForwardingServerCallListener<ReqT>
24     extends PartialForwardingServerCallListener<ReqT> {
25   /**
26    * Returns the delegated {@code ServerCall.Listener}.
27    */
28   @Override
delegate()29   protected abstract ServerCall.Listener<ReqT> delegate();
30 
31   @Override
onMessage(ReqT message)32   public void onMessage(ReqT message) {
33     delegate().onMessage(message);
34   }
35 
36   /**
37    * A simplified version of {@link ForwardingServerCallListener} where subclasses can pass in a
38    * {@link ServerCall.Listener} as the delegate.
39    */
40   public abstract static class SimpleForwardingServerCallListener<ReqT>
41       extends ForwardingServerCallListener<ReqT> {
42 
43     private final ServerCall.Listener<ReqT> delegate;
44 
SimpleForwardingServerCallListener(ServerCall.Listener<ReqT> delegate)45     protected SimpleForwardingServerCallListener(ServerCall.Listener<ReqT> delegate) {
46       this.delegate = delegate;
47     }
48 
49     @Override
delegate()50     protected ServerCall.Listener<ReqT> delegate() {
51       return delegate;
52     }
53   }
54 }
55