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.
Methods
-
cancelTimer(id) → {boolean}
-
Cancels the timer with the specified
id
.Parameters:
Name Type Description id
number The id of the timer to cancel 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. -
createDatagramSocket(options) → {DatagramSocket}
-
Create a datagram socket using the specified options
Parameters:
Name Type Description options
Object the options to use 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 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 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 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 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 Returns:
the server- Type
- NetServer
-
deploymentIDs() → {Array.<string>}
-
Return a Set of deployment IDs for the currently deployed deploymentIDs.
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 -
eventBus() → {EventBus}
-
Get the event bus object. There is a single instance of EventBus per Vertx instance.
Returns:
the event bus object- Type
- EventBus
-
executeBlocking(blockingCodeHandler, 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 intoblockingCodeHandler
. When the blocking code successfully completes, the handler should call the Future#complete or {@link Future#complete} method, or the Future#fail method if it failed.Parameters:
Name Type Description blockingCodeHandler
function handler representing the blocking code to run resultHandler
function handler that will be called when the blocking code is complete -
fileSystem() → {FileSystem}
-
Get the filesystem object. There is a single instance of FileSystem per Vertx instance.
Returns:
the filesystem object- Type
- FileSystem
-
getOrCreateContext() → {Context}
-
Gets the current context, or creates one if there isn't one
Returns:
The current context (created if didn't exist)- Type
- Context
-
isClustered() → {boolean}
-
Is this Vert.x instance clustered?
Returns:
true if clustered- Type
- boolean
-
isMetricsEnabled() → {boolean}
-
Whether the metrics are enabled for this measured object
Returns:
true if the metrics are enabled- 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 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 -
setPeriodic(delay, handler) → {number}
-
Set a periodic timer to fire every
delay
milliseconds, at which pointhandler
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 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 pointhandler
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 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.
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 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