Top Description Fields Methods
io.vertx.core.impl

public Interface ContextInternal

extends Context
Known Direct Implementers
io.vertx.core.impl.DuplicatedContext, io.vertx.core.impl.ContextImpl
Imports
io.netty.channel.EventLoop, io.vertx.core.*, .Future, io.vertx.core.impl.future.FailedFuture, .PromiseImpl, .PromiseInternal, .SucceededFuture, io.vertx.core.spi.context.storage.AccessMode, .ContextLocal, io.vertx.core.spi.tracing.VertxTracer, java.util.concurrent.*, java.util.function.Supplier

This interface provides an api for vert.x core internal use only It is not part of the public API and should not be used by developers creating vert.x applications
Author
Julien Viet

Field Summary

Modifier and TypeField and Description
public static final ContextLocal<ConcurrentMap<Object, Object>>

Method Summary

Modifier and TypeMethod and Description
public default void
addCloseHook(Closeable
the close hook
hook
)

Add a close hook.

public default ContextInternal

Returns:

the previous context that shall be restored after or null if there is none
beginDispatch
()

Begin the execution of a task on this context.

public ClassLoader

Returns:

the classloader associated with this context
classLoader
()

public Future<Void>

Returns:

a future signalling close completion
close
()

Close this context, cleanup close future hooks then dispose pending ordered task queue.

public CloseFuture
public ConcurrentMap<Object, Object>

Returns:

the ConcurrentMap used to store context data
contextData
()

public static ContextInternal

Returns:

the current context
current
()

public default String
deploymentID()

Implements io.vertx.core.Context.deploymentID.

If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment.

public default void
dispatch(Runnable handler)

public default void
dispatch(Handler<Void> handler)

public default <E> void
dispatch(E
the event for the handler
event
,
Handler<E>
the handler to execute with the event
handler
)

Dispatch an event to the handler on this context.

public ContextInternal

Returns:

a duplicate of this context
duplicate
()

Returns a context sharing with this context

  • the same concurrency
  • the same exception handler
  • the same context data
  • the same deployment
  • the same config
  • the same classloader
public <T> void
emit(T
the task argument
argument
,
Handler<T>
the handler to execute with the event argument
task
)

Emit the given argument event to the task and switch on this context if necessary, this also associates the current thread with the current context so Vertx#currentContext() returns this context.

public default void
emit(Handler<Void> task)

public default void
endDispatch(ContextInternal
the previous context to restore or null if there is none
previous
)

End the execution of a task on this context, see beginDispatch()

You should not use this API directly, instead you should use dispatch(Object, Handler)

public default void
public void
execute(Runnable
the task to execute
task
)

Execute the task on this context, it will be executed according to the context concurrency model.

public <T> void
execute(T
the task argument
argument
,
Handler<T>
the task to execute
task
)

Execute a task on this context, the task will be executed according to the context concurrency model.

public default <T> void
executeBlocking(Handler<Promise<T>> blockingCodeHandler, TaskQueue queue, Handler<AsyncResult<T>> resultHandler)
Deprecated instead use executeBlocking(Callable, TaskQueue)

Like executeBlocking(Handler, boolean, Handler) but uses the queue to order the tasks instead of the internal queue of this context.

public <T> Future<T>
executeBlocking(Handler<Promise<T>> blockingCodeHandler, TaskQueue queue)
Deprecated

Like executeBlocking(Handler, boolean) but uses the queue to order the tasks instead of the internal queue of this context.

public <T> Future<T>
executeBlocking(Callable<T> blockingCodeHandler, TaskQueue queue)

public default <T> void
executeBlocking(Handler<Promise<T>>
handler representing the blocking code to run
blockingCodeHandler
,
boolean
if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees
ordered
,
Handler<AsyncResult<T>>
handler that will be called when the blocking code is complete
resultHandler
)

Implements io.vertx.core.Context.executeBlocking.

Safely execute some blocking code.

