io.vertx.core

## Interface Vertx

- All Superinterfaces:
    Measured

      public interface Vertx
      extends 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(io.vertx.core.VertxOptions)` and `clusteredVertx(io.vertx.core.VertxOptions, Handler)`.

  Please see the user manual for more detailed usage information.

  Author:
    Tim Fox

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static VertxFactory` | `factory`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method 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(Handler<AsyncResult<Void>> completionHandler)` Like `close()` but the completionHandler will be called when the close is complete
    `static void` | `clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler)` Creates a clustered instance using the specified options.
    `DatagramSocket` | `createDatagramSocket()` Create a datagram socket using default options
    `DatagramSocket` | `createDatagramSocket(DatagramSocketOptions options)` Create a datagram socket using the specified options
    `DnsClient` | `createDnsClient(int port, String host)` Create a DNS client to connect to a DNS server at the specified host and port
    `HttpClient` | `createHttpClient()` Create a HTTP/HTTPS client using default options
    `HttpClient` | `createHttpClient(HttpClientOptions options)` Create a HTTP/HTTPS client using the specified options
    `HttpServer` | `createHttpServer()` Create an HTTP/HTTPS server using default options
    `HttpServer` | `createHttpServer(HttpServerOptions options)` Create an HTTP/HTTPS server using the specified options
    `NetClient` | `createNetClient()` Create a TCP/SSL client using default options
    `NetClient` | `createNetClient(NetClientOptions options)` Create a TCP/SSL client using the specified options
    `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)` 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.
    `void` | `deployVerticle(String name)` Deploy a verticle instance given a name.
    `void` | `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.
    `void` | `deployVerticle(String name, Handler<AsyncResult<String>> completionHandler)` Like `deployVerticle(String)` but the completionHandler will be notified when the deployment is complete.
    `void` | `deployVerticle(Verticle verticle)` Deploy a verticle instance that you have created yourself.
    `void` | `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.
    `<T> void` | `executeBlocking(Handler<Future<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)` Safely execute some blocking code.
    `<T> void` | `executeBlocking(Handler<Future<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)` Like `executeBlocking(Handler, boolean, Handler)` called with ordered = true.
    `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?
    `EventLoopGroup` | `nettyEventLoopGroup()` Return the Netty EventLoopGroup used by Vert.x
    `TimeoutStream` | `periodicStream(long delay)` Returns a periodic timer as a read stream.
    `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.
    `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` | `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)` Returns a one-shot timer as a read stream.
    `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

    - ### Methods inherited from interface io.vertx.core.metrics.Measured

      `isMetricsEnabled`

