Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vertx

The entry point into the Vert.x Core API.

You use an instance of this class for functionality including:

  • Creating TCP clients and servers
  • Creating HTTP clients and servers
  • Creating DNS clients
  • Creating Datagram sockets
  • Setting and cancelling periodic and one-shot timers
  • Getting a reference to the event bus API
  • Getting a reference to the file system API
  • Getting a reference to the shared data API
  • Deploying and undeploying verticles

Most functionality in Vert.x core is fairly low level.

To create an instance of this class you can use the static factory methods: {@link Vertx#vertx}, {@link Vertx#vertx} and {@link Vertx#clusteredVertx}.

Please see the user manual for more detailed usage information.

Hierarchy

  • Vertx

Implements

Index

Methods

cancelTimer

  • cancelTimer(id: number): boolean
  • Cancels the timer with the specified id.

    Parameters

    • id: number

    Returns boolean

close

  • Like {@link Vertx#close} but the completionHandler will be called when the close is complete

    Returns PromiseLike<void>

  • Like {@link Vertx#close} but the completionHandler will be called when the close is complete

    Parameters

    Returns void

createDatagramSocket

  • Create a datagram socket using the specified options

    Parameters

    Returns DatagramSocket

  • Create a datagram socket using default options

    Returns DatagramSocket

createDnsClient

  • Create a DNS client to connect to a DNS server at the specified host and port, with the default query timeout (5 seconds)

    Parameters

    • port: number
    • host: string

    Returns DnsClient

  • Create a DNS client to connect to the DNS server configured by VertxOptions

    DNS client takes the first configured resolver address provided by }

    Returns DnsClient

  • Create a DNS client to connect to a DNS server

    Parameters

    Returns DnsClient

createHttpClient

  • Create a HTTP/HTTPS client using the specified options

    Parameters

    Returns HttpClient

  • Create a HTTP/HTTPS client using default options

    Returns HttpClient

createHttpServer

  • Create an HTTP/HTTPS server using the specified options

    Parameters

    Returns HttpServer

  • Create an HTTP/HTTPS server using default options

    Returns HttpServer

createNetClient

  • Create a TCP/SSL client using the specified options

    Parameters

    Returns NetClient

  • Create a TCP/SSL client using default options

    Returns NetClient

createNetServer

  • Create a TCP/SSL server using the specified options

    Parameters

    Returns NetServer

  • Create a TCP/SSL server using default options

    Returns NetServer

createSharedWorkerExecutor

  • createSharedWorkerExecutor(name: string): WorkerExecutor
  • createSharedWorkerExecutor(name: string, poolSize: number): WorkerExecutor
  • createSharedWorkerExecutor(name: string, poolSize: number, maxExecuteTime: number): WorkerExecutor
  • createSharedWorkerExecutor(name: string, poolSize: number, maxExecuteTime: number, maxExecuteTimeUnit: any): WorkerExecutor
  • Like {@link Vertx#createSharedWorkerExecutor} but with the VertxOptions poolSize.

    Parameters

    • name: string

    Returns WorkerExecutor

  • Like {@link Vertx#createSharedWorkerExecutor} but with the VertxOptions maxExecuteTime.

    Parameters

    • name: string
    • poolSize: number

    Returns WorkerExecutor

  • Like {@link Vertx#createSharedWorkerExecutor} but with the VertxOptions maxExecuteTimeUnit.

    Parameters

    • name: string
    • poolSize: number
    • maxExecuteTime: number

    Returns WorkerExecutor

  • Create a named worker executor, the executor should be closed when it's not needed anymore to release resources.

    This method can be called mutiple times with the same name. Executors with the same name will share the same worker pool. The worker pool size , max execute time and unit of max execute time are set when the worker pool is created and won't change after.

    The worker pool is released when all the WorkerExecutor sharing the same name are closed.

    Parameters

    • name: string
    • poolSize: number
    • maxExecuteTime: number
    • maxExecuteTimeUnit: any

    Returns WorkerExecutor

deployVerticle

  • Like {@link Vertx#deployVerticle} but the completionHandler will be notified when the deployment is complete.

    If the deployment is successful the result will contain a String representing the unique deployment ID of the deployment.

    This deployment ID can subsequently be used to undeploy the verticle.

    Parameters

    • name: string

    Returns PromiseLike<string>

  • Like {@link Vertx#deployVerticle} but the completionHandler will be notified when the deployment is complete.

    If the deployment is successful the result will contain a String representing the unique deployment ID of the deployment.

    This deployment ID can subsequently be used to undeploy the verticle.

    Parameters

    Returns void

  • Like {@link Vertx#deployVerticle} but DeploymentOptions are provided to configure the deployment.

    Parameters

    Returns PromiseLike<string>

  • Like {@link Vertx#deployVerticle} but DeploymentOptions are provided to configure the deployment.

    Parameters

    Returns void

  • Like {@link Vertx#deployVerticle} but the completionHandler will be notified when the deployment is complete.

    If the deployment is successful the result will contain a string representing the unique deployment ID of the deployment.

    This deployment ID can subsequently be used to undeploy the verticle.

    Parameters

    • verticle: any

    Returns PromiseLike<string>

  • Like {@link Vertx#deployVerticle} but the completionHandler will be notified when the deployment is complete.

    If the deployment is successful the result will contain a string representing the unique deployment ID of the deployment.

    This deployment ID can subsequently be used to undeploy the verticle.

    Parameters

    Returns void

  • Like {@link Vertx#deployVerticle} but DeploymentOptions are provided to configure the deployment.

    Parameters

    Returns PromiseLike<string>

  • Like {@link Vertx#deployVerticle} but DeploymentOptions are provided to configure the deployment.

    Parameters

    Returns void

  • Like {@link Vertx#deployVerticle} but {@link Verticle} instance is created by invoking the verticleSupplier.

    The supplier will be invoked as many times as DeploymentOptions. It must not return the same instance twice.

    Note that the supplier will be invoked on the caller thread.

    Parameters

    Returns PromiseLike<string>

  • Like {@link Vertx#deployVerticle} but {@link Verticle} instance is created by invoking the verticleSupplier.

    The supplier will be invoked as many times as DeploymentOptions. It must not return the same instance twice.

    Note that the supplier will be invoked on the caller thread.

    Parameters

    Returns void

deploymentIDs

  • deploymentIDs(): string
  • Return a Set of deployment IDs for the currently deployed deploymentIDs.

    Returns string

eventBus

  • Get the event bus object. There is a single instance of EventBus per Vertx instance.

    Returns EventBus

exceptionHandler

  • Set a default exception handler for Context, set on {@link Context#exceptionHandler} at creation.

    Parameters

    Returns Vertx

executeBlocking

  • 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 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 {@link Promise#complete} or {@link Promise#complete} method, or the {@link Promise#fail} method if it failed.

    In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on the this context and not on the worker thread.

    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 {@link Context#runOnContext}

    Type parameters

    • T

    Parameters

    Returns PromiseLike<T>

  • 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 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 {@link Promise#complete} or {@link Promise#complete} method, or the {@link Promise#fail} method if it failed.

    In the blockingCodeHandler the current context remains the original context and therefore any task scheduled in the blockingCodeHandler will be executed on the this context and not on the worker thread.

    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 {@link Context#runOnContext}

    Type parameters

    • T

    Parameters

    Returns void

  • Like {@link Vertx#executeBlocking} called with ordered = true.

    Type parameters

    • T

    Parameters

    Returns PromiseLike<T>

  • Like {@link Vertx#executeBlocking} called with ordered = true.

    Type parameters

    • T

    Parameters

    Returns void

fileSystem

  • Get the filesystem object. There is a single instance of FileSystem per Vertx instance.

    Returns FileSystem

getOrCreateContext

  • Gets the current context, or creates one if there isn't one

    Returns Context

isClustered

  • isClustered(): boolean
  • Is this Vert.x instance clustered?

    Returns boolean

isMetricsEnabled

  • isMetricsEnabled(): boolean
  • Whether the metrics are enabled for this measured object

    Returns boolean

isNativeTransportEnabled

  • isNativeTransportEnabled(): boolean
  • Returns boolean

nettyEventLoopGroup

  • nettyEventLoopGroup(): any
  • Return the Netty EventLoopGroup used by Vert.x

    Returns any

periodicStream

  • Returns a periodic timer as a read stream. The timer will be fired every delay milliseconds after the has been called.

    Parameters

    • delay: number

    Returns TimeoutStream

  • Returns a periodic timer as a read stream. The timer will be fired every delay milliseconds after the has been called.

    Parameters

    • initialDelay: number
    • delay: number

    Returns TimeoutStream

registerVerticleFactory

  • registerVerticleFactory(factory: any): void
  • Register a VerticleFactory that can be used for deploying Verticles based on an identifier.

    Parameters

    • factory: any

    Returns void

runOnContext

  • runOnContext(action: ((res: void) => void) | Handler<void>): void
  • Puts the handler on the event queue for the current context so it will be run asynchronously ASAP after all preceeding events have been handled.

    Parameters

    • action: ((res: void) => void) | Handler<void>

    Returns void

setPeriodic

  • setPeriodic(delay: number, handler: ((res: number) => void) | Handler<number>): number
  • setPeriodic(initialDelay: number, delay: number, handler: ((res: number) => void) | Handler<number>): number
  • Set a periodic timer to fire every delay milliseconds, at which point handler will be called with the id of the timer.

    Parameters

    • delay: number
    • handler: ((res: number) => void) | Handler<number>

    Returns number

  • Set a periodic timer to fire every delay milliseconds with initial delay, at which point handler will be called with the id of the timer.

    Parameters

    • initialDelay: number
    • delay: number
    • handler: ((res: number) => void) | Handler<number>

    Returns number

setTimer

  • setTimer(delay: number, handler: ((res: number) => void) | Handler<number>): number
  • Set a one-shot timer to fire after delay milliseconds, at which point handler will be called with the id of the timer.

    Parameters

    • delay: number
    • handler: ((res: number) => void) | Handler<number>

    Returns number

sharedData

  • Get the shared data object. There is a single instance of SharedData per Vertx instance.

    Returns SharedData

timerStream

  • Returns a one-shot timer as a read stream. The timer will be fired after delay milliseconds after the has been called.

    Parameters

    • delay: number

    Returns TimeoutStream

unavailableNativeTransportCause

  • unavailableNativeTransportCause(): Throwable
  • Returns Throwable

undeploy

  • undeploy(deploymentID: string): PromiseLike<void>
  • undeploy(deploymentID: string, completionHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): void
  • Like [#undeploy(String)] Vertx but the completionHandler will be notified when the undeployment is complete.

    Parameters

    • deploymentID: string

    Returns PromiseLike<void>

  • Like [#undeploy(String)] Vertx but the completionHandler will be notified when the undeployment is complete.

    Parameters

    Returns void

unregisterVerticleFactory

  • unregisterVerticleFactory(factory: any): void
  • Unregister a VerticleFactory

    Parameters

    • factory: any

    Returns void

verticleFactories

  • verticleFactories(): any
  • Return the Set of currently registered verticle factories.

    Returns any

Static clusteredVertx

  • Creates a clustered instance using the specified options.

    The instance is created asynchronously and the resultHandler is called with the result when it is ready.

    Parameters

    Returns PromiseLike<Vertx>

  • Creates a clustered instance using the specified options.

    The instance is created asynchronously and the resultHandler is called with the result when it is ready.

    Parameters

    Returns void

Static currentContext

  • Gets the current context

    Returns Context | null

Static vertx

  • Creates a non clustered instance using default options.

    Returns Vertx

  • Creates a non clustered instance using the specified options

    Parameters

    Returns Vertx

Generated using TypeDoc