public default <T> void
executeBlockingInternal(Handler<Promise<T>> action, Handler<AsyncResult<T>> resultHandler)
Deprecated

Execute an internal task on the internal blocking ordered executor.

public default <T> void
executeBlockingInternal(Handler<Promise<T>> action, boolean ordered, Handler<AsyncResult<T>> resultHandler)
Deprecated

public <T> Future<T>
executeBlockingInternal(Handler<Promise<T>> action)

Like executeBlockingInternal(Handler, Handler) but returns a Future of the asynchronous result

public <T> Future<T>
public <T> Future<T>
executeBlockingInternal(Handler<Promise<T>> action, boolean ordered)

Like executeBlockingInternal(Handler, boolean, Handler) but returns a Future of the asynchronous result

public <T> Future<T>
executeBlockingInternal(Callable<T> action, boolean ordered)

public Executor

Returns:

an executor that schedule a task on this context, the thread executing the task will not be associated with this context
executor
()

public default <T> Future<T>

Returns:

a Future failed with the failure associated with this context
failedFuture
(Throwable failure)

public default <T> Future<T>

Returns:

a Future failed with the message associated with this context
failedFuture
(String message)

public default <T> T
get(Object
the key of the data
key
)

Implements io.vertx.core.Context.get.

Get some data from the context.

public Deployment

Returns:

the deployment associated with this context or null
getDeployment
()

public default int
public default <
the type of the data
T
>
T

Returns:

the local data
getLocal
(ContextLocal<T>
the key of the data
key
)

Get some local data from the context.

public <
the type of the data
T
>
T

Returns:

the local data
getLocal
(ContextLocal<T>
the key of the data
key
,
AccessMode accessMode)

Get some local data from the context.

public <
the type of the data
T
>
T

Returns:

the local data
getLocal
(ContextLocal<T>
the key of the data
key
,
AccessMode accessMode, Supplier<? extends T>
the supplier of the initial value optionally called
initialValueSupplier
)

Get some local data from the context, when it does not exist the initialValueSupplier is called to obtain the initial value.

public default <T> T
getLocal(Object
the key of the data
key
)

Implements io.vertx.core.Context.getLocal.

Deprecated

Get some local data from the context.

public boolean
public default boolean

Returns:

true when the context is associated with a deployment
isDeployment
()

public default boolean

Returns:

true if this context is a duplicated context, false otherwise.
isDuplicate
()

Returns true if this context is a duplicated context.

public default boolean

Returns:

whether the current thread is running on this context
isRunningOnContext
()

public default ConcurrentMap<Object, Object>

Returns:

the ConcurrentMap used to store local context data
localContextData
()

public EventLoop

Returns:

the EventLoop
nettyEventLoop
()

Return the Netty EventLoop used by this Context.

public VertxInternal
public default <T> PromiseInternal<T>

Returns:

a Promise associated with this context
promise
()

public default <T> PromiseInternal<T>

Returns:

a Promise associated with this context or the handler if that handler is already an instance of PromiseInternal
promise
(Handler<AsyncResult<T>> handler)

public default void
put(Object
the key of the data
key
,
Object
the data
value
)

Implements io.vertx.core.Context.put.

Put some data in the context.

public <T> void
putLocal(ContextLocal<T>
the key of the data
key
,
AccessMode accessMode, T
the data
value
)

Put some local data in the context.

public default void
putLocal(Object
the key of the data
key
,
Object
the data
value
)

Implements io.vertx.core.Context.putLocal.

Deprecated

Put some local data in the context.

public default boolean
remove(Object
the key to remove
key
)

Implements io.vertx.core.Context.remove.

Remove some data from the context.

public default void
removeCloseHook(Closeable
the close hook
hook
)

Remove a close hook.

public default <T> void
removeLocal(ContextLocal<T>
the key to remove
key
,
AccessMode accessMode)

Remove some local data from the context.

public default boolean
removeLocal(Object
the key to remove
key
)

