Top Description Fields Constructors Methods
io.vertx.core.impl

public final Class ContextImpl

extends ContextBase
implements ContextInternal
Class Inheritance
All Implemented Interfaces
io.vertx.core.impl.ContextInternal, io.vertx.core.Context
Imports
io.netty.channel.EventLoop, io.vertx.core.*, .Future, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.json.JsonObject, io.vertx.core.spi.metrics.PoolMetrics, io.vertx.core.spi.tracing.VertxTracer, java.util.concurrent.*

A base class for Context implementations.
Authors
Tim Fox, Julien Viet

Field Summary

Modifier and TypeField and Description
private final CloseFuture
private final JsonObject
config

References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.
private ConcurrentMap<Object, Object>
private final Deployment
pack-priv static final boolean
private static final String
private final EventLoop
private volatile Handler<Throwable>
pack-priv final WorkerTaskQueue
private final EventExecutor
pack-priv final TaskQueue
pack-priv final WorkerPool
private static final Logger
private final VertxImpl
private final ClassLoader
private final ThreadingModel
pack-priv final WorkerPool
Inherited from io.vertx.core.impl.ContextBase:
localsLength

Constructor Summary

AccessConstructor and Description
public
ContextImpl(VertxImpl vertx, int localsLength, ThreadingModel threadingModel, EventLoop eventLoop, EventExecutor executor, WorkerPool internalWorkerPool, WorkerPool workerPool, Deployment deployment, CloseFuture closeFuture, ClassLoader tccl)

Method Summary

Modifier and TypeMethod and Description
public ClassLoader
public Future<Void>
close()

Implements io.vertx.core.impl.ContextInternal.close.

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

public CloseFuture
public JsonObject
config()

Implements io.vertx.core.Context.config.

References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

If the context is associated with a Verticle deployment, this returns the configuration that was specified when the verticle was deployed.

public synchronized ConcurrentMap<Object, Object>
public ContextInternal
duplicate()

Implements io.vertx.core.impl.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
public <T> void
emit(T
the task argument
argument
,
Handler<T>
the handler to execute with the event argument
task
)

Implements io.vertx.core.impl.ContextInternal.emit.

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.

protected <T> void
emit(ContextInternal ctx, T argument, Handler<T> task)

public Context
public Handler<Throwable>
public void
execute(Runnable
the task to execute
task
)

Implements io.vertx.core.impl.ContextInternal.execute.

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

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

Implements io.vertx.core.impl.ContextInternal.execute.

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

protected void
protected <T> void
execute(ContextInternal ctx, T argument, Handler<T> task)

  • When the current thread is event-loop thread of this context the implementation will execute the task directly
  • When the current thread is a worker thread of this context the implementation will execute the task directly
  • Otherwise the task will be scheduled on the context thread for execution
public <T> Future<T>
executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)

Implements io.vertx.core.Context.executeBlocking.

Same as executeBlocking(Handler, boolean, Handler) but with an handler called when the operation completes

public <T> Future<T>
executeBlocking(Callable<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
)

Implements io.vertx.core.Context.executeBlocking.

Safely execute some blocking code.

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

Implements io.vertx.core.impl.ContextInternal.executeBlocking.

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

public <T> Future<T>
pack-priv static <T> Future<T>
executeBlocking(ContextInternal context, Callable<T> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)

pack-priv static <T> Future<T>
executeBlocking(ContextInternal context, Handler<Promise<T>> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)

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

Implements io.vertx.core.impl.ContextInternal.executeBlockingInternal.

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

public <T> Future<T>
public EventExecutor
public Deployment
private static <T> Future<T>
internalExecuteBlocking(ContextInternal context, Handler<Promise<T>> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)

public boolean
public boolean
isEventLoopContext()

Implements io.vertx.core.Context.isEventLoopContext.

Is the current context an event loop context?

public boolean
isWorkerContext()

Implements io.vertx.core.Context.isWorkerContext.

Is the current context a worker context?

public EventLoop
nettyEventLoop()

Implements io.vertx.core.impl.ContextInternal.nettyEventLoop.

Return the Netty EventLoop used by this Context.

public VertxImpl
public void
reportException(Throwable
the exception to report
t
)

Implements io.vertx.core.impl.ContextInternal.reportException.

Report an exception to this context synchronously.

protected void
pack-priv static <T> void
setResultHandler(ContextInternal ctx, Future<T> fut, Handler<AsyncResult<T>> resultHandler)

public ThreadingModel
public VertxTracer<I, O>
public WorkerPool
Inherited from io.vertx.core.impl.ContextBase:
getLocalgetLocalputLocal

Field Detail

closeFutureback to summary
private final CloseFuture closeFuture
configback to summary
private final JsonObject config

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

