Class Vertx
- All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate, Measured
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: vertx(),
vertx() and clusteredVertx(VertxOptions).
Please see the user manual for more detailed usage information.
NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic VertxBuilderbuilder()Return a builder for Vert.x instances which allows to specify SPI such as cluster manager, metrics or tracing.booleancancelTimer(long id) Cancels the timer with the specifiedid.close()Stop the Vertx instance and release any resources held by it.clusteredVertx(VertxOptions options) Creates a clustered instance using the specified options.Create a datagram socket using default optionsCreate a datagram socket using the specified optionsCreate a DNS client to connect to the DNS server configured byVertxOptionscreateDnsClient(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)createDnsClient(DnsClientOptions options) Create a DNS client to connect to a DNS serverCreate a HTTP/HTTPS client using default optionscreateHttpClient(HttpClientConfig config) Create an HTTP/HTTPS client using the specified configcreateHttpClient(HttpClientConfig clientConfig, PoolOptions poolOptions) Create a HTTP/HTTPS client using the specified client and pool optionscreateHttpClient(HttpClientConfig clientConfig, ClientSSLOptions sslOptions) Create a HTTP/HTTPS client using the specified client and ssl optionscreateHttpClient(HttpClientConfig clientConfig, ClientSSLOptions sslOptions, PoolOptions poolOptions) Create a HTTP/HTTPS client using the specified client, ssl options and pool optionscreateHttpClient(HttpClientOptions clientOptions) Create a HTTP/HTTPS client using the specified client optionscreateHttpClient(HttpClientOptions clientOptions, PoolOptions poolOptions) Create a HTTP/HTTPS client using the specified client and pool optionscreateHttpClient(PoolOptions poolOptions) Create a HTTP/HTTPS client using the specified pool optionsCreate an HTTP/HTTPS server using default config.createHttpServer(HttpServerConfig config) Create an HTTP server using the specifiedconfig.createHttpServer(HttpServerConfig config, ServerSSLOptions sslOptions) Create an HTTP server using the specified config and the specifiedsslOptionscreateHttpServer(HttpServerOptions options) Create an HTTP/HTTPS server using the specifiedoptionscreateHttpServer(ServerSSLOptions sslOptions) Create an HTTP server using default config and the specifiedsslOptions.Create a TCP/SSL client using default optionscreateNetClient(NetClientOptions options) Create a TCP/SSL client using the specified optionscreateNetClient(TcpClientConfig config) Create a TCP/SSL client using the specified configcreateNetClient(TcpClientConfig config, ClientSSLOptions sslOptions) Create a TCP/SSL client using the specified config and the specified ssl optionsCreate a TCP/SSL server using default optionscreateNetServer(NetServerOptions options) Create a TCP/SSL server using the specified optionscreateNetServer(TcpServerConfig config) Create a TCP/SSL server using the specified configcreateNetServer(TcpServerConfig config, ServerSSLOptions sslOptions) Create a TCP/SSL server using the specified config and the specified ssl optionscreateQuicClient(ClientSSLOptions defaultSslOptions) LikecreateQuicClient(QuicClientConfig, ClientSSLOptions), with the default client configuration.createQuicClient(QuicClientConfig config) Create a configured Quic client.createQuicClient(QuicClientConfig config, ClientSSLOptions sslOptions) Create a configured Quic client.createQuicServer(QuicServerConfig config, ServerSSLOptions sslOptions) Create a configured Quic server.createQuicServer(ServerSSLOptions sslOptions) LikecreateQuicServer(QuicServerConfig, ServerSSLOptions), with the default server configuration.createSharedWorkerExecutor(String name, int poolSize) createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime) 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.Create a WebSocket client using default optionsCreate a WebSocket client using the specified optionsstatic ContextGets the current contextReturn a Set of deployment IDs for the currently deployed deploymentIDs.deployVerticle(Deployable verticle) Deploy a verticle instance that you have created yourself.deployVerticle(Deployable verticle, DeploymentOptions options) LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.deployVerticle(String name) Deploy a verticle instance given a name.deployVerticle(String name, DeploymentOptions options) LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.deployVerticle(Supplier<? extends Deployable> supplier, DeploymentOptions options) booleaneventBus()Get the event bus object.exceptionHandler(Handler<Throwable> handler) Set a default exception handler forContext, set onContext.exceptionHandler(Handler)at creation.<T> Maybe<T> executeBlocking(Callable<T> blockingCodeHandler) LikeexecuteBlocking(Callable, boolean)called with ordered = true.<T> Maybe<T> executeBlocking(Callable<T> blockingCodeHandler, boolean ordered) Safely execute some blocking code.Get the filesystem object.Gets the current context, or creates one if there isn't oneinthashCode()Provide a builder for , it can be used to configure advanced HTTP client settings like a redirect handler or a connection handler.Provide a builder for , it can be used to configure advanced HTTP servre settings like a connection handler.booleanIs this Vert.x instance clustered?booleanWhether the metrics are enabled for this measured objectbooleanstatic VertxnewInstance(Vertx arg) voidregisterVerticleFactory(VerticleFactory factory) Register aVerticleFactorythat can be used for deploying Verticles based on an identifier.voidrunOnContext(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.rxClose()Stop the Vertx instance and release any resources held by it.rxClusteredVertx(VertxOptions options) Creates a clustered instance using the specified options.rxDeployVerticle(Deployable verticle) Deploy a verticle instance that you have created yourself.rxDeployVerticle(Deployable verticle, DeploymentOptions options) LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.rxDeployVerticle(String name) Deploy a verticle instance given a name.rxDeployVerticle(String name, DeploymentOptions options) LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.rxDeployVerticle(Supplier<? extends Deployable> supplier, DeploymentOptions options) <T> Maybe<T> rxExecuteBlocking(Callable<T> blockingCodeHandler) LikeexecuteBlocking(Callable, boolean)called with ordered = true.<T> Maybe<T> rxExecuteBlocking(Callable<T> blockingCodeHandler, boolean ordered) Safely execute some blocking code.rxUndeploy(String deploymentID) Undeploy a verticle deployment.longsetPeriodic(long initialDelay, long delay, Handler<Long> handler) Set a periodic timer to fire everydelaymilliseconds with initial delay, at which pointhandlerwill be called with the id of the timer.longsetPeriodic(long delay, Handler<Long> handler) Set a periodic timer to fire everydelaymilliseconds, at which pointhandlerwill be called with the id of the timer.longSet a one-shot timer to fire afterdelaymilliseconds, at which pointhandlerwill be called with the id of the timer.Get the shared data object.timer(long delay) Liketimer(long)with a unit in millis.Create a timer task configured with the specifieddelay, when the timeout fires the timer future is succeeded, when the timeout is cancelled the timer future is failed with aCancellationExceptioninstance.toString()Undeploy a verticle deployment.voidunregisterVerticleFactory(VerticleFactory factory) Unregister aVerticleFactoryReturn the Set of currently registered verticle factories.static Vertxvertx()Creates a non clustered instance using default options.static Vertxvertx(VertxOptions options) Creates a non clustered instance using the specified options
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
Vertx
-
Vertx
-
-
Method Details
-
toString
-
equals
-
hashCode
-
getDelegate
- Specified by:
getDelegatein interfaceMeasured- Specified by:
getDelegatein interfaceio.vertx.lang.rx.RxDelegate
-
isMetricsEnabled
public boolean isMetricsEnabled()Whether the metrics are enabled for this measured object- Specified by:
isMetricsEnabledin interfaceMeasured- Returns:
trueif metrics are enabled
-
builder
Return a builder for Vert.x instances which allows to specify SPI such as cluster manager, metrics or tracing.- Returns:
- a Vert.x instance builder
-
vertx
Creates a non clustered instance using default options.- Returns:
- the instance
-
vertx
Creates a non clustered instance using the specified options- Parameters:
options- the options to use- Returns:
- the instance
-
clusteredVertx
Creates a clustered instance using the specified options.The instance is created asynchronously and the returned future is completed with the result when it is ready.
- Parameters:
options- the options to use- Returns:
- a future completed with the clustered vertx
-
rxClusteredVertx
Creates a clustered instance using the specified options.The instance is created asynchronously and the returned future is completed with the result when it is ready.
- Parameters:
options- the options to use- Returns:
- a future completed with the clustered vertx
-
currentContext
Gets the current context- Returns:
- The current context or
nullif there is no current context
-
getOrCreateContext
Gets the current context, or creates one if there isn't one- Returns:
- The current context (created if didn't exist)
-
createNetServer
Create a TCP/SSL server using the specified config- Parameters:
config- the config to use- Returns:
- the server
-
createNetServer
Create a TCP/SSL server using the specified config and the specified ssl options- Parameters:
config- the config to usesslOptions- the server SSL options- Returns:
- the server
-
createNetServer
Create a TCP/SSL server using the specified options- Parameters:
options- the options to use- Returns:
- the server
-
createNetServer
Create a TCP/SSL server using default options- Returns:
- the server
-
createNetClient
Create a TCP/SSL client using the specified config- Parameters:
config- the config to use- Returns:
- the client
-
createNetClient
Create a TCP/SSL client using the specified config and the specified ssl options- Parameters:
config- the config to usesslOptions- the default client SSL options- Returns:
- the client
-
createNetClient
Create a TCP/SSL client using the specified options- Parameters:
options- the options to use- Returns:
- the client
-
createNetClient
Create a TCP/SSL client using default options- Returns:
- the client
-
createQuicServer
Create a configured Quic server.
The returned server can be bound, after setting a connection
- Parameters:
config- the server configurationsslOptions- the server SSL options- Returns:
- the server
-
createQuicServer
LikecreateQuicServer(QuicServerConfig, ServerSSLOptions), with the default server configuration.- Parameters:
sslOptions-- Returns:
-
createQuicClient
Create a configured Quic client.
- Parameters:
config- the client configurationsslOptions- the default client SSL options- Returns:
- the client
-
createQuicClient
LikecreateQuicClient(QuicClientConfig, ClientSSLOptions), with the default client configuration.- Parameters:
defaultSslOptions-- Returns:
-
createQuicClient
Create a configured Quic client.
- Parameters:
config- the client configuration- Returns:
- the client
-
createHttpServer
Create an HTTP/HTTPS server using the specifiedoptions- Parameters:
options- the options to use- Returns:
- the server
-
createHttpServer
Create an HTTP server using the specifiedconfig.- Parameters:
config- the config to use- Returns:
- the server
-
createHttpServer
Create an HTTP server using the specified config and the specifiedsslOptions- Parameters:
config- the config to usesslOptions- the ssl options to use- Returns:
- the server
-
createHttpServer
Create an HTTP server using default config and the specifiedsslOptions.- Parameters:
sslOptions- the ssl options to use- Returns:
- the server
-
createHttpServer
Create an HTTP/HTTPS server using default config.- Returns:
- the server
-
httpServerBuilder
Provide a builder for , it can be used to configure advanced HTTP servre settings like a connection handler.Example usage:
HttpServer server = vertx.httpServerBuilder().with(options).withConnectHandler(conn -> ...).build()- Returns:
-
createWebSocketClient
Create a WebSocket client using default options- Returns:
- the client
-
createWebSocketClient
Create a WebSocket client using the specified options- Parameters:
options- the options to use- Returns:
- the client
-
httpClientBuilder
Provide a builder for , it can be used to configure advanced HTTP client settings like a redirect handler or a connection handler.Example usage:
HttpClient client = vertx.httpClientBuilder().with(options).withConnectHandler(conn -> ...).build()- Returns:
-
createHttpClient
Create a HTTP/HTTPS client using the specified client and pool options- Parameters:
clientConfig- the client config to usepoolOptions- the pool options to use- Returns:
- the client
-
createHttpClient
public HttpClientAgent createHttpClient(HttpClientConfig clientConfig, ClientSSLOptions sslOptions, PoolOptions poolOptions) Create a HTTP/HTTPS client using the specified client, ssl options and pool options- Parameters:
clientConfig- the client config to usesslOptions- the ssl options to usepoolOptions- the pool options to use- Returns:
- the client
-
createHttpClient
Create a HTTP/HTTPS client using the specified client and ssl options- Parameters:
clientConfig- the client config to usesslOptions- the ssl options to use- Returns:
- the client
-
createHttpClient
Create a HTTP/HTTPS client using the specified client and pool options- Parameters:
clientOptions- the client options to usepoolOptions- the pool options to use- Returns:
- the client
-
createHttpClient
Create an HTTP/HTTPS client using the specified config- Parameters:
config- the config to use- Returns:
- the server
-
createHttpClient
Create a HTTP/HTTPS client using the specified client options- Parameters:
clientOptions- the options to use- Returns:
- the client
-
createHttpClient
Create a HTTP/HTTPS client using the specified pool options- Parameters:
poolOptions- the pool options to use- Returns:
- the client
-
createHttpClient
Create a HTTP/HTTPS client using default options- Returns:
- the client
-
createDatagramSocket
Create a datagram socket using the specified options- Parameters:
options- the options to use- Returns:
- the socket
-
createDatagramSocket
Create a datagram socket using default options- Returns:
- the socket
-
fileSystem
Get the filesystem object. There is a single instance of FileSystem per Vertx instance.- Returns:
- the filesystem object
-
eventBus
Get the event bus object. There is a single instance of EventBus per Vertx instance.- Returns:
- the event bus object
-
createDnsClient
-
createDnsClient
Create a DNS client to connect to the DNS server configured byVertxOptionsDNS client takes the first configured resolver address provided by }
- Returns:
- the DNS client
-
createDnsClient
Create a DNS client to connect to a DNS server- Parameters:
options- the client options- Returns:
- the DNS client
-
timer
-
timer
Create a timer task configured with the specifieddelay, when the timeout fires the timer future is succeeded, when the timeout is cancelled the timer future is failed with aCancellationExceptioninstance.- Parameters:
delay- the delayunit- the delay unit- Returns:
- the timer object
-
setTimer
Set a one-shot timer to fire afterdelaymilliseconds, at which pointhandlerwill be called with the id of the timer.- Parameters:
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- Returns:
- the unique ID of the timer
-
setPeriodic
Set a periodic timer to fire everydelaymilliseconds, at which pointhandlerwill be called with the id of the timer.- Parameters:
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- Returns:
- the unique ID of the timer
-
setPeriodic
Set a periodic timer to fire everydelaymilliseconds with initial delay, at which pointhandlerwill be called with the id of the timer.- Parameters:
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- Returns:
- the unique ID of the timer
-
cancelTimer
public boolean cancelTimer(long id) Cancels the timer with the specifiedid.- Parameters:
id- The id of the timer to cancel- Returns:
- true if the timer was successfully cancelled, or false if the timer does not exist.
-
runOnContext
-
close
Stop 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.
- Returns:
- a future completed with the result
-
rxClose
Stop 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.
- Returns:
- a future completed with the result
-
deployVerticle
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.
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- the name.- Returns:
- a future completed with the result
-
rxDeployVerticle
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.
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- the name.- Returns:
- a future completed with the result
-
deployVerticle
LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.- Parameters:
name- the nameoptions- the deployment options.- Returns:
- a future completed with the result
-
rxDeployVerticle
LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.- Parameters:
name- the nameoptions- the deployment options.- Returns:
- a future completed with the result
-
undeploy
Undeploy a verticle deployment.The actual undeployment happens asynchronously and may not complete until after the method has returned.
- Parameters:
deploymentID- the deployment ID- Returns:
- a future completed with the result
-
rxUndeploy
Undeploy a verticle deployment.The actual undeployment happens asynchronously and may not complete until after the method has returned.
- Parameters:
deploymentID- the deployment ID- Returns:
- a future completed with the result
-
deploymentIDs
-
isClustered
public boolean isClustered()Is this Vert.x instance clustered?- Returns:
- true if clustered
-
isNativeTransportEnabled
public boolean isNativeTransportEnabled()- Returns:
- whether the native transport is used
-
exceptionHandler
Set a default exception handler forContext, set onContext.exceptionHandler(Handler)at creation.- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
deployVerticle
Deploy a verticle instance that you have created yourself.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.
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- the verticle instance to deploy.- Returns:
- a future completed with the result
-
rxDeployVerticle
Deploy a verticle instance that you have created yourself.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.
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- the verticle instance to deploy.- Returns:
- a future completed with the result
-
deployVerticle
LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.- Parameters:
verticle- the verticle instance to deployoptions- the deployment options.- Returns:
- a future completed with the result
-
rxDeployVerticle
LikedeployVerticle(String)butDeploymentOptionsare provided to configure the deployment.- Parameters:
verticle- the verticle instance to deployoptions- the deployment options.- Returns:
- a future completed with the result
-
deployVerticle
public Single<String> deployVerticle(Supplier<? extends Deployable> supplier, DeploymentOptions options) LikedeployVerticle(String)butDeployableinstance is created by invoking theverticleSupplier.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:
supplier-options-- Returns:
- a future completed with the result
-
rxDeployVerticle
public Single<String> rxDeployVerticle(Supplier<? extends Deployable> supplier, DeploymentOptions options) LikedeployVerticle(String)butDeployableinstance is created by invoking theverticleSupplier.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:
supplier-options-- Returns:
- a future completed with the result
-
registerVerticleFactory
Register aVerticleFactorythat can be used for deploying Verticles based on an identifier.- Parameters:
factory- the factory to register
-
unregisterVerticleFactory
Unregister aVerticleFactory- Parameters:
factory- the factory to unregister
-
verticleFactories
Return the Set of currently registered verticle factories.- Returns:
- the set of verticle factories
-
executeBlocking
Safely execute some blocking code.Executes the blocking code in the handler
blockingCodeHandlerusing 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
blockingCodeHandlerthe current context remains the original context and therefore any task scheduled in theblockingCodeHandlerwill 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)- Parameters:
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 guarantees- Returns:
- a future completed when the blocking code is complete
-
rxExecuteBlocking
Safely execute some blocking code.Executes the blocking code in the handler
blockingCodeHandlerusing 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
blockingCodeHandlerthe current context remains the original context and therefore any task scheduled in theblockingCodeHandlerwill 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)- Parameters:
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 guarantees- Returns:
- a future completed when the blocking code is complete
-
executeBlocking
LikeexecuteBlocking(Callable, boolean)called with ordered = true.- Parameters:
blockingCodeHandler-- Returns:
-
rxExecuteBlocking
LikeexecuteBlocking(Callable, boolean)called with ordered = true.- Parameters:
blockingCodeHandler-- Returns:
-
newInstance
-