• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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 package com.google.android.libraries.mobiledatadownload.tracing;
17 
18 import com.google.common.base.Function;
19 import com.google.common.util.concurrent.AsyncCallable;
20 import com.google.common.util.concurrent.AsyncFunction;
21 import com.google.common.util.concurrent.ClosingFuture.ClosingFunction;
22 import com.google.common.util.concurrent.FutureCallback;
23 import com.google.errorprone.annotations.CheckReturnValue;
24 import java.util.concurrent.Callable;
25 
26 /**
27  * Contains decorators for propagating the current trace into a callback. When the wrapped callback
28  * runs, it will run under the same trace the wrapper was created in.
29  */
30 @CheckReturnValue
31 public final class TracePropagation {
32 
33   @CheckReturnValue
propagateAsyncCallable(final AsyncCallable<V> asyncCallable)34   public static <V> AsyncCallable<V> propagateAsyncCallable(final AsyncCallable<V> asyncCallable) {
35     return asyncCallable;
36   }
37 
38   @CheckReturnValue
propagateAsyncFunction( final AsyncFunction<I, O> function)39   public static <I, O> AsyncFunction<I, O> propagateAsyncFunction(
40       final AsyncFunction<I, O> function) {
41     return function;
42   }
43 
44   @CheckReturnValue
propagateCallable(final Callable<V> callable)45   public static <V> Callable<V> propagateCallable(final Callable<V> callable) {
46     return callable;
47   }
48 
49   @CheckReturnValue
propagateFunction(final Function<I, O> function)50   public static <I, O> Function<I, O> propagateFunction(final Function<I, O> function) {
51     return function;
52   }
53 
54   @CheckReturnValue
propagateFutureCallback(final FutureCallback<T> callback)55   public static <T> FutureCallback<T> propagateFutureCallback(final FutureCallback<T> callback) {
56     return callback;
57   }
58 
propagateClosingFunction( final ClosingFunction<I, O> closingFunction)59   public static <I, O> ClosingFunction<I, O> propagateClosingFunction(
60       final ClosingFunction<I, O> closingFunction) {
61     return closingFunction;
62   }
63 
64   @CheckReturnValue
propagateRunnable(Runnable runnable)65   public static Runnable propagateRunnable(Runnable runnable) {
66     return runnable;
67   }
68 
TracePropagation()69   private TracePropagation() {}
70 }
71