- - ### Field Detail

    - #### factory

          static final VertxFactory factory

  - ### Method Detail

    - #### vertx

          static Vertx vertx()

      Creates a non clustered instance using default options.
      Returns:
        the instance

    - #### vertx

          static Vertx vertx(VertxOptions options)

      Creates a non clustered instance using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the instance

    - #### clusteredVertx

          static void clusteredVertx(VertxOptions options,
                                     Handler<AsyncResult<Vertx>> resultHandler)

      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.

      Parameters:
        `options` - the options to use
        `resultHandler` - the result handler that will receive the result

    - #### currentContext

          static Context currentContext()

      Gets the current context
      Returns:
        The current context or null if no current context

    - #### getOrCreateContext

          Context getOrCreateContext()

      Gets the current context, or creates one if there isn't one
      Returns:
        The current context (created if didn't exist)

    - #### createNetServer

          NetServer createNetServer(NetServerOptions options)

      Create a TCP/SSL server using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the server

    - #### createNetServer

          NetServer createNetServer()

      Create a TCP/SSL server using default options
      Returns:
        the server

    - #### createNetClient

          NetClient createNetClient(NetClientOptions options)

      Create a TCP/SSL client using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the client

    - #### createNetClient

          NetClient createNetClient()

      Create a TCP/SSL client using default options
      Returns:
        the client

    - #### createHttpServer

          HttpServer createHttpServer(HttpServerOptions options)

      Create an HTTP/HTTPS server using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the server

    - #### createHttpServer

          HttpServer createHttpServer()

      Create an HTTP/HTTPS server using default options
      Returns:
        the server

    - #### createHttpClient

          HttpClient createHttpClient(HttpClientOptions options)

      Create a HTTP/HTTPS client using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the client

    - #### createHttpClient

          HttpClient createHttpClient()

      Create a HTTP/HTTPS client using default options
      Returns:
        the client

    - #### createDatagramSocket

          DatagramSocket createDatagramSocket(DatagramSocketOptions options)

      Create a datagram socket using the specified options
      Parameters:
        `options` - the options to use
      Returns:
        the socket

    - #### createDatagramSocket

          DatagramSocket createDatagramSocket()

      Create a datagram socket using default options
      Returns:
        the socket

    - #### fileSystem

          FileSystem fileSystem()

      Get the filesystem object. There is a single instance of FileSystem per Vertx instance.
      Returns:
        the filesystem object

    - #### eventBus

          EventBus eventBus()

      Get the event bus object. There is a single instance of EventBus per Vertx instance.
      Returns:
        the event bus object

    - #### createDnsClient

          DnsClient createDnsClient(int port,
                                    String host)

      Create a DNS client to connect to a DNS server at the specified host and port
      Parameters:
        `port` - the port
        `host` - the host
      Returns:
        the DNS client

    - #### sharedData

          SharedData sharedData()

      Get the shared data object. There is a single instance of SharedData per Vertx instance.
      Returns:
        the shared data object

    - #### setTimer

          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.
      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:
        the unique ID of the timer

    - #### timerStream

          TimeoutStream timerStream(long delay)

      Returns a one-shot timer as a read stream. The timer will be fired after `delay` milliseconds after the `ReadStream.handler(io.vertx.core.Handler<T>)` has been called.
      Parameters:
        `delay` - the delay in milliseconds, after which the timer will fire
      Returns:
        the timer stream

    - #### setPeriodic

          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.
      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:
        the unique ID of the timer

    - #### periodicStream

          TimeoutStream periodicStream(long delay)

      Returns a periodic timer as a read stream. The timer will be fired every `delay` milliseconds after the `ReadStream.handler(io.vertx.core.Handler<T>)` has been called.
      Parameters:
        `delay` - the delay in milliseconds, after which the timer will fire
      Returns:
        the periodic stream

    - #### cancelTimer

          boolean cancelTimer(long id)

      Cancels the timer with the specified `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

          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.
      Parameters:
        `action` - - a handler representing the action to execute

    - #### close

          void close()

      Stop 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.

    - #### close

          void close(Handler<AsyncResult<Void>> completionHandler)

      Like `close()` but the completionHandler will be called when the close is complete
      Parameters:
        `completionHandler` - The handler will be notified when the close is complete.

    - #### deployVerticle

          void deployVerticle(Verticle verticle)

      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.

      Parameters:
        `verticle` - the verticle instance to deploy.

    - #### deployVerticle

          void deployVerticle(Verticle verticle,
                              Handler<AsyncResult<String>> completionHandler)

      Like `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.

      Parameters:
        `verticle` - the verticle instance to deploy
        `completionHandler` - a handler which will be notified when the deployment is complete

    - #### deployVerticle

          void deployVerticle(Verticle verticle,
                              DeploymentOptions options)

      Like `deployVerticle(Verticle)` but `DeploymentOptions` are provided to configure the deployment.
      Parameters:
        `verticle` - the verticle instance to deploy
        `options` - the deployment options.

    - #### deployVerticle

          void deployVerticle(Verticle verticle,
                              DeploymentOptions options,
                              Handler<AsyncResult<String>> completionHandler)

      Like `deployVerticle(Verticle, Handler)` but `DeploymentOptions` are provided to configure the deployment.
      Parameters:
        `verticle` - the verticle instance to deploy
        `options` - the deployment options.
        `completionHandler` - a handler which will be notified when the deployment is complete

    - #### deployVerticle

          void deployVerticle(String name)

      Deploy a verticle instance given a 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.

      Parameters:
        `name` - the name.

    - #### deployVerticle

          void deployVerticle(String name,
                              Handler<AsyncResult<String>> completionHandler)

      Like `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.

      Parameters:
        `name` - The identifier
        `completionHandler` - a handler which will be notified when the deployment is complete

    - #### deployVerticle

          void deployVerticle(String name,
                              DeploymentOptions options)

      Like `deployVerticle(Verticle)` but `DeploymentOptions` are provided to configure the deployment.
      Parameters:
        `name` - the name
        `options` - the deployment options.

    - #### deployVerticle

          void deployVerticle(String name,
                              DeploymentOptions options,
                              Handler<AsyncResult<String>> completionHandler)

      Like `deployVerticle(String, Handler)` but `DeploymentOptions` are provided to configure the deployment.
      Parameters:
        `name` - the name
        `options` - the deployment options.
        `completionHandler` - a handler which will be notified when the deployment is complete

    - #### undeploy

          void undeploy(String deploymentID)

      Undeploy a verticle deployment.

      The actual undeployment happens asynchronously and may not complete until after the method has returned.

      Parameters:
        `deploymentID` - the deployment ID

    - #### undeploy

          void undeploy(String deploymentID,
                        Handler<AsyncResult<Void>> completionHandler)

      Like `undeploy(String)` but the completionHandler will be notified when the undeployment is complete.
      Parameters:
        `deploymentID` - the deployment ID
        `completionHandler` - a handler which will be notified when the undeployment is complete

    - #### deploymentIDs

          Set<String> deploymentIDs()

      Return a Set of deployment IDs for the currently deployed deploymentIDs.
      Returns:
        Set of deployment IDs

    - #### registerVerticleFactory

          void registerVerticleFactory(VerticleFactory factory)

      Register a `VerticleFactory` that can be used for deploying Verticles based on an identifier.
      Parameters:
        `factory` - the factory to register

    - #### unregisterVerticleFactory

          void unregisterVerticleFactory(VerticleFactory factory)

      Unregister a `VerticleFactory`
      Parameters:
        `factory` - the factory to unregister

    - #### verticleFactories

          Set<VerticleFactory> verticleFactories()

      Return the Set of currently registered verticle factories.
      Returns:
        the set of verticle factories

    - #### isClustered

          boolean isClustered()

      Is this Vert.x instance clustered?
      Returns:
        true if clustered

    - #### executeBlocking

          <T> void executeBlocking(Handler<Future<T>> blockingCodeHandler,
                                   boolean ordered,
                                   Handler<AsyncResult<T>> 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 into `blockingCodeHandler`. When the blocking code successfully completes, the handler should call the `Future.complete(T)` or `Future.complete(Object)` method, or the `Future.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.

      Type Parameters:
        `T` - the type of the result
      Parameters:
        `blockingCodeHandler` - handler representing the blocking code to run
        `resultHandler` - handler that will be called when the blocking code is complete
        `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

          <T> void executeBlocking(Handler<Future<T>> blockingCodeHandler,
                                   Handler<AsyncResult<T>> resultHandler)

      Like `executeBlocking(Handler, boolean, Handler)` called with ordered = true.

    - #### nettyEventLoopGroup

          EventLoopGroup nettyEventLoopGroup()

      Return the Netty EventLoopGroup used by Vert.x
      Returns:
        the EventLoopGroup

    - #### createSharedWorkerExecutor

          WorkerExecutor createSharedWorkerExecutor(String name)

      Like `createSharedWorkerExecutor(String, int)` but with the `VertxOptions.setWorkerPoolSize(int)` `poolSize`.

    - #### createSharedWorkerExecutor

          WorkerExecutor createSharedWorkerExecutor(String name,
                                                    int poolSize)

      Like `createSharedWorkerExecutor(String, int, long)` but with the `VertxOptions.setMaxWorkerExecuteTime(long)` `maxExecuteTime`.

    - #### createSharedWorkerExecutor

          WorkerExecutor createSharedWorkerExecutor(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.

      This method can be called mutiple times with the same `name`. 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.

      Parameters:
        `name` - the name of the worker executor
        `poolSize` - the size of the pool
        `maxExecuteTime` - the value of max worker execute time, in ms
      Returns:
        the named worker executor

    - #### exceptionHandler

          Vertx exceptionHandler(Handler<Throwable> handler)

      Set a default exception handler for `Context`, set on `Context.exceptionHandler(Handler)` at creation.
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### exceptionHandler

          Handler<Throwable> exceptionHandler()

      Returns:
        the current default exception handler

Copyright © 2016. All rights reserved.