Implements io.vertx.core.Context.removeLocal.

Deprecated

Remove some local data from the context.

public void
reportException(Throwable
the exception to report
t
)

Report an exception to this context synchronously.

public default void
runOnContext(Handler<Void>
the action to run
action
)

Implements io.vertx.core.Context.runOnContext.

Run the specified action asynchronously on the same context, some time after the current execution has completed.

public default long
setPeriodic(long delay, Handler<Long> handler)

Like Vertx#setPeriodic(long, Handler) except the periodic timer will fire on this context and the timer will not be associated with the context close hook.

public default long
setTimer(long delay, Handler<Long> handler)

Like Vertx#setTimer(long, Handler) except the timer will fire on this context and the timer will not be associated with the context close hook.

public default <T> Future<T>

Returns:

an empty succeeded Future associated with this context
succeededFuture
()

public default <T> Future<T>

Returns:

a succeeded Future of the result associated with this context
succeededFuture
(T result)

public VertxTracer<I, O>

Returns:

the tracer for this context
tracer
()

public default ContextInternal

Returns:

the wrapped context
unwrap
()

Returns the original context, a duplicate context returns the wrapped context otherwise this instance is returned.

public WorkerPool

Returns:

the context worker pool
workerPool
()

Inherited from io.vertx.core.Context:
configexceptionHandlerexceptionHandlerexecuteBlockingexecuteBlockingexecuteBlockingexecuteBlockingexecuteBlockingexecuteBlockingexecuteBlockingisEventLoopContextisOnEventLoopThreadisOnVertxThreadisOnWorkerThreadisWorkerContextprocessArgsthreadingModel

Field Detail

LOCAL_MAPback to summary
public static final ContextLocal<ConcurrentMap<Object, Object>> LOCAL_MAP

Method Detail

addCloseHookback to summary
public default void addCloseHook(Closeable hook)

Add a close hook.

The hook will be called when the associated resource needs to be released. Hooks are useful for automatically cleanup resources when a Verticle is undeployed.

Parameters
hook:Closeable

the close hook

beginDispatchback to summary
public default ContextInternal beginDispatch()

Begin the execution of a task on this context.

The task execution is monitored by the blocked thread checker.

This context is thread-local associated during the task execution.

You should not use this API directly, instead you should use dispatch(Object, Handler)

Returns:ContextInternal

the previous context that shall be restored after or null if there is none

Exceptions
IllegalStateException:
when the current thread of execution cannot execute this task
classLoaderback to summary
public ClassLoader classLoader()
Returns:ClassLoader

the classloader associated with this context

closeback to summary
public Future<Void> close()

Close this context, cleanup close future hooks then dispose pending ordered task queue.

Returns:Future<Void>

a future signalling close completion

closeFutureback to summary
public CloseFuture closeFuture()
contextDataback to summary
public ConcurrentMap<Object, Object> contextData()
Returns:ConcurrentMap<Object, Object>

the ConcurrentMap used to store context data

See Also
Context#get(Object), Context#put(Object, Object)
currentback to summary
public static ContextInternal current()
Returns:ContextInternal

the current context

deploymentIDback to summary
public default String deploymentID()

Implements io.vertx.core.Context.deploymentID.

Doc from io.vertx.core.Context.deploymentID.

If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment.

Returns:String

the deployment ID of the deployment or null if not a Verticle deployment

dispatchback to summary
public default void dispatch(Runnable handler)
See Also
dispatch(Handler)
dispatchback to summary
public default void dispatch(Handler<Void> handler)
See Also
dispatch(Object, Handler)
dispatchback to summary
public default <E> void dispatch(E event, Handler<E> handler)

Dispatch an event to the handler on this context.

The handler is executed directly by the caller thread which must be a context thread.

The handler execution is monitored by the blocked thread checker.

This context is thread-local associated during the task execution.

Parameters
event:E

the event for the handler

handler:Handler<E>

the handler to execute with the event

