public class EventLoopContext extends Object
| Modifier and Type | Field and Description |
|---|---|
protected JsonObject |
config |
protected String |
deploymentID |
protected WorkerPool |
internalBlockingPool |
protected TaskQueue |
internalOrderedTasks |
protected VertxInternal |
owner |
protected WorkerPool |
workerPool |
| Constructor and Description |
|---|
EventLoopContext(VertxInternal vertx,
io.netty.channel.EventLoop eventLoop,
WorkerPool internalBlockingPool,
WorkerPool workerPool,
String deploymentID,
JsonObject config,
ClassLoader tccl) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCloseHook(Closeable hook) |
JsonObject |
config()
If the context is associated with a Verticle deployment, this returns the configuration that was specified when
the verticle was deployed.
|
static Context |
context() |
ConcurrentMap<Object,Object> |
contextData() |
String |
deploymentID()
If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment.
|
Handler<Throwable> |
exceptionHandler() |
Context |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler called when the context runs an action throwing an uncaught throwable.
When this handler is called,
Vertx.currentContext() will return this context. |
<T> void |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
boolean ordered,
Handler<AsyncResult<T>> resultHandler)
Safely execute some blocking code.
|
<T> void |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
Handler<AsyncResult<T>> resultHandler)
Invoke
Context.executeBlocking(Handler, boolean, Handler) with order = true. |
<T> void |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
TaskQueue queue,
Handler<AsyncResult<T>> resultHandler)
Like
Context.executeBlocking(Handler, boolean, Handler) but uses the queue to order the tasks instead
of the internal queue of this context. |
<T> void |
executeBlockingInternal(Handler<Promise<T>> action,
Handler<AsyncResult<T>> resultHandler)
Execute an internal task on the internal blocking ordered executor.
|
void |
executeFromIO(Handler<Void> task)
Like
ContextInternal.executeFromIO(Object, Handler) but with no argument. |
<T> void |
executeFromIO(T value,
Handler<T> task)
Execute the context task and switch on this context if necessary, this also associates the
current thread with the current context so
Vertx.currentContext() returns this context.
The caller thread should be the the event loop thread of this context.
Any exception thrown from the task will be reported on this context. |
<T> T |
get(String key)
Get some data from the context.
|
Deployment |
getDeployment() |
int |
getInstanceCount() |
boolean |
isEventLoopContext()
Is the current context an event loop context?
|
boolean |
isMultiThreadedWorkerContext()
Is the current context a multi-threaded worker context?
|
boolean |
isWorkerContext()
Is the current context a worker context?
|
io.netty.channel.EventLoop |
nettyEventLoop()
Return the Netty EventLoop used by this Context.
|
VertxInternal |
owner() |
List<String> |
processArgs()
The process args
|
void |
put(String key,
Object value)
Put some data in the context.
|
boolean |
remove(String key)
Remove some data from the context.
|
boolean |
removeCloseHook(Closeable hook) |
void |
reportException(Throwable t)
Report an exception to this context synchronously.
|
void |
runCloseHooks(Handler<AsyncResult<Void>> completionHandler) |
void |
runOnContext(Handler<Void> task)
Run the specified action asynchronously on the same context, some time after the current execution has completed.
|
void |
setDeployment(Deployment deployment) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisOnEventLoopThread, isOnVertxThread, isOnWorkerThreadprotected final VertxInternal owner
protected final String deploymentID
protected final JsonObject config
protected final WorkerPool workerPool
protected final WorkerPool internalBlockingPool
protected final TaskQueue internalOrderedTasks
public EventLoopContext(VertxInternal vertx, io.netty.channel.EventLoop eventLoop, WorkerPool internalBlockingPool, WorkerPool workerPool, String deploymentID, JsonObject config, ClassLoader tccl)
public boolean isEventLoopContext()
Context
NOTE! when running blocking code using Vertx.executeBlocking(Handler, Handler) from a
standard (not worker) verticle, the context will still an event loop context and this this#isEventLoopContext()
will return true.
isEventLoopContext in interface Contextpublic boolean isMultiThreadedWorkerContext()
ContextisMultiThreadedWorkerContext in interface Contextpublic static Context context()
public void setDeployment(Deployment deployment)
public Deployment getDeployment()
getDeployment in interface ContextInternalnullpublic void addCloseHook(Closeable hook)
addCloseHook in interface Contextpublic boolean removeCloseHook(Closeable hook)
removeCloseHook in interface Contextpublic void runCloseHooks(Handler<AsyncResult<Void>> completionHandler)
public <T> T get(String key)
Contextpublic void put(String key, Object value)
ContextThis can be used to share data between different handlers that share a context
public boolean remove(String key)
Contextpublic boolean isWorkerContext()
Context
NOTE! when running blocking code using Vertx.executeBlocking(Handler, Handler) from a
standard (not worker) verticle, the context will still an event loop context and this this#isWorkerContext()
will return false.
isWorkerContext in interface Contextpublic final void executeFromIO(Handler<Void> task)
ContextInternalContextInternal.executeFromIO(Object, Handler) but with no argument.executeFromIO in interface ContextInternalpublic final <T> void executeFromIO(T value,
Handler<T> task)
ContextInternalVertx.currentContext() returns this context.
The caller thread should be the the event loop thread of this context.
Any exception thrown from the task will be reported on this context.executeFromIO in interface ContextInternalvalue - the argument for the tasktask - the task to execute with the value argumentpublic void runOnContext(Handler<Void> task)
ContextrunOnContext in interface Contexttask - the action to runpublic String deploymentID()
ContextdeploymentID in interface Contextpublic JsonObject config()
Contextpublic List<String> processArgs()
ContextprocessArgs in interface Contextpublic io.netty.channel.EventLoop nettyEventLoop()
ContextInternalnettyEventLoop in interface ContextInternalpublic VertxInternal owner()
owner in interface Contextowner in interface ContextInternalpublic <T> void executeBlockingInternal(Handler<Promise<T>> action, Handler<AsyncResult<T>> resultHandler)
ContextInternalexecuteBlockingInternal in interface ContextInternalpublic <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)
Context
Executes the blocking code in the handler blockingCodeHandler using a thread from the worker pool.
When the code is complete the handler resultHandler will be called with the result on the original context
(e.g. on the original event loop of the caller).
A Future instance is passed into blockingCodeHandler. When the blocking code successfully completes,
the handler should call the Promise.complete(T) or Promise.complete(Object) method, or the Promise.fail(java.lang.Throwable)
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)
executeBlocking in interface ContextT - the type of the resultblockingCodeHandler - handler representing the blocking code to runordered - 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
guaranteesresultHandler - handler that will be called when the blocking code is completepublic <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)
ContextContext.executeBlocking(Handler, boolean, Handler) with order = true.executeBlocking in interface ContextT - the type of the resultblockingCodeHandler - handler representing the blocking code to runresultHandler - handler that will be called when the blocking code is completepublic <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, TaskQueue queue, Handler<AsyncResult<T>> resultHandler)
ContextInternalContext.executeBlocking(Handler, boolean, Handler) but uses the queue to order the tasks instead
of the internal queue of this context.executeBlocking in interface ContextInternalpublic ConcurrentMap<Object,Object> contextData()
contextData in interface ContextInternalConcurrentMap used to store context dataContext.get(String),
Context.put(String, Object)public void reportException(Throwable t)
ContextInternalThe exception handler will be called when there is one, otherwise the exception will be logged.
reportException in interface ContextInternalt - the exception to reportpublic Context exceptionHandler(Handler<Throwable> handler)
ContextVertx.currentContext() will return this context.exceptionHandler in interface Contexthandler - the exception handlerpublic Handler<Throwable> exceptionHandler()
exceptionHandler in interface Contextpublic int getInstanceCount()
getInstanceCount in interface ContextCopyright © 2020. All rights reserved.