databack to summary
private ConcurrentMap<Object, Object> data
deploymentback to summary
private final Deployment deployment
DISABLE_TIMINGSback to summary
pack-priv static final boolean DISABLE_TIMINGS
DISABLE_TIMINGS_PROP_NAMEback to summary
private static final String DISABLE_TIMINGS_PROP_NAME
eventLoopback to summary
private final EventLoop eventLoop
exceptionHandlerback to summary
private volatile Handler<Throwable> exceptionHandler
executeBlockingTasksback to summary
pack-priv final WorkerTaskQueue executeBlockingTasks
executorback to summary
private final EventExecutor executor
internalOrderedTasksback to summary
pack-priv final TaskQueue internalOrderedTasks
internalWorkerPoolback to summary
pack-priv final WorkerPool internalWorkerPool
logback to summary
private static final Logger log
ownerback to summary
private final VertxImpl owner
tcclback to summary
private final ClassLoader tccl
threadingModelback to summary
private final ThreadingModel threadingModel
workerPoolback to summary
pack-priv final WorkerPool workerPool

Constructor Detail

ContextImplback to summary
public ContextImpl(VertxImpl vertx, int localsLength, ThreadingModel threadingModel, EventLoop eventLoop, EventExecutor executor, WorkerPool internalWorkerPool, WorkerPool workerPool, Deployment deployment, CloseFuture closeFuture, ClassLoader tccl)

Method Detail

classLoaderback to summary
public ClassLoader classLoader()

Implements io.vertx.core.impl.ContextInternal.classLoader.

Returns:ClassLoader

Doc from io.vertx.core.impl.ContextInternal.classLoader.

the classloader associated with this context

Annotations
@Override
closeback to summary
public Future<Void> close()

Implements io.vertx.core.impl.ContextInternal.close.

Doc from io.vertx.core.impl.ContextInternal.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()

Implements io.vertx.core.impl.ContextInternal.closeFuture.

Annotations
@Override
configback to summary
public JsonObject config()

Implements io.vertx.core.Context.config.

Doc from io.vertx.core.Context.config.

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

If the context is associated with a Verticle deployment, this returns the configuration that was specified when the verticle was deployed.

Returns:JsonObject

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

Annotations
@Override
contextDataback to summary
public synchronized ConcurrentMap<Object, Object> contextData()

Implements io.vertx.core.impl.ContextInternal.contextData.

Returns:ConcurrentMap<Object, Object>

Doc from io.vertx.core.impl.ContextInternal.contextData.

the ConcurrentMap used to store context data

Annotations
@Override
duplicateback to summary
public ContextInternal duplicate()

Implements io.vertx.core.impl.ContextInternal.duplicate.

Doc from io.vertx.core.impl.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

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

Implements io.vertx.core.impl.ContextInternal.emit.

Doc from io.vertx.core.impl.ContextInternal.emit.

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

Annotations
@Override
emitback to summary
protected <T> void emit(ContextInternal ctx, T argument, Handler<T> task)
exceptionHandlerback to summary
public Context exceptionHandler(Handler<Throwable> handler)
Annotations
@Override
exceptionHandlerback to summary
public Handler<Throwable> exceptionHandler()

Implements io.vertx.core.Context.exceptionHandler.

Returns:Handler<Throwable>

Doc from io.vertx.core.Context.exceptionHandler.

the current exception handler of this context

Annotations
@Override
executeback to summary
public void execute(Runnable task)

Implements io.vertx.core.impl.ContextInternal.execute.

Doc from io.vertx.core.impl.ContextInternal.execute.

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

Parameters
task:Runnable

the task to execute

Annotations
@Override
executeback to summary
public final <T> void execute(T argument, Handler<T> task)

Implements io.vertx.core.impl.ContextInternal.execute.

Doc from io.vertx.core.impl.ContextInternal.execute.

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

Annotations
@Override
executeback to summary
protected void execute(ContextInternal ctx, Runnable task)
executeback to summary
protected <T> void execute(ContextInternal ctx, T argument, Handler<T> task)

  • When the current thread is event-loop thread of this context the implementation will execute the task directly
  • When the current thread is a worker thread of this context the implementation will execute the task directly
  • Otherwise the task will be scheduled on the context thread for execution
executeBlockingback to summary
public <T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)

Implements io.vertx.core.Context.executeBlocking.

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

Same as executeBlocking(Handler, boolean, Handler) but with an handler called when the operation completes

Annotations
@Override
executeBlockingback to summary
public <T> Future<T> executeBlocking(Callable<T> blockingCodeHandler, boolean ordered)

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.

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:Callable<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

Returns:Future<T>

a future completed when the blocking code is complete

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

