Class: Vertx

vertx-js/vertx~ Vertx

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

Source:

Methods

cancelTimer(id) → {boolean}

Cancels the timer with the specified id.
Parameters:
Name Type Description
id number The id of the timer to cancel
Source:
Returns:
true if the timer was successfully cancelled, or false if the timer does not exist.
Type
boolean

close(completionHandler)

Like Vertx#close but the completionHandler will be called when the close is complete
Parameters:
Name Type Description
completionHandler function The handler will be notified when the close is complete.
Source:

createDatagramSocket(options) → {DatagramSocket}

Create a datagram socket using the specified options
Parameters:
Name Type Description
options Object the options to use
Source:
Returns:
the socket
Type
DatagramSocket

createDnsClient(port, host) → {DnsClient}

Create a DNS client to connect to a DNS server at the specified host and port
Parameters:
Name Type Description
port number the port
host string the host
Source:
Returns:
the DNS client
Type
DnsClient

createHttpClient(options) → {HttpClient}

Create a HTTP/HTTPS client using the specified options
Parameters:
Name Type Description
options Object the options to use
Source:
Returns:
the client
Type
HttpClient

createHttpServer(options) → {HttpServer}

Create an HTTP/HTTPS server using the specified options
Parameters:
Name Type Description
options Object the options to use
Source:
Returns:
the server
Type
HttpServer

createNetClient(options) → {NetClient}

Create a TCP/SSL client using the specified options
Parameters:
Name Type Description
options Object the options to use
Source:
Returns:
the client
Type
NetClient

createNetServer(options) → {NetServer}

Create a TCP/SSL server using the specified options
Parameters:
Name Type Description
options Object the options to use
Source:
Returns:
the server
Type
NetServer

createSharedWorkerExecutor(name, poolSize, maxExecuteTime) → {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 and 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 Type Description
name string the name of the worker executor
poolSize number the size of the pool
maxExecuteTime number the value of max worker execute time, in ns
Source:
Returns:
the named worker executor
Type
WorkerExecutor

deploymentIDs() → {Array.<string>}

Return a Set of deployment IDs for the currently deployed deploymentIDs.
Source:
Returns:
Set of deployment IDs
Type
Array.<string>

deployVerticle(name, options, completionHandler)

Like Vertx#deployVerticle but DeploymentOptions are provided to configure the deployment.
Parameters:
Name Type Description
name string the name
options Object the deployment options.
completionHandler function a handler which will be notified when the deployment is complete
Source:

eventBus() → {EventBus}

Get the event bus object. There is a single instance of EventBus per Vertx instance.
Source:
Returns:
the event bus object
Type
EventBus

exceptionHandler(handler) → {Vertx}

Set a default exception handler for Context, set on at creation.
Parameters:
Name Type Description
handler function the exception handler
Source:
Returns:
a reference to this, so the API can be used fluently
Type
Vertx

executeBlocking(blockingCodeHandler, ordered, resultHandler)

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 Future#complete or Future#complete method, or the Future#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.

Parameters:
Name Type Description
blockingCodeHandler function 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
resultHandler function handler that will be called when the blocking code is complete
Source:

fileSystem() → {FileSystem}

Get the filesystem object. There is a single instance of FileSystem per Vertx instance.
Source:
Returns:
the filesystem object
Type
FileSystem

getOrCreateContext() → {Context}

Gets the current context, or creates one if there isn't one
Source:
Returns:
The current context (created if didn't exist)
Type
Context

isClustered() → {boolean}

Is this Vert.x instance clustered?
Source:
Returns:
true if clustered
Type
boolean

isMetricsEnabled() → {boolean}

Whether the metrics are enabled for this measured object
Source:
Returns:
true if the metrics are enabled
Type
boolean

isNativeTransportEnabled() → {boolean}

Source:
Returns:
wether the native transport is used
Type
boolean

periodicStream(delay) → {TimeoutStream}

Returns a periodic timer as a read stream. The timer will be fired every delay milliseconds after the has been called.
Parameters:
Name Type Description
delay number the delay in milliseconds, after which the timer will fire
Source:
Returns:
the periodic stream
Type
TimeoutStream

runOnContext(action)

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:
Name Type Description
action function a handler representing the action to execute
Source:

setPeriodic(delay, handler) → {number}

Set a periodic timer to fire every delay milliseconds, at which point handler will be called with the id of the timer.
Parameters:
Name Type Description
delay number the delay in milliseconds, after which the timer will fire
handler function the handler that will be called with the timer ID when the timer fires
Source:
Returns:
the unique ID of the timer
Type
number

setTimer(delay, handler) → {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:
Name Type Description
delay number the delay in milliseconds, after which the timer will fire
handler function the handler that will be called with the timer ID when the timer fires
Source:
Returns:
the unique ID of the timer
Type
number

sharedData() → {SharedData}

Get the shared data object. There is a single instance of SharedData per Vertx instance.
Source:
Returns:
the shared data object
Type
SharedData

timerStream(delay) → {TimeoutStream}

Returns a one-shot timer as a read stream. The timer will be fired after delay milliseconds after the has been called.
Parameters:
Name Type Description
delay number the delay in milliseconds, after which the timer will fire
Source:
Returns:
the timer stream
Type
TimeoutStream

undeploy(deploymentID, completionHandler)

Like [#undeploy(String)] Vertx but the completionHandler will be notified when the undeployment is complete.
Parameters:
Name Type Description
deploymentID string the deployment ID
completionHandler function a handler which will be notified when the undeployment is complete
Source: