Top Description Constructors Methods
io.smallrye.common.vertx

public Class ContextLocals

extends Object
Class Inheritance
Imports
java.util.Optional, io.smallrye.common.constraint.Assert, io.vertx.core.Context, .Vertx

Utilities to access Vert.x Context locals.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Context
public static <
the expected type of the associated value
T
>
Optional<T>

Returns:

an optional containing the associated value if any, empty otherwise.
get
(String
the key, must not be null
key
)

Gets the value from the context local associated with the given key.

public static <
the expected type of the associated value
T
>
T

Returns:

the associated value if any, the given default otherwise.
get
(String
the key, must not be null
key
,
T
the default value returned if there is no associated value with the given key. Can be null
def
)

Gets the value from the context local associated with the given key.

public static <
the expected type of the associated value
T
>
void
put(String
the key, must not be null
key
,
T
the value, must not be null
value
)

Stores the given key/value in the context local.

public static boolean

Returns:

true if there were a value associated with the given key. false otherwise.
remove
(String
the key, must not be null
key
)

Removes the value associated with the given key from the context locals.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ContextLocalsback to summary
private ContextLocals()

Method Detail

ensureDuplicatedContextback to summary
private static Context ensureDuplicatedContext()
getback to summary
public static <T> Optional<T> get(String key)

Gets the value from the context local associated with the given key.

Parameters
<T>
the expected type of the associated value
key:String

the key, must not be null

Returns:Optional<T>

an optional containing the associated value if any, empty otherwise.

getback to summary
public static <T> T get(String key, T def)

Gets the value from the context local associated with the given key. If there is no associated value, it returns the given default.

Parameters
<T>
the expected type of the associated value
key:String

the key, must not be null

def:T

the default value returned if there is no associated value with the given key. Can be null

Returns:T

the associated value if any, the given default otherwise.

putback to summary
public static <T> void put(String key, T value)

Stores the given key/value in the context local. This method overwrite the existing value if any.

Parameters
<T>
the expected type of the associated value
key:String

the key, must not be null

value:T

the value, must not be null

removeback to summary
public static boolean remove(String key)

Removes the value associated with the given key from the context locals.

Parameters
key:String

the key, must not be null

Returns:boolean

true if there were a value associated with the given key. false otherwise.