Top Description Methods
io.vertx.core.spi.context.storage

public Interface ContextLocal<T>

Known Direct Implementers
io.vertx.core.impl.ContextLocalImpl
Imports
io.vertx.core.Context, io.vertx.core.impl.ContextInternal, .ContextLocalImpl, java.util.function.Function, .Supplier

A local storage for arbitrary data attached to a duplicated Context.

Local storage should be registered before creating a io.vertx.core.Vertx instance, once registered a local storage cannot be unregistered.

It is recommended to initialize local storage as static fields of a io.vertx.core.spi.VertxServiceProvider, since providers are discovered before the capture of known local storages.

Author
Julien Viet

Method Summary

Modifier and TypeMethod and Description
public default T

Returns:

the local data
get
(Context context)

Get the local data from the context.

public default T

Returns:

the local data
get
(Context context, Supplier<? extends T>
the supplier of the initial value
initialValueSupplier
)

Get the local data from the context, when it does not exist then call initialValueSupplier to obtain the initial value.

public default T
get(Context context, AccessMode accessMode)

Like get(Context) but with an accessMode.

public default T
get(Context context, AccessMode accessMode, Supplier<? extends T> initialValueSupplier)

Like get(Context, Supplier) but with an accessMode.

public default void
put(Context context, T
the data
data
)

Put local data in the context.

public default void
put(Context context, AccessMode accessMode, T value)

Like put(Context, T) but with an accessMode.

public static <T> ContextLocal<T>

Returns:

the context local storage
registerLocal
(Class<T> type)

Registers a context local storage.

public static <T> ContextLocal<T>

Returns:

the context local storage
registerLocal
(Class<T> type, Function<T, T> duplicator)

Registers a context local storage.

public default void
remove(Context context)

Remove the local data from the context.

public default void
remove(Context context, AccessMode accessMode)

Like remove(Context) but with an accessMode.

Method Detail

getback to summary
public default T get(Context context)

Get the local data from the context.

Returns:T

the local data

getback to summary
public default T get(Context context, Supplier<? extends T> initialValueSupplier)

Get the local data from the context, when it does not exist then call initialValueSupplier to obtain the initial value. The supplier can be called multiple times when several threads call this method concurrently.

Parameters
initialValueSupplier:Supplier<? extends T>

the supplier of the initial value

Returns:T

the local data

getback to summary
public default T get(Context context, AccessMode accessMode)

Like get(Context) but with an accessMode.

getback to summary
public default T get(Context context, AccessMode accessMode, Supplier<? extends T> initialValueSupplier)

Like get(Context, Supplier) but with an accessMode.

putback to summary
public default void put(Context context, T data)

Put local data in the context.

Parameters
data:T

the data

putback to summary
public default void put(Context context, AccessMode accessMode, T value)

Like put(Context, T) but with an accessMode.

registerLocalback to summary
public static <T> ContextLocal<T> registerLocal(Class<T> type)

Registers a context local storage.

Returns:ContextLocal<T>

the context local storage

registerLocalback to summary
public static <T> ContextLocal<T> registerLocal(Class<T> type, Function<T, T> duplicator)

Registers a context local storage.

Returns:ContextLocal<T>

the context local storage

removeback to summary
public default void remove(Context context)

Remove the local data from the context.

removeback to summary
public default void remove(Context context, AccessMode accessMode)

Like remove(Context) but with an accessMode.