Class Vertx

  • All Implemented Interfaces:
    Measured

    public class Vertx
    extends Object
    implements Measured
    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.

    To create an instance of this class you can use the static factory methods: vertx(), vertx() and clusteredVertx(io.vertx.core.VertxOptions).

    Please see the user manual for more detailed usage information.

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Field Detail

    • Constructor Detail

      • Vertx

        public Vertx​(io.vertx.core.Vertx delegate)
      • Vertx

        public Vertx​(Object delegate)
    • Method Detail

      • getDelegate

        public io.vertx.core.Vertx getDelegate()
        Specified by:
        getDelegate in interface Measured
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isMetricsEnabled

        public boolean isMetricsEnabled()
        Specified by:
        isMetricsEnabled in interface Measured
        Returns:
        true if metrics are enabled
      • vertx

        public static Vertx vertx()
        Returns:
        the instance
      • vertx

        public static Vertx vertx​(io.vertx.core.VertxOptions options)
        Parameters:
        options - the options to use
        Returns:
        the instance
      • clusteredVertx

        @CheckReturnValue
        public static io.smallrye.mutiny.Uni<Vertx> clusteredVertx​(io.vertx.core.VertxOptions options)
        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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        options - the options to use
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • clusteredVertxAndAwait

        public static Vertx clusteredVertxAndAwait​(io.vertx.core.VertxOptions options)
        Blocking variant of clusteredVertx(VertxOptions).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        options - the options to use
        Returns:
        the Vertx instance produced by the operation.
      • clusteredVertxAndForget

        public static void clusteredVertxAndForget​(io.vertx.core.VertxOptions options)
        Variant of clusteredVertx(VertxOptions) that ignores the result of the operation.

        This method subscribes on the result of clusteredVertx(VertxOptions), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from clusteredVertx(VertxOptions) but you don't need to compose it with other operations.

        Parameters:
        options - the options to use
      • currentContext

        public static Context currentContext()
        Returns:
        The current context or null if there is no current context
      • getOrCreateContext

        public Context getOrCreateContext()
        Returns:
        The current context (created if didn't exist)
      • createNetServer

        public NetServer createNetServer​(io.vertx.core.net.NetServerOptions options)
        Parameters:
        options - the options to use
        Returns:
        the server
      • createNetServer

        public NetServer createNetServer()
        Returns:
        the server
      • createNetClient

        public NetClient createNetClient​(io.vertx.core.net.NetClientOptions options)
        Parameters:
        options - the options to use
        Returns:
        the client
      • createNetClient

        public NetClient createNetClient()
        Returns:
        the client
      • createHttpServer

        public HttpServer createHttpServer​(io.vertx.core.http.HttpServerOptions options)
        Parameters:
        options - the options to use
        Returns:
        the server
      • createHttpServer

        public HttpServer createHttpServer()
        Returns:
        the server
      • createHttpClient

        public HttpClient createHttpClient​(io.vertx.core.http.HttpClientOptions options)
        Parameters:
        options - the options to use
        Returns:
        the client
      • createHttpClient

        public HttpClient createHttpClient()
        Returns:
        the client
      • createDatagramSocket

        public DatagramSocket createDatagramSocket​(io.vertx.core.datagram.DatagramSocketOptions options)
        Parameters:
        options - the options to use
        Returns:
        the socket
      • createDatagramSocket

        public DatagramSocket createDatagramSocket()
        Returns:
        the socket
      • fileSystem

        public FileSystem fileSystem()
        Returns:
        the filesystem object
      • eventBus

        public EventBus eventBus()
        Returns:
        the event bus object
      • createDnsClient

        public DnsClient createDnsClient​(int port,
                                         String host)
        Parameters:
        port - the port
        host - the host
        Returns:
        the DNS client
      • createDnsClient

        public DnsClient createDnsClient()
        Returns:
        the DNS client
      • createDnsClient

        public DnsClient createDnsClient​(io.vertx.core.dns.DnsClientOptions options)
        Parameters:
        options - the client options
        Returns:
        the DNS client
      • sharedData

        public SharedData sharedData()
        Returns:
        the shared data object
      • setTimer

        public long setTimer​(long delay,
                             Consumer<Long> handler)
        Parameters:
        delay - the delay in milliseconds, after which the timer will fire
        handler - the handler that will be called with the timer ID when the timer fires
        Returns:
      • timerStream

        public TimeoutStream timerStream​(long delay)
        Parameters:
        delay - the delay in milliseconds, after which the timer will fire
        Returns:
        the timer stream
      • setPeriodic

        public long setPeriodic​(long delay,
                                Consumer<Long> handler)
        Parameters:
        delay - the delay in milliseconds, after which the timer will fire
        handler - the handler that will be called with the timer ID when the timer fires
        Returns:
      • periodicStream

        public TimeoutStream periodicStream​(long delay)
        Parameters:
        delay - the delay in milliseconds, after which the timer will fire
        Returns:
        the periodic stream
      • cancelTimer

        public boolean cancelTimer​(long id)
        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

        public void runOnContext​(Runnable action)
        Parameters:
        action - - a handler representing the action to execute
      • close

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Void> close()
        Like close() but the completionHandler will be called when the close is complete

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • closeAndAwait

        public Void closeAndAwait()
        Blocking variant of close().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the Void instance produced by the operation.
      • closeAndForget

        public void closeAndForget()
        Variant of close() that ignores the result of the operation.

        This method subscribes on the result of close(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from close() but you don't need to compose it with other operations.

      • deployVerticle

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<String> deployVerticle​(String name)
        Like deployVerticle(java.lang.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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        name - The identifier
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • deployVerticleAndAwait

        public String deployVerticleAndAwait​(String name)
        Blocking variant of deployVerticle(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        name - The identifier
        Returns:
        the String instance produced by the operation.
      • deployVerticleAndForget

        public void deployVerticleAndForget​(String name)
        Variant of deployVerticle(String) that ignores the result of the operation.

        This method subscribes on the result of deployVerticle(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from deployVerticle(String) but you don't need to compose it with other operations.

        Parameters:
        name - The identifier
      • deployVerticle

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<String> deployVerticle​(String name,
                                                             io.vertx.core.DeploymentOptions options)
        Like deployVerticle(java.lang.String) but DeploymentOptions are provided to configure the deployment.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        name - the name
        options - the deployment options.
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • deployVerticleAndAwait

        public String deployVerticleAndAwait​(String name,
                                             io.vertx.core.DeploymentOptions options)
        Blocking variant of deployVerticle(String,DeploymentOptions).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        name - the name
        options - the deployment options.
        Returns:
        the String instance produced by the operation.
      • undeploy

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Void> undeploy​(String deploymentID)
        Like #undeploy(String) but the completionHandler will be notified when the undeployment is complete.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        deploymentID - the deployment ID
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • undeployAndAwait

        public Void undeployAndAwait​(String deploymentID)
        Blocking variant of undeploy(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        deploymentID - the deployment ID
        Returns:
        the Void instance produced by the operation.
      • undeployAndForget

        public void undeployAndForget​(String deploymentID)
        Variant of undeploy(String) that ignores the result of the operation.

        This method subscribes on the result of undeploy(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from undeploy(String) but you don't need to compose it with other operations.

        Parameters:
        deploymentID - the deployment ID
      • deploymentIDs

        public Set<String> deploymentIDs()
        Returns:
        Set of deployment IDs
      • isClustered

        public boolean isClustered()
        Returns:
        true if clustered
      • executeBlocking

        @CheckReturnValue
        public <T> io.smallrye.mutiny.Uni<T> executeBlocking​(io.smallrye.mutiny.Uni<T> blockingCodeHandler,
                                                             boolean ordered)
        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 Promise.complete(T) or Promise.complete(T) 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 the 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(java.lang.Runnable)

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        blockingCodeHandler - handler representing the blocking code to run
        ordered - 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:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • executeBlockingAndAwait

        public <T> T executeBlockingAndAwait​(io.smallrye.mutiny.Uni<T> blockingCodeHandler,
                                             boolean ordered)
        Blocking variant of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer,boolean).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        blockingCodeHandler - handler representing the blocking code to run
        ordered - 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:
        the T instance produced by the operation.
      • executeBlockingAndForget

        public <T> void executeBlockingAndForget​(io.smallrye.mutiny.Uni<T> blockingCodeHandler,
                                                 boolean ordered)
        Variant of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer,boolean) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer,boolean), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.Vertx#executeBlocking(Consumer,boolean) but you don't need to compose it with other operations.

        Parameters:
        blockingCodeHandler - handler representing the blocking code to run
        ordered - 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
      • executeBlocking

        @CheckReturnValue
        public <T> io.smallrye.mutiny.Uni<T> executeBlocking​(io.smallrye.mutiny.Uni<T> blockingCodeHandler)
        Like executeBlocking(io.smallrye.mutiny.Uni<T>, boolean) called with ordered = true.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        blockingCodeHandler -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • executeBlockingAndAwait

        public <T> T executeBlockingAndAwait​(io.smallrye.mutiny.Uni<T> blockingCodeHandler)
        Blocking variant of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        blockingCodeHandler -
        Returns:
        the T instance produced by the operation.
      • executeBlockingAndForget

        public <T> void executeBlockingAndForget​(io.smallrye.mutiny.Uni<T> blockingCodeHandler)
        Variant of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.Vertx#executeBlocking(Consumer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.Vertx#executeBlocking(Consumer) but you don't need to compose it with other operations.

        Parameters:
        blockingCodeHandler -
      • createSharedWorkerExecutor

        public WorkerExecutor createSharedWorkerExecutor​(String name)
        Parameters:
        name -
        Returns:
      • createSharedWorkerExecutor

        public WorkerExecutor createSharedWorkerExecutor​(String name,
                                                         int poolSize)
        Parameters:
        name -
        poolSize -
        Returns:
      • createSharedWorkerExecutor

        public WorkerExecutor createSharedWorkerExecutor​(String name,
                                                         int poolSize,
                                                         long maxExecuteTime)
        Parameters:
        name -
        poolSize -
        maxExecuteTime -
        Returns:
      • createSharedWorkerExecutor

        public WorkerExecutor createSharedWorkerExecutor​(String name,
                                                         int poolSize,
                                                         long maxExecuteTime,
                                                         TimeUnit maxExecuteTimeUnit)
        Parameters:
        name - the name of the worker executor
        poolSize - the size of the pool
        maxExecuteTime - the value of max worker execute time
        maxExecuteTimeUnit - the value of unit of max worker execute time
        Returns:
        the named worker executor
      • isNativeTransportEnabled

        public boolean isNativeTransportEnabled()
        Returns:
        whether the native transport is used
      • exceptionHandler

        public Vertx exceptionHandler​(Consumer<Throwable> handler)
        Parameters:
        handler - the exception handler
        Returns:
      • deployVerticle

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<String> deployVerticle​(io.vertx.core.Verticle verticle)
        Like deployVerticle(java.lang.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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        verticle - the verticle instance to deploy
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • deployVerticleAndAwait

        public String deployVerticleAndAwait​(io.vertx.core.Verticle verticle)
        Blocking variant of deployVerticle(Verticle).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        verticle - the verticle instance to deploy
        Returns:
        the String instance produced by the operation.
      • deployVerticleAndForget

        public void deployVerticleAndForget​(io.vertx.core.Verticle verticle)
        Variant of deployVerticle(Verticle) that ignores the result of the operation.

        This method subscribes on the result of deployVerticle(Verticle), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from deployVerticle(Verticle) but you don't need to compose it with other operations.

        Parameters:
        verticle - the verticle instance to deploy
      • deployVerticle

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<String> deployVerticle​(io.vertx.core.Verticle verticle,
                                                             io.vertx.core.DeploymentOptions options)
        Like deployVerticle(java.lang.String) but DeploymentOptions are provided to configure the deployment.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        verticle - the verticle instance to deploy
        options - the deployment options.
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • deployVerticleAndAwait

        public String deployVerticleAndAwait​(io.vertx.core.Verticle verticle,
                                             io.vertx.core.DeploymentOptions options)
        Blocking variant of deployVerticle(Verticle,DeploymentOptions).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        verticle - the verticle instance to deploy
        options - the deployment options.
        Returns:
        the String instance produced by the operation.
      • deployVerticle

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<String> deployVerticle​(Supplier<io.vertx.core.Verticle> verticleSupplier,
                                                             io.vertx.core.DeploymentOptions options)
        Like deployVerticle(java.lang.String) but Verticle instance is created by invoking the verticleSupplier.

        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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        verticleSupplier -
        options -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • deployVerticleAndAwait

        public String deployVerticleAndAwait​(Supplier<io.vertx.core.Verticle> verticleSupplier,
                                             io.vertx.core.DeploymentOptions options)
        Blocking variant of deployVerticle(Supplier,DeploymentOptions).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        verticleSupplier -
        options -
        Returns:
        the String instance produced by the operation.
      • registerVerticleFactory

        public void registerVerticleFactory​(io.vertx.core.spi.VerticleFactory factory)
        Parameters:
        factory - the factory to register
      • unregisterVerticleFactory

        public void unregisterVerticleFactory​(io.vertx.core.spi.VerticleFactory factory)
        Parameters:
        factory - the factory to unregister
      • verticleFactories

        public Set<io.vertx.core.spi.VerticleFactory> verticleFactories()
        Returns:
        the set of verticle factories
      • nettyEventLoopGroup

        public io.netty.channel.EventLoopGroup nettyEventLoopGroup()
        Returns:
        the EventLoopGroup
      • newInstance

        public static Vertx newInstance​(io.vertx.core.Vertx arg)