duplicateback to summary
public ContextInternal duplicate()

Returns a context sharing with this context

  • the same concurrency
  • the same exception handler
  • the same context data
  • the same deployment
  • the same config
  • the same classloader

The duplicate context has its own

  • local context data
  • worker task queue
Returns:ContextInternal

a duplicate of this context

emitback to summary
public <T> void emit(T argument, Handler<T> task)

Emit the given argument event to the task and switch on this context if necessary, this also associates the current thread with the current context so Vertx#currentContext() returns this context.
Any exception thrown from the task will be reported on this context.
Calling this method is equivalent to execute(v -> dispatch(argument, task))

Parameters
argument:T

the task argument

task:Handler<T>

the handler to execute with the event argument

emitback to summary
public default void emit(Handler<Void> task)
See Also
emit(Object, Handler)
endDispatchback to summary
public default void endDispatch(ContextInternal previous)

End the execution of a task on this context, see beginDispatch()

You should not use this API directly, instead you should use dispatch(Object, Handler)

Parameters
previous:ContextInternal

the previous context to restore or null if there is none

Exceptions
IllegalStateException:
when the current thread of execution cannot execute this task
executeback to summary
public default void execute(Handler<Void> task)
See Also
execute(Object, Handler)
executeback to summary
public void execute(Runnable task)

Execute the task on this context, it will be executed according to the context concurrency model.

Parameters
task:Runnable

the task to execute

executeback to summary
public <T> void execute(T argument, Handler<T> task)

Execute a task on this context, the task will be executed according to the context concurrency model.

Parameters
argument:T

the task argument

task:Handler<T>

the task to execute

executeBlockingback to summary
public default <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, TaskQueue queue, Handler<AsyncResult<T>> resultHandler)

Deprecated

instead use executeBlocking(Callable, TaskQueue)

Like executeBlocking(Handler, boolean, Handler) but uses the queue to order the tasks instead of the internal queue of this context.

Annotations
@Deprecated
executeBlockingback to summary
public <T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler, TaskQueue queue)

Deprecated

Like executeBlocking(Handler, boolean) but uses the queue to order the tasks instead of the internal queue of this context.

Annotations
@Deprecated
executeBlockingback to summary
public <T> Future<T> executeBlocking(Callable<T> blockingCodeHandler, TaskQueue queue)
executeBlockingback to summary
public default <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)

Implements io.vertx.core.Context.executeBlocking.

Doc from io.vertx.core.Context.executeBlocking.

Safely execute some blocking code.

Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.

The returned future will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.

A Future instance is passed into blockingCodeHandler. When the blocking code successfully completes, the handler should call the Promise#complete or Promise#complete(Object) method, or the Promise#fail method if it failed.

The blocking code should block for a reasonable amount of time (i.e no more than a few seconds). Long blocking operations or polling operations (i.e a thread that spin in a loop polling events in a blocking fashion) are precluded.

When the blocking operation lasts more than the 10 seconds, a message will be printed on the console by the blocked thread checker.

Long blocking operations should use a dedicated thread managed by the application, which can interact with verticles using the event-bus or Context#runOnContext(Handler)

Parameters
<T>
the type of the result
blockingCodeHandler:Handler<Promise<T>>

handler representing the blocking code to run

ordered:boolean

if true then if executeBlocking is called several times on the same context, the executions for that context will be executed serially, not in parallel. if false then they will be no ordering guarantees

resultHandler:Handler<AsyncResult<T>>

handler that will be called when the blocking code is complete

Annotations
@Override
executeBlockingInternalback to summary
public default <T> void executeBlockingInternal(Handler<Promise<T>> action, Handler<AsyncResult<T>> resultHandler)

Deprecated

Execute an internal task on the internal blocking ordered executor.

Annotations
@Deprecated
executeBlockingInternalback to summary
public default <T> void executeBlockingInternal(Handler<Promise<T>> action, boolean ordered, Handler<AsyncResult<T>> resultHandler)

