class Context extends AnyRef
The execution context of a scala-function execution.
When Vert.x provides an event to a handler or calls the start or stop methods of a io.vertx.lang.scala.ScalaVerticle,
the execution is associated with a Context
.
Usually a context is an *event-loop context* and is tied to a specific event loop thread. So executions for that context always occur on that exact same event loop thread.
In the case of worker verticles and running inline blocking code a worker context will be associated with the execution which will use a thread from the worker thread pool.
When a handler is set by a thread associated with a specific context, the Vert.x will guarantee that when that handler is executed, that execution will be associated with the same context.
If a handler is set by a thread not associated with a context (i.e. a non Vert.x thread). Then a new context will be created for that handler.
In other words, a context is propagated.
This means that when a verticle is deployed, any handlers it sets will be associated with the same context - the context of the verticle.
This means (in the case of a standard verticle) that the verticle code will always be executed with the exact same thread, so you don't have to worry about multi-threaded acccess to the verticle state and you can code your application as single threaded.
This class also allows arbitrary data to be io.vertx.scala.core.Context#put and io.vertx.scala.core.Context#get on the context so it can be shared easily amongst different handlers of, for example, a verticle instance.
This class also provides io.vertx.scala.core.Context#runOnContext which allows an action to be executed asynchronously using the same context.
- Alphabetic
- By Inheritance
- Context
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Context(_asJava: AnyRef)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asJava: AnyRef
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
config(): Option[JsonObject]
If the context is associated with a Verticle deployment, this returns the configuration that was specified when the verticle was deployed.
If the context is associated with a Verticle deployment, this returns the configuration that was specified when the verticle was deployed. * @return the configuration of the deployment or null if not a Verticle deployment
-
def
deploymentID(): String
If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment.
If the context is associated with a Verticle deployment, this returns the deployment ID of that deployment. * @return the deployment ID of the deployment or null if not a Verticle deployment
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
exceptionHandler(handler: Handler[Throwable]): Context
Set an exception handler called when the context runs an action throwing an uncaught throwable.
Set an exception handler called when the context runs an action throwing an uncaught throwable.
When this handler is called, io.vertx.scala.core.Vertx#currentContext will return this context. * @param handler the exception handler
- returns
a reference to this, so the API can be used fluently
-
def
executeBlocking[T](blockingFunction: () ⇒ T, ordered: Boolean = true): scala.concurrent.Future[T]
Safely execute some blocking code.
Safely execute some blocking code.
Executes the blocking code in the handler
blockingCodeHandler
using a thread from the worker pool.When the code is complete the returned Future will be completed with the result.
- blockingFunction
function containing blocking code
- ordered
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
a Future representing the result of the blocking operation
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
get[T](key: String)(implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): T
Get some data from the context.
Get some data from the context. * @param key the key of the data
- returns
the data
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getInstanceCount(): Int
- returns
the number of instances of the verticle that were deployed in the deployment (if any) related to this context
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
isEventLoopContext(): Boolean
Is the current context an event loop context?
Is the current context an event loop context?
NOTE! when running blocking code using io.vertx.scala.core.Vertx#executeBlocking from a standard (not worker) verticle, the context will still an event loop context and this will return true. * @return true if false otherwise
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isMultiThreadedWorkerContext(): Boolean
Is the current context a multi-threaded worker context? * @return true if the current context is a multi-threaded worker context, false otherwise
-
def
isWorkerContext(): Boolean
Is the current context a worker context?
Is the current context a worker context?
NOTE! when running blocking code using io.vertx.scala.core.Vertx#executeBlocking from a standard (not worker) verticle, the context will still an event loop context and this will return false. * @return true if the current context is a worker context, false otherwise
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
owner(): Vertx
- returns
The Vertx instance that created the context
-
def
processArgs(): Buffer[String]
The process args
-
def
put(key: String, value: AnyRef): Unit
Put some data in the context.
Put some data in the context.
This can be used to share data between different handlers that share a context * @param key the key of the data
- value
the data
-
def
remove(key: String): Boolean
Remove some data from the context.
Remove some data from the context. * @param key the key to remove
- returns
true if removed successfully, false otherwise
-
def
runOnContext(action: Handler[Unit]): Unit
Run the specified action asynchronously on the same context, some time after the current execution has completed.
Run the specified action asynchronously on the same context, some time after the current execution has completed. * @param action the action to run
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )