1 /* 2 * Copyright 2017, OpenCensus 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.opencensus.trace.propagation; 18 19 import io.opencensus.common.ExperimentalApi; 20 21 /** 22 * Container class for all the supported propagation formats. Currently supports only Binary format 23 * (see {@link BinaryFormat}) and B3 Text format (see {@link TextFormat}) but more formats will be 24 * added. 25 * 26 * @since 0.5 27 */ 28 public abstract class PropagationComponent { 29 private static final PropagationComponent NOOP_PROPAGATION_COMPONENT = 30 new NoopPropagationComponent(); 31 32 /** 33 * Returns the {@link BinaryFormat} with the provided implementations. If no implementation is 34 * provided then no-op implementation will be used. 35 * 36 * @return the {@code BinaryFormat} implementation. 37 * @since 0.5 38 */ getBinaryFormat()39 public abstract BinaryFormat getBinaryFormat(); 40 41 /** 42 * Returns the B3 {@link TextFormat} with the provided implementations. See <a 43 * href="https://github.com/openzipkin/b3-propagation">b3-propagation</a> for more information. If 44 * no implementation is provided then no-op implementation will be used. 45 * 46 * @since 0.11.0 47 * @return the B3 {@code TextFormat} implementation for B3. 48 */ 49 @ExperimentalApi getB3Format()50 public abstract TextFormat getB3Format(); 51 52 /** 53 * Returns an instance that contains no-op implementations for all the instances. 54 * 55 * @return an instance that contains no-op implementations for all the instances. 56 * @since 0.5 57 */ getNoopPropagationComponent()58 public static PropagationComponent getNoopPropagationComponent() { 59 return NOOP_PROPAGATION_COMPONENT; 60 } 61 62 private static final class NoopPropagationComponent extends PropagationComponent { 63 @Override getBinaryFormat()64 public BinaryFormat getBinaryFormat() { 65 return BinaryFormat.getNoopBinaryFormat(); 66 } 67 68 @Override getB3Format()69 public TextFormat getB3Format() { 70 return TextFormat.getNoopTextFormat(); 71 } 72 } 73 } 74