@groovy.transform.CompileStatic class Vertx extends java.lang.Object
The entry point into the Vert.x Core API.
You use an instance of this class for functionality including:
Most functionality in Vert.x core is fairly low level.
To create an instance of this class you can use the static factory methods: Vertx.vertx, Vertx.vertx and Vertx.clusteredVertx.
Please see the user manual for more detailed usage information.
Constructor and description |
---|
Vertx
(java.lang.Object delegate) |
Type | Name and description | ||||
---|---|---|---|---|---|
boolean |
cancelTimer(long id) Cancels the timer with the specified id . |
||||
void |
close() Stop the the Vertx instance and release any resources held by it. |
||||
void |
close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler) Like Vertx.close but the completionHandler will be called when the close is complete |
||||
static void |
clusteredVertx(java.util.Map<java.lang.String, java.lang.Object> options = [:], io.vertx.core.Handler<io.vertx.core.AsyncResult<Vertx>> resultHandler) Creates a clustered instance using the specified options. |
||||
DatagramSocket |
createDatagramSocket(java.util.Map<java.lang.String, java.lang.Object> options) Create a datagram socket using the specified options |
||||
DatagramSocket |
createDatagramSocket() Create a datagram socket using default options |
||||
DnsClient |
createDnsClient(int port, java.lang.String host) Create a DNS client to connect to a DNS server at the specified host and port |
||||
HttpClient |
createHttpClient(java.util.Map<java.lang.String, java.lang.Object> options) Create a HTTP/HTTPS client using the specified options |
||||
HttpClient |
createHttpClient() Create a HTTP/HTTPS client using default options |
||||
HttpServer |
createHttpServer(java.util.Map<java.lang.String, java.lang.Object> options) Create an HTTP/HTTPS server using the specified options |
||||
HttpServer |
createHttpServer() Create an HTTP/HTTPS server using default options |
||||
NetClient |
createNetClient(java.util.Map<java.lang.String, java.lang.Object> options) Create a TCP/SSL client using the specified options |
||||
NetClient |
createNetClient() Create a TCP/SSL client using default options |
||||
NetServer |
createNetServer(java.util.Map<java.lang.String, java.lang.Object> options) Create a TCP/SSL server using the specified options |
||||
NetServer |
createNetServer() Create a TCP/SSL server using default options |
||||
WorkerExecutor |
createSharedWorkerExecutor(java.lang.String name) Like Vertx.createSharedWorkerExecutor but with the | WorkerExecutor |
createSharedWorkerExecutor(java.lang.String name, int poolSize) Like Vertx.createSharedWorkerExecutor but with the | WorkerExecutor |
createSharedWorkerExecutor(java.lang.String name, int poolSize, long maxExecuteTime) Create a named worker executor, the executor should be closed when it's not needed anymore to release resources. |
static Context |
currentContext() Gets the current context |
||||
void |
deployVerticle(java.lang.String name) Deploy a verticle instance given a name. |
||||
void |
deployVerticle(java.lang.String name, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler) Like Vertx.deployVerticle but the completionHandler will be notified when the deployment is complete. |
||||
void |
deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options) Like Vertx.deployVerticle but | void |
deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler) Like Vertx.deployVerticle but | java.util.Set<java.lang.String> |
deploymentIDs() Return a Set of deployment IDs for the currently deployed deploymentIDs. |
EventBus |
eventBus() Get the event bus object. |
||||
Vertx |
exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler) Set a default exception handler for Context, set on at creation. |
||||
void |
executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, boolean ordered, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler) Safely execute some blocking code. |
||||
void |
executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler) Like Vertx.executeBlocking called with ordered = true. |
||||
FileSystem |
fileSystem() Get the filesystem object. |
||||
java.lang.Object |
getDelegate() |
||||
Context |
getOrCreateContext() Gets the current context, or creates one if there isn't one |
||||
boolean |
isClustered() Is this Vert.x instance clustered? |
||||
boolean |
isMetricsEnabled() Whether the metrics are enabled for this measured object |
||||
TimeoutStream |
periodicStream(long delay) Returns a periodic timer as a read stream. |
||||
void |
runOnContext(io.vertx.core.Handler<java.lang.Void> 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. |
||||
long |
setPeriodic(long delay, io.vertx.core.Handler<java.lang.Long> handler) Set a periodic timer to fire every delay milliseconds, at which point handler will be called with
the id of the timer. |
||||
long |
setTimer(long delay, io.vertx.core.Handler<java.lang.Long> handler) Set a one-shot timer to fire after delay milliseconds, at which point handler will be called with
the id of the timer. |
||||
SharedData |
sharedData() Get the shared data object. |
||||
TimeoutStream |
timerStream(long delay) Returns a one-shot timer as a read stream. |
||||
void |
undeploy(java.lang.String deploymentID) Undeploy a verticle deployment. |
||||
void |
undeploy(java.lang.String deploymentID, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler) Like #undeploy(String) but the completionHandler will be notified when the undeployment is complete. |
||||
static Vertx |
vertx() Creates a non clustered instance using default options. |
||||
static Vertx |
vertx(java.util.Map<java.lang.String, java.lang.Object> options) Creates a non clustered instance using the specified options |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Cancels the timer with the specified id
.
id
- The id of the timer to cancelStop the the Vertx instance and release any resources held by it.
The instance cannot be used after it has been closed.
The actual close is asynchronous and may not complete until after the call has returned.
Like Vertx.close but the completionHandler will be called when the close is complete
completionHandler
- The handler will be notified when the close is complete.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.
options
- the options to use (see VertxOptions)resultHandler
- the result handler that will receive the resultCreate a datagram socket using the specified options
options
- the options to use (see DatagramSocketOptions)Create a datagram socket using default options
Create a DNS client to connect to a DNS server at the specified host and port
port
- the porthost
- the hostCreate a HTTP/HTTPS client using the specified options
options
- the options to use (see HttpClientOptions)Create a HTTP/HTTPS client using default options
Create an HTTP/HTTPS server using the specified options
options
- the options to use (see HttpServerOptions)Create an HTTP/HTTPS server using default options
Create a TCP/SSL client using the specified options
options
- the options to use (see NetClientOptions)Create a TCP/SSL client using default options
Create a TCP/SSL server using the specified options
options
- the options to use (see NetServerOptions)Create a TCP/SSL server using default options
Like Vertx.createSharedWorkerExecutor but with the VertxOptions poolSize
.
Like Vertx.createSharedWorkerExecutor but with the VertxOptions maxExecuteTime
.
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 samename
. 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.
name
- the name of the worker executorpoolSize
- the size of the poolmaxExecuteTime
- the value of max worker execute time, in msGets the current context
Deploy a verticle instance given a name.
Given the name, Vert.x selects a instance to use to instantiate the verticle.
For the rules on how factories are selected please consult the user manual.
name
- the name.Like 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.
name
- The identifiercompletionHandler
- a handler which will be notified when the deployment is completeLike Vertx.deployVerticle but DeploymentOptions are provided to configure the deployment.
name
- the nameoptions
- the deployment options. (see DeploymentOptions)Like Vertx.deployVerticle but DeploymentOptions are provided to configure the deployment.
name
- the nameoptions
- the deployment options. (see DeploymentOptions)completionHandler
- a handler which will be notified when the deployment is completeReturn a Set of deployment IDs for the currently deployed deploymentIDs.
Get the event bus object. There is a single instance of EventBus per Vertx instance.
Set a default exception handler for Context, set on at creation.
handler
- the exception handlerSafely 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.
blockingCodeHandler
- handler representing the blocking code to runordered
- 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 guaranteesresultHandler
- handler that will be called when the blocking code is completeLike Vertx.executeBlocking called with ordered = true.
Get the filesystem object. There is a single instance of FileSystem per Vertx instance.
Gets the current context, or creates one if there isn't one
Is this Vert.x instance clustered?
Whether the metrics are enabled for this measured object
Returns a periodic timer as a read stream. The timer will be fired every delay
milliseconds after
the has been called.
delay
- the delay in milliseconds, after which the timer will firePuts the handler on the event queue for the current context so it will be run asynchronously ASAP after all preceeding events have been handled.
action
- - a handler representing the action to execute Set a periodic timer to fire every delay
milliseconds, at which point handler
will be called with
the id of the timer.
delay
- the delay in milliseconds, after which the timer will firehandler
- the handler that will be called with the timer ID when the timer fires Set a one-shot timer to fire after delay
milliseconds, at which point handler
will be called with
the id of the timer.
delay
- the delay in milliseconds, after which the timer will firehandler
- the handler that will be called with the timer ID when the timer firesGet the shared data object. There is a single instance of SharedData per Vertx instance.
Returns a one-shot timer as a read stream. The timer will be fired after delay
milliseconds after
the has been called.
delay
- the delay in milliseconds, after which the timer will fireUndeploy a verticle deployment.
The actual undeployment happens asynchronously and may not complete until after the method has returned.
deploymentID
- the deployment IDLike #undeploy(String) but the completionHandler will be notified when the undeployment is complete.
deploymentID
- the deployment IDcompletionHandler
- a handler which will be notified when the undeployment is completeCreates a non clustered instance using default options.
Creates a non clustered instance using the specified options
options
- the options to use (see VertxOptions)