InvocationLocal

public class InvocationLocal
extends Object

java.lang.Object
   ↳ com.android.tradefed.invoker.logger.InvocationLocal<T>


This class provides invocation-scope variables.

The mechanism operates similarly to ThreadLocal. These variables differ from their normal counterparts in that code in an invocation that accesses one (via its get method) has its own, independently initialized copy of the variable. InvocationLocal instances are typically private static fields in classes that wish to associate state with an invocation.

Each invocation is associated with a copy of an invocation-scoped variable as long as the invocation is in progress and the InvocationLocal instance is accessible. After an invocation is complete, all of its copies of invocation-local instances are subject to garbage collection (unless other references to these copies exist).

Note that unlike ThreadLocal instances that are no longer referenced while the invocation is still in progress are not garbage collected. Creating local or non-static instances is therefore not recommended as they could grow without bound.

Warning: Use this class sparingly as invocation-locals are glorified global variables with many of the same pitfalls.

Summary

Public constructors

InvocationLocal()

Public methods

final T get()

Returns the currently-executing invocation's copy of this invocation-local variable.

Protected methods

T initialValue()

Returns the current invocation's "initial value" for this invocation-local variable.

Public constructors

InvocationLocal

public InvocationLocal ()

Public methods

get

public final T get ()

Returns the currently-executing invocation's copy of this invocation-local variable. If the variable has no value for the current invocation, it is first initialized to the value returned by a call to the initialValue() method.

Returns
T the currently executing invocation's copy of this invocation-local.

Protected methods

initialValue

protected T initialValue ()

Returns the current invocation's "initial value" for this invocation-local variable. This method will be invoked the first time code executing in the context of the invocation accesses the variable with the get() method. This method is guaranteed to be invoked at most once per invocation.

This implementation simply returns null but can be changed by sub-classing InvocationLocal and overriding this method.

Returns
T the initial value for this invocation-scoped variable