Implements io.vertx.core.impl.ContextInternal.executeBlocking.

Doc from io.vertx.core.impl.ContextInternal.executeBlocking.

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

Annotations
@Override
executeBlockingback to summary
public <T> Future<T> executeBlocking(Callable<T> blockingCodeHandler, TaskQueue queue)

Implements io.vertx.core.impl.ContextInternal.executeBlocking.

Annotations
@Override
executeBlockingback to summary
pack-priv static <T> Future<T> executeBlocking(ContextInternal context, Callable<T> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)
executeBlockingback to summary
pack-priv static <T> Future<T> executeBlocking(ContextInternal context, Handler<Promise<T>> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)
executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Handler<Promise<T>> action)

Implements io.vertx.core.impl.ContextInternal.executeBlockingInternal.

Doc from io.vertx.core.impl.ContextInternal.executeBlockingInternal.

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

Annotations
@Override
executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Callable<T> action)

Implements io.vertx.core.impl.ContextInternal.executeBlockingInternal.

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

Implements io.vertx.core.impl.ContextInternal.executeBlockingInternal.

Doc from io.vertx.core.impl.ContextInternal.executeBlockingInternal.

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

Annotations
@Override
executeBlockingInternalback to summary
public <T> Future<T> executeBlockingInternal(Callable<T> action, boolean ordered)

Implements io.vertx.core.impl.ContextInternal.executeBlockingInternal.

Annotations
@Override
executorback to summary
public EventExecutor executor()

Implements io.vertx.core.impl.ContextInternal.executor.

Returns:EventExecutor

Doc from io.vertx.core.impl.ContextInternal.executor.

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

Annotations
@Override
getDeploymentback to summary
public Deployment getDeployment()

Implements io.vertx.core.impl.ContextInternal.getDeployment.

Returns:Deployment

Doc from io.vertx.core.impl.ContextInternal.getDeployment.

the deployment associated with this context or null

internalExecuteBlockingback to summary
private static <T> Future<T> internalExecuteBlocking(ContextInternal context, Handler<Promise<T>> blockingCodeHandler, WorkerPool workerPool, TaskQueue queue)
inThreadback to summary
public boolean inThread()

Implements io.vertx.core.impl.ContextInternal.inThread.

Annotations
@Override
isEventLoopContextback to summary
public boolean isEventLoopContext()

Implements io.vertx.core.Context.isEventLoopContext.

Doc from io.vertx.core.Context.isEventLoopContext.

Is the current context an event loop context?

Note

when running blocking code using io.vertx.core.Vertx#executeBlocking(Callable) from a standard (not worker) verticle, the context will still an event loop context and this this#isEventLoopContext() will return true.

Returns:boolean

true if false otherwise

Annotations
@Override
isWorkerContextback to summary
public boolean isWorkerContext()

Implements io.vertx.core.Context.isWorkerContext.

Doc from io.vertx.core.Context.isWorkerContext.

Is the current context a worker context?

Note

when running blocking code using io.vertx.core.Vertx#executeBlocking(Callable) from a standard (not worker) verticle, the context will still an event loop context and this this#isWorkerContext() will return false.

Returns:boolean

true if the current context is a worker context, false otherwise

Annotations
@Override
nettyEventLoopback to summary
public EventLoop nettyEventLoop()

Implements io.vertx.core.impl.ContextInternal.nettyEventLoop.

Doc from io.vertx.core.impl.ContextInternal.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 VertxImpl owner()

Implements io.vertx.core.impl.ContextInternal.owner.

Returns:VertxImpl

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

The Vertx instance that created the context

reportExceptionback to summary
public void reportException(Throwable t)

Implements io.vertx.core.impl.ContextInternal.reportException.

Doc from io.vertx.core.impl.ContextInternal.reportException.

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
protected void runOnContext(ContextInternal ctx, Handler<Void> action)
setResultHandlerback to summary
pack-priv static <T> void setResultHandler(ContextInternal ctx, Future<T> fut, Handler<AsyncResult<T>> resultHandler)
threadingModelback to summary
public ThreadingModel threadingModel()

Implements io.vertx.core.Context.threadingModel.

Returns:ThreadingModel

Doc from io.vertx.core.Context.threadingModel.

the context threading model

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

Implements io.vertx.core.impl.ContextInternal.tracer.

Returns:VertxTracer<I, O>

Doc from io.vertx.core.impl.ContextInternal.tracer.

the tracer for this context

Annotations
@Override
workerPoolback to summary
public WorkerPool workerPool()

Implements io.vertx.core.impl.ContextInternal.workerPool.

Returns:WorkerPool

Doc from io.vertx.core.impl.ContextInternal.workerPool.

the context worker pool

Annotations
@Override