public interface Vertx extends Measured
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(io.vertx.core.VertxOptions)
and clusteredVertx(io.vertx.core.VertxOptions, Handler)
.
Please see the user manual for more detailed usage information.
Modifier and Type | Method and Description |
---|---|
boolean |
cancelTimer(long id)
Cancels the timer with the specified
id . |
Future<Void> |
close()
Stop the Vertx instance and release any resources held by it.
|
void |
close(Handler<AsyncResult<Void>> completionHandler)
Like
close() but the completionHandler will be called when the close is complete |
static Future<Vertx> |
clusteredVertx(VertxOptions options)
Same as
clusteredVertx(VertxOptions, Handler) but with an handler called when the operation completes |
static void |
clusteredVertx(VertxOptions options,
Handler<AsyncResult<Vertx>> resultHandler)
Creates a clustered instance using the specified options.
|
default DatagramSocket |
createDatagramSocket()
Create a datagram socket using default options
|
DatagramSocket |
createDatagramSocket(DatagramSocketOptions options)
Create a datagram socket using the specified options
|
DnsClient |
createDnsClient()
Create a DNS client to connect to the DNS server configured by
VertxOptions.getAddressResolverOptions() |
DnsClient |
createDnsClient(DnsClientOptions options)
Create a DNS client to connect to a DNS server
|
DnsClient |
createDnsClient(int port,
String host)
Create a DNS client to connect to a DNS server at the specified host and port, with the default query timeout (5 seconds)
|
default HttpClient |
createHttpClient()
Create a HTTP/HTTPS client using default options
|
HttpClient |
createHttpClient(HttpClientOptions options)
Create a HTTP/HTTPS client using the specified options
|
default HttpServer |
createHttpServer()
Create an HTTP/HTTPS server using default options
|
HttpServer |
createHttpServer(HttpServerOptions options)
Create an HTTP/HTTPS server using the specified options
|
default NetClient |
createNetClient()
Create a TCP/SSL client using default options
|
NetClient |
createNetClient(NetClientOptions options)
Create a TCP/SSL client using the specified options
|
default NetServer |
createNetServer()
Create a TCP/SSL server using default options
|
NetServer |
createNetServer(NetServerOptions options)
Create a TCP/SSL server using the specified options
|
WorkerExecutor |
createSharedWorkerExecutor(String name)
Like
createSharedWorkerExecutor(String, int) but with the VertxOptions.setWorkerPoolSize(int) poolSize . |
WorkerExecutor |
createSharedWorkerExecutor(String name,
int poolSize)
Like
createSharedWorkerExecutor(String, int, long) but with the VertxOptions.setMaxWorkerExecuteTime(long) maxExecuteTime . |
WorkerExecutor |
createSharedWorkerExecutor(String name,
int poolSize,
long maxExecuteTime)
Like
createSharedWorkerExecutor(String, int, long, TimeUnit) but with the VertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit) maxExecuteTimeUnit . |
WorkerExecutor |
createSharedWorkerExecutor(String name,
int poolSize,
long maxExecuteTime,
TimeUnit maxExecuteTimeUnit)
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 . |
static Context |
currentContext()
Gets the current context
|
Set<String> |
deploymentIDs()
Return a Set of deployment IDs for the currently deployed deploymentIDs.
|
Future<String> |
deployVerticle(Class<? extends Verticle> verticleClass,
DeploymentOptions options)
Like
deployVerticle(Verticle, DeploymentOptions) but Verticle instance is created by invoking the
default constructor of verticleClass . |
void |
deployVerticle(Class<? extends Verticle> verticleClass,
DeploymentOptions options,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(Verticle, DeploymentOptions, Handler) but Verticle instance is created by
invoking the default constructor of verticleClass . |
default Future<String> |
deployVerticle(String name)
Deploy a verticle instance given a name.
|
Future<String> |
deployVerticle(String name,
DeploymentOptions options)
Like
deployVerticle(Verticle) but DeploymentOptions are provided to configure the
deployment. |
void |
deployVerticle(String name,
DeploymentOptions options,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(String, Handler) but DeploymentOptions are provided to configure the
deployment. |
default void |
deployVerticle(String name,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(String) but the completionHandler will be notified when the deployment is complete. |
Future<String> |
deployVerticle(java.util.function.Supplier<Verticle> verticleSupplier,
DeploymentOptions options)
Like
deployVerticle(Verticle, DeploymentOptions) but Verticle instance is created by invoking the
verticleSupplier . |
void |
deployVerticle(java.util.function.Supplier<Verticle> verticleSupplier,
DeploymentOptions options,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(Verticle, DeploymentOptions, Handler) but Verticle instance is created by
invoking the verticleSupplier . |
default Future<String> |
deployVerticle(Verticle verticle)
Deploy a verticle instance that you have created yourself.
|
Future<String> |
deployVerticle(Verticle verticle,
DeploymentOptions options)
Like
deployVerticle(Verticle) but DeploymentOptions are provided to configure the
deployment. |
void |
deployVerticle(Verticle verticle,
DeploymentOptions options,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(Verticle, Handler) but DeploymentOptions are provided to configure the
deployment. |
void |
deployVerticle(Verticle verticle,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(Verticle) but the completionHandler will be notified when the deployment is complete. |
EventBus |
eventBus()
Get the event bus object.
|
Handler<Throwable> |
exceptionHandler() |
Vertx |
exceptionHandler(Handler<Throwable> handler)
Set a default exception handler for
Context , set on Context.exceptionHandler(Handler) at creation. |
default <T> Future<T> |
executeBlocking(Callable<T> blockingCodeHandler)
Like
executeBlocking(Callable, boolean) called with ordered = true. |
default <T> Future<T> |
executeBlocking(Callable<T> blockingCodeHandler,
boolean ordered)
Safely execute some blocking code.
|
default <T> Future<T> |
executeBlocking(Handler<Promise<T>> blockingCodeHandler)
Deprecated.
instead use
executeBlocking(Callable) |
default <T> Future<T> |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
boolean ordered)
Deprecated.
instead use
executeBlocking(Callable, boolean) |
default <T> void |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
boolean ordered,
Handler<AsyncResult<T>> resultHandler)
Deprecated.
use instead
executeBlocking(Callable, boolean) |
default <T> void |
executeBlocking(Handler<Promise<T>> blockingCodeHandler,
Handler<AsyncResult<T>> resultHandler)
Deprecated.
instead use
executeBlocking(Callable) |
FileSystem |
fileSystem()
Get the filesystem object.
|
Context |
getOrCreateContext()
Gets the current context, or creates one if there isn't one
|
boolean |
isClustered()
Is this Vert.x instance clustered?
|
boolean |
isNativeTransportEnabled() |
EventLoopGroup |
nettyEventLoopGroup()
Deprecated.
removed from public API in Vert.x 5
|
default TimeoutStream |
periodicStream(long delay)
Deprecated.
use
setPeriodic(long, io.vertx.core.Handler<java.lang.Long>) instead. RxJava like integrations should use the Vert.x scheduler integration. |
TimeoutStream |
periodicStream(long initialDelay,
long delay)
Deprecated.
use
setPeriodic(long, io.vertx.core.Handler<java.lang.Long>) instead. RxJava like integrations should use the Vert.x scheduler integration. |
void |
registerVerticleFactory(VerticleFactory factory)
Register a
VerticleFactory that can be used for deploying Verticles based on an identifier. |
void |
runOnContext(Handler<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.
|
default long |
setPeriodic(long delay,
Handler<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 |
setPeriodic(long initialDelay,
long delay,
Handler<Long> handler)
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. |
long |
setTimer(long delay,
Handler<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)
Deprecated.
use
setTimer(long, io.vertx.core.Handler<java.lang.Long>) instead. RxJava like integrations should use the Vert.x scheduler integration. |
Throwable |
unavailableNativeTransportCause() |
Future<Void> |
undeploy(String deploymentID)
Undeploy a verticle deployment.
|
void |
undeploy(String deploymentID,
Handler<AsyncResult<Void>> completionHandler)
Like
undeploy(String) but the completionHandler will be notified when the undeployment is complete. |
void |
unregisterVerticleFactory(VerticleFactory factory)
Unregister a
VerticleFactory |
Set<VerticleFactory> |
verticleFactories()
Return the Set of currently registered verticle factories.
|
static Vertx |
vertx()
Creates a non clustered instance using default options.
|
static Vertx |
vertx(VertxOptions options)
Creates a non clustered instance using the specified options
|
isMetricsEnabled
static Vertx vertx()
static Vertx vertx(VertxOptions options)
options
- the options to usestatic void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler)
The instance is created asynchronously and the resultHandler is called with the result when it is ready.
options
- the options to useresultHandler
- the result handler that will receive the resultstatic Future<Vertx> clusteredVertx(VertxOptions options)
clusteredVertx(VertxOptions, Handler)
but with an handler
called when the operation completesstatic Context currentContext()
null
if there is no current contextContext getOrCreateContext()
NetServer createNetServer(NetServerOptions options)
options
- the options to usedefault NetServer createNetServer()
NetClient createNetClient(NetClientOptions options)
options
- the options to usedefault NetClient createNetClient()
HttpServer createHttpServer(HttpServerOptions options)
options
- the options to usedefault HttpServer createHttpServer()
HttpClient createHttpClient(HttpClientOptions options)
options
- the options to usedefault HttpClient createHttpClient()
DatagramSocket createDatagramSocket(DatagramSocketOptions options)
options
- the options to usedefault DatagramSocket createDatagramSocket()
FileSystem fileSystem()
EventBus eventBus()
DnsClient createDnsClient(int port, String host)
port
- the porthost
- the hostDnsClient createDnsClient()
VertxOptions.getAddressResolverOptions()
DNS client takes the first configured resolver address provided by DnsResolverProvider.nameServerAddresses()
}
DnsClient createDnsClient(DnsClientOptions options)
options
- the client optionsSharedData sharedData()
long setTimer(long delay, Handler<Long> handler)
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@Deprecated TimeoutStream timerStream(long delay)
setTimer(long, io.vertx.core.Handler<java.lang.Long>)
instead. RxJava like integrations should use the Vert.x scheduler integration.delay
milliseconds after
the ReadStream.handler(io.vertx.core.Handler<T>)
has been called.delay
- the delay in milliseconds, after which the timer will firedefault long setPeriodic(long delay, Handler<Long> handler)
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 fireslong setPeriodic(long initialDelay, long delay, Handler<Long> handler)
delay
milliseconds with initial delay, at which point handler
will be called with
the id of the timer.initialDelay
- the initial delay in millisecondsdelay
- the delay in milliseconds, after which the timer will firehandler
- the handler that will be called with the timer ID when the timer fires@Deprecated default TimeoutStream periodicStream(long delay)
setPeriodic(long, io.vertx.core.Handler<java.lang.Long>)
instead. RxJava like integrations should use the Vert.x scheduler integration.delay
milliseconds after
the ReadStream.handler(io.vertx.core.Handler<T>)
has been called.delay
- the delay in milliseconds, after which the timer will fire@Deprecated TimeoutStream periodicStream(long initialDelay, long delay)
setPeriodic(long, io.vertx.core.Handler<java.lang.Long>)
instead. RxJava like integrations should use the Vert.x scheduler integration.delay
milliseconds after
the ReadStream.handler(io.vertx.core.Handler<T>)
has been called.initialDelay
- the initial delay in millisecondsdelay
- the delay in milliseconds, after which the timer will fireboolean cancelTimer(long id)
id
.id
- The id of the timer to cancelvoid runOnContext(Handler<Void> action)
action
- - a handler representing the action to executeFuture<Void> close()
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.
void close(Handler<AsyncResult<Void>> completionHandler)
close()
but the completionHandler will be called when the close is completecompletionHandler
- The handler will be notified when the close is complete.default Future<String> deployVerticle(Verticle verticle)
Vert.x will assign the verticle a context and start the verticle.
The actual deploy happens asynchronously and may not complete until after the call has returned.
verticle
- the verticle instance to deploy.void deployVerticle(Verticle verticle, Handler<AsyncResult<String>> completionHandler)
deployVerticle(Verticle)
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.
verticle
- the verticle instance to deploycompletionHandler
- a handler which will be notified when the deployment is completeFuture<String> deployVerticle(Verticle verticle, DeploymentOptions options)
deployVerticle(Verticle)
but DeploymentOptions
are provided to configure the
deployment.verticle
- the verticle instance to deployoptions
- the deployment options.Future<String> deployVerticle(Class<? extends Verticle> verticleClass, DeploymentOptions options)
deployVerticle(Verticle, DeploymentOptions)
but Verticle
instance is created by invoking the
default constructor of verticleClass
.Future<String> deployVerticle(java.util.function.Supplier<Verticle> verticleSupplier, DeploymentOptions options)
deployVerticle(Verticle, DeploymentOptions)
but Verticle
instance is created by invoking the
verticleSupplier
.
The supplier will be invoked as many times as DeploymentOptions.getInstances()
.
It must not return the same instance twice.
Note that the supplier will be invoked on the caller thread.
void deployVerticle(Verticle verticle, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
deployVerticle(Verticle, Handler)
but DeploymentOptions
are provided to configure the
deployment.verticle
- the verticle instance to deployoptions
- the deployment options.completionHandler
- a handler which will be notified when the deployment is completevoid deployVerticle(Class<? extends Verticle> verticleClass, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
deployVerticle(Verticle, DeploymentOptions, Handler)
but Verticle
instance is created by
invoking the default constructor of verticleClass
.void deployVerticle(java.util.function.Supplier<Verticle> verticleSupplier, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
deployVerticle(Verticle, DeploymentOptions, Handler)
but Verticle
instance is created by
invoking the verticleSupplier
.
The supplier will be invoked as many times as DeploymentOptions.getInstances()
.
It must not return the same instance twice.
Note that the supplier will be invoked on the caller thread.
default Future<String> deployVerticle(String name)
Given the name, Vert.x selects a VerticleFactory
instance to use to instantiate the verticle.
For the rules on how factories are selected please consult the user manual.
name
- the name.default void deployVerticle(String name, Handler<AsyncResult<String>> completionHandler)
deployVerticle(String)
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 completeFuture<String> deployVerticle(String name, DeploymentOptions options)
deployVerticle(Verticle)
but DeploymentOptions
are provided to configure the
deployment.name
- the nameoptions
- the deployment options.void deployVerticle(String name, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
deployVerticle(String, Handler)
but DeploymentOptions
are provided to configure the
deployment.name
- the nameoptions
- the deployment options.completionHandler
- a handler which will be notified when the deployment is completeFuture<Void> undeploy(String deploymentID)
The actual undeployment happens asynchronously and may not complete until after the method has returned.
deploymentID
- the deployment IDvoid undeploy(String deploymentID, Handler<AsyncResult<Void>> completionHandler)
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 completeSet<String> deploymentIDs()
void registerVerticleFactory(VerticleFactory factory)
VerticleFactory
that can be used for deploying Verticles based on an identifier.factory
- the factory to registervoid unregisterVerticleFactory(VerticleFactory factory)
VerticleFactory
factory
- the factory to unregisterSet<VerticleFactory> verticleFactories()
boolean isClustered()
@Deprecated default <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)
executeBlocking(Callable, boolean)
Executes the blocking code in the handler blockingCodeHandler
using a thread from the worker pool.
The returned future will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.
A Future
instance is passed into blockingCodeHandler
. When the blocking code successfully completes,
the handler should call the Promise.complete(T)
or Promise.complete(Object)
method, or the Promise.fail(java.lang.Throwable)
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 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 Context.runOnContext(Handler)
T
- the type of the resultblockingCodeHandler
- handler representing the blocking code to runresultHandler
- handler that will be called when the blocking code is completeordered
- 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@Deprecated default <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)
executeBlocking(Callable)
executeBlocking(Handler, boolean, Handler)
called with ordered = true.@Deprecated default <T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)
executeBlocking(Callable, boolean)
executeBlocking(Handler, boolean, Handler)
but with an handler
called when the operation completesdefault <T> Future<T> executeBlocking(Callable<T> blockingCodeHandler, boolean ordered)
Executes the blocking code in the handler blockingCodeHandler
using a thread from the worker pool.
The returned future will be completed with the result on the original context (i.e. on the original event loop of the caller) or failed when the handler throws an exception.
In the blockingCodeHandler
the current context remains the original context and therefore any task
scheduled in the blockingCodeHandler
will be executed on 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 Context.runOnContext(Handler)
T
- the type of the resultblockingCodeHandler
- 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
guarantees@Deprecated default <T> Future<T> executeBlocking(Handler<Promise<T>> blockingCodeHandler)
executeBlocking(Callable)
executeBlocking(Handler, Handler)
but with an handler
called when the operation completesdefault <T> Future<T> executeBlocking(Callable<T> blockingCodeHandler)
executeBlocking(Callable, boolean)
called with ordered = true.@Deprecated EventLoopGroup nettyEventLoopGroup()
WorkerExecutor createSharedWorkerExecutor(String name)
createSharedWorkerExecutor(String, int)
but with the VertxOptions.setWorkerPoolSize(int)
poolSize
.WorkerExecutor createSharedWorkerExecutor(String name, int poolSize)
createSharedWorkerExecutor(String, int, long)
but with the VertxOptions.setMaxWorkerExecuteTime(long)
maxExecuteTime
.WorkerExecutor createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime)
createSharedWorkerExecutor(String, int, long, TimeUnit)
but with the VertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit)
maxExecuteTimeUnit
.WorkerExecutor createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime, TimeUnit maxExecuteTimeUnit)
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.
name
- the name of the worker executorpoolSize
- the size of the poolmaxExecuteTime
- the value of max worker execute timemaxExecuteTimeUnit
- the value of unit of max worker execute timeboolean isNativeTransportEnabled()
Throwable unavailableNativeTransportCause()
isNativeTransportEnabled()
returns false
.Vertx exceptionHandler(Handler<Throwable> handler)
Context
, set on Context.exceptionHandler(Handler)
at creation.handler
- the exception handlerCopyright © 2024 Eclipse. All rights reserved.