Deprecated

Annotations
@Deprecated
executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Handler<Promise<T>> action)

Like executeBlockingInternal(Handler, Handler) but returns a Future of the asynchronous result

executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Callable<T> action)
executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Handler<Promise<T>> action, boolean ordered)

Like executeBlockingInternal(Handler, boolean, Handler) but returns a Future of the asynchronous result

executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Callable<T> action, boolean ordered)
executorback to summary
public Executor executor()
Returns:Executor

an executor that schedule a task on this context, the thread executing the task will not be associated with this context

failedFutureback to summary
public default <T> Future<T> failedFuture(Throwable failure)
Returns:Future<T>

a Future failed with the failure associated with this context

failedFutureback to summary
public default <T> Future<T> failedFuture(String message)
Returns:Future<T>

a Future failed with the message associated with this context

getback to summary
public default <T> T get(Object key)

Implements io.vertx.core.Context.get.

Doc from io.vertx.core.Context.get.

Get some data from the context.

Parameters
<T>
the type of the data
key:Object

the key of the data

Returns:T

the data

Annotations
@SuppressWarnings:unchecked
@Override
getDeploymentback to summary
public Deployment getDeployment()
Returns:Deployment

the deployment associated with this context or null

getInstanceCountback to summary
public default int getInstanceCount()

Implements io.vertx.core.Context.getInstanceCount.

Returns:int

Doc from io.vertx.core.Context.getInstanceCount.

the number of instances of the verticle that were deployed in the deployment (if any) related to this context

getLocalback to summary
public default <T> T getLocal(ContextLocal<T> key)

Get some local data from the context.

Parameters
<T>
the type of the data
key:ContextLocal<T>

the key of the data

Returns:T

the local data

getLocalback to summary
public <T> T getLocal(ContextLocal<T> key, AccessMode accessMode)

Get some local data from the context.

Parameters
<T>
the type of the data
key:ContextLocal<T>

the key of the data

Returns:T

the local data

getLocalback to summary
public <T> T getLocal(ContextLocal<T> key, AccessMode accessMode, Supplier<? extends T> initialValueSupplier)

Get some local data from the context, when it does not exist the initialValueSupplier is called to obtain the initial value.

The initialValueSupplier might be called multiple times when multiple threads call this method concurrently.

Parameters
<T>
the type of the data
key:ContextLocal<T>

the key of the data

initialValueSupplier:Supplier<? extends T>

the supplier of the initial value optionally called

Returns:T

the local data

getLocalback to summary
public default <T> T getLocal(Object key)

Implements io.vertx.core.Context.getLocal.

Doc from io.vertx.core.Context.getLocal.

Deprecated

Get some local data from the context.

Parameters
<T>
the type of the data
key:Object

the key of the data

Returns:T

the data

Annotations
@Deprecated
@SuppressWarnings:unchecked
@Override
inThreadback to summary
public boolean inThread()
isDeploymentback to summary
public default boolean isDeployment()
Returns:boolean

true when the context is associated with a deployment

isDuplicateback to summary
public default boolean isDuplicate()

Returns true if this context is a duplicated context.

Returns:boolean

true if this context is a duplicated context, false otherwise.

isRunningOnContextback to summary
public default boolean isRunningOnContext()
Returns:boolean

whether the current thread is running on this context

localContextDataback to summary
public default ConcurrentMap<Object, Object> localContextData()
Returns:ConcurrentMap<Object, Object>

the ConcurrentMap used to store local context data

nettyEventLoopback to summary
public EventLoop nettyEventLoop()

Return the Netty EventLoop used by this Context. This can be used to integrate a Netty Server with a Vert.x runtime, specially the Context part.

Returns:EventLoop

the EventLoop

ownerback to summary
public VertxInternal owner()

Redeclares io.vertx.core.Context.owner.

Returns:VertxInternal

Doc from io.vertx.core.Context.owner.

The Vertx instance that created the context

