Packages

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Context
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Context(_asJava: AnyRef)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def asJava: AnyRef
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. 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

  8. 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

  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  11. 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

  12. 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

  13. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. 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

  15. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def getInstanceCount(): Int

    returns

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

  17. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. 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

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. 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

  21. 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

  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. def owner(): Vertx

    returns

    The Vertx instance that created the context

  26. def processArgs(): Buffer[String]

    The process args

  27. 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

  28. 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

  29. 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

  30. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  31. def toString(): String
    Definition Classes
    AnyRef → Any
  32. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped