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.util.concurrent.AsyncCallable; 19 import com.google.common.util.concurrent.ExecutionSequencer; 20 import com.google.common.util.concurrent.ListenableFuture; 21 import java.util.concurrent.Callable; 22 import java.util.concurrent.Executor; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** Wrapper around {@link ExecutionSequencer} with trace propagation. */ 26 public final class PropagatedExecutionSequencer { 27 28 private final ExecutionSequencer executionSequencer = ExecutionSequencer.create(); 29 PropagatedExecutionSequencer()30 private PropagatedExecutionSequencer() {} 31 32 /** Creates a new instance. */ create()33 public static PropagatedExecutionSequencer create() { 34 return new PropagatedExecutionSequencer(); 35 } 36 37 /** See {@link ExecutionSequencer#submit(Callable, Executor)}. */ submit( Callable<T> callable, Executor executor)38 public <T extends @Nullable Object> ListenableFuture<T> submit( 39 Callable<T> callable, Executor executor) { 40 return executionSequencer.submit(callable, executor); 41 } 42 43 /** See {@link ExecutionSequencer#submitAsync(AsyncCallable, Executor)}. */ submitAsync( AsyncCallable<T> callable, Executor executor)44 public <T extends @Nullable Object> ListenableFuture<T> submitAsync( 45 AsyncCallable<T> callable, Executor executor) { 46 return executionSequencer.submitAsync(callable, executor); 47 } 48 } 49