1 /* 2 * Copyright 2016 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 * Listens on server transport life-cycle events, with the capability to read and/or change 21 * transport attributes. Attributes returned by this filter will be merged into {@link 22 * ServerCall#getAttributes}. 23 * 24 * <p>Multiple filters maybe registered to a server, in which case the output of a filter is the 25 * input of the next filter. For example, what returned by {@link #transportReady} of a filter is 26 * passed to the same method of the next filter, and the last filter's return value is the effective 27 * transport attributes. 28 * 29 * <p>{@link Grpc} defines commonly used attributes. 30 */ 31 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2132") 32 public abstract class ServerTransportFilter { 33 /** 34 * Called when a transport is ready to process streams. All necessary handshakes, e.g., TLS 35 * handshake, are done at this point. 36 * 37 * <p>Note the implementation should always inherit the passed-in attributes using {@code 38 * Attributes.newBuilder(transportAttrs)}, instead of creating one from scratch. 39 * 40 * @param transportAttrs current transport attributes 41 * 42 * @return new transport attributes. Default implementation returns the passed-in attributes 43 * intact. 44 */ transportReady(Attributes transportAttrs)45 public Attributes transportReady(Attributes transportAttrs) { 46 return transportAttrs; 47 } 48 49 /** 50 * Called when a transport is terminated. Default implementation is no-op. 51 * 52 * @param transportAttrs the effective transport attributes, which is what returned by {@link 53 * #transportReady} of the last executed filter. 54 */ transportTerminated(Attributes transportAttrs)55 public void transportTerminated(Attributes transportAttrs) { 56 } 57 } 58