Annotations
@Override
promiseback to summary
public default <T> PromiseInternal<T> promise()
Returns:PromiseInternal<T>

a Promise associated with this context

promiseback to summary
public default <T> PromiseInternal<T> promise(Handler<AsyncResult<T>> handler)
Returns:PromiseInternal<T>

a Promise associated with this context or the handler if that handler is already an instance of PromiseInternal

putback to summary
public default void put(Object key, Object value)

Implements io.vertx.core.Context.put.

Doc from io.vertx.core.Context.put.

Put some data in the context.

This can be used to share data between different handlers that share a context

Parameters
key:Object

the key of the data

value:Object

the data

Annotations
@Override
putLocalback to summary
public <T> void putLocal(ContextLocal<T> key, AccessMode accessMode, T value)

Put some local data in the context.

This can be used to share data between different handlers that share a context

Parameters
key:ContextLocal<T>

the key of the data

value:T

the data

putLocalback to summary
public default void putLocal(Object key, Object value)

Implements io.vertx.core.Context.putLocal.

Doc from io.vertx.core.Context.putLocal.

Deprecated

Put some local data in the context.

This can be used to share data between different handlers that share a context

Parameters
key:Object

the key of the data

value:Object

the data

Annotations
@Deprecated
@Override
removeback to summary
public default boolean remove(Object key)

Implements io.vertx.core.Context.remove.

Doc from io.vertx.core.Context.remove.

Remove some data from the context.

Parameters
key:Object

the key to remove

Returns:boolean

true if removed successfully, false otherwise

Annotations
@Override
removeCloseHookback to summary
public default void removeCloseHook(Closeable hook)

Remove a close hook.

This is called when the resource is released explicitly and does not need anymore a managed close.

Parameters
hook:Closeable

the close hook

removeLocalback to summary
public default <T> void removeLocal(ContextLocal<T> key, AccessMode accessMode)

Remove some local data from the context.

Parameters
key:ContextLocal<T>

the key to remove

removeLocalback to summary
public default boolean removeLocal(Object key)

Implements io.vertx.core.Context.removeLocal.

Doc from io.vertx.core.Context.removeLocal.

Deprecated

Remove some local data from the context.

Parameters
key:Object

the key to remove

Returns:boolean

true if removed successfully, false otherwise

Annotations
@Deprecated
@Override
reportExceptionback to summary
public void reportException(Throwable t)

Report an exception to this context synchronously.

The exception handler will be called when there is one, otherwise the exception will be logged.

Parameters
t:Throwable

the exception to report

runOnContextback to summary
public default void runOnContext(Handler<Void> action)

Implements io.vertx.core.Context.runOnContext.

Doc from io.vertx.core.Context.runOnContext.

Run the specified action asynchronously on the same context, some time after the current execution has completed.

Parameters
action:Handler<Void>

the action to run

Annotations
@Override
setPeriodicback to summary
public default long setPeriodic(long delay, Handler<Long> handler)

Like Vertx#setPeriodic(long, Handler) except the periodic timer will fire on this context and the timer will not be associated with the context close hook.

setTimerback to summary
public default long setTimer(long delay, Handler<Long> handler)

Like Vertx#setTimer(long, Handler) except the timer will fire on this context and the timer will not be associated with the context close hook.

succeededFutureback to summary
public default <T> Future<T> succeededFuture()
Returns:Future<T>

an empty succeeded Future associated with this context

succeededFutureback to summary
public default <T> Future<T> succeededFuture(T result)
Returns:Future<T>

a succeeded Future of the result associated with this context

tracerback to summary
public VertxTracer<I, O> tracer()
Returns:VertxTracer<I, O>

the tracer for this context

unwrapback to summary
public default ContextInternal unwrap()

Returns the original context, a duplicate context returns the wrapped context otherwise this instance is returned.

Returns:ContextInternal

the wrapped context

workerPoolback to summary
public WorkerPool workerPool()
Returns:WorkerPool

the context worker pool