TracePropagatingExecutorService

public final class TracePropagatingExecutorService
extends Object implements ExecutorService

java.lang.Object
   ↳ com.android.tradefed.invoker.tracing.TracePropagatingExecutorService


An executor service that forwards tasks to an underlying implementation while propagating the tracing context.

This enables using tracing facilities such as CloseableTraceScope in submitted tasks.

Summary

Public methods

boolean awaitTermination(long timeout, TimeUnit unit)
static TracePropagatingExecutorService create(ExecutorService delegate)

Creates an ExecutorService that delegates to the given delegate executor.

void execute(Runnable command)
<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
<T> T invokeAny(Collection<? extends Callable<T>> tasks)
<T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
boolean isShutdown()
boolean isTerminated()
void shutdown()
List<Runnable> shutdownNow()
Future<?> submit(Runnable task)
<T> Future<T> submit(Callable<T> task)
<T> Future<T> submit(Runnable task, T result)

Protected methods

<T> Collection<? extends Callable<T>> wrapTasks(Collection<? extends Callable<T>> tasks)

Public methods

awaitTermination

public boolean awaitTermination (long timeout, 
                TimeUnit unit)

Parameters
timeout long

unit TimeUnit

Returns
boolean

Throws
InterruptedException

create

public static TracePropagatingExecutorService create (ExecutorService delegate)

Creates an ExecutorService that delegates to the given delegate executor.

Note that the active trace on is that is propagated to tasks is the one active on calls to the executor method. This is done because TF constructs most objects before starting the invocation and attaching the trace.

Parameters
delegate ExecutorService

Returns
TracePropagatingExecutorService

execute

public void execute (Runnable command)

Parameters
command Runnable

invokeAll

public List<Future<T>> invokeAll (Collection<? extends Callable<T>> tasks)

Parameters
tasks Collection

Returns
List<Future<T>>

Throws
InterruptedException

invokeAll

public List<Future<T>> invokeAll (Collection<? extends Callable<T>> tasks, 
                long timeout, 
                TimeUnit unit)

Parameters
tasks Collection

timeout long

unit TimeUnit

Returns
List<Future<T>>

Throws
InterruptedException

invokeAny

public T invokeAny (Collection<? extends Callable<T>> tasks)

Parameters
tasks Collection

Returns
T

Throws
ExecutionException
InterruptedException

invokeAny

public T invokeAny (Collection<? extends Callable<T>> tasks, 
                long timeout, 
                TimeUnit unit)

Parameters
tasks Collection

timeout long

unit TimeUnit

Returns
T

Throws
ExecutionException
InterruptedException
TimeoutException

isShutdown

public boolean isShutdown ()

Returns
boolean

isTerminated

public boolean isTerminated ()

Returns
boolean

shutdown

public void shutdown ()

shutdownNow

public List<Runnable> shutdownNow ()

Returns
List<Runnable>

submit

public Future<?> submit (Runnable task)

Parameters
task Runnable

Returns
Future<?>

submit

public Future<T> submit (Callable<T> task)

Parameters
task Callable

Returns
Future<T>

submit

public Future<T> submit (Runnable task, 
                T result)

Parameters
task Runnable

result T

Returns
Future<T>

Protected methods

wrapTasks

protected Collection<? extends Callable<T>> wrapTasks (Collection<? extends Callable<T>> tasks)

Parameters
tasks Collection

Returns
Collection<? extends Callable<T>>