Package: io.vertx.groovy.core

## [Groovy] Class Vertx

- io.vertx.groovy.core.Vertx

- All Implemented Interfaces and Traits:
    Measured

      @groovy.transform.CompileStatic
      class Vertx
      extends java.lang.Object

  The entry point into the Vert.x Core API.

  You use an instance of this class for functionality including:

  - 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, Vertx.vertx and Vertx.clusteredVertx.

  Please see the user manual for more detailed usage information.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `Vertx (java.lang.Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `boolean` | `cancelTimer(long id)` Cancels the timer with the specified `id`.
    `void` | `close()` Stop the the Vertx instance and release any resources held by it.
    `void` | `close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler)` Like Vertx.close but the completionHandler will be called when the close is complete
    `static void` | `clusteredVertx(java.util.Map<java.lang.String, java.lang.Object> options = [:], io.vertx.core.Handler<io.vertx.core.AsyncResult<Vertx>> resultHandler)` Creates a clustered instance using the specified options.
    `DatagramSocket` | `createDatagramSocket(java.util.Map<java.lang.String, java.lang.Object> options)` Create a datagram socket using the specified options
    `DatagramSocket` | `createDatagramSocket()` Create a datagram socket using default options
    `DnsClient` | `createDnsClient(int port, java.lang.String host)` Create a DNS client to connect to a DNS server at the specified host and port
    `HttpClient` | `createHttpClient(java.util.Map<java.lang.String, java.lang.Object> options)` Create a HTTP/HTTPS client using the specified options
    `HttpClient` | `createHttpClient()` Create a HTTP/HTTPS client using default options
    `HttpServer` | `createHttpServer(java.util.Map<java.lang.String, java.lang.Object> options)` Create an HTTP/HTTPS server using the specified options
    `HttpServer` | `createHttpServer()` Create an HTTP/HTTPS server using default options
    `NetClient` | `createNetClient(java.util.Map<java.lang.String, java.lang.Object> options)` Create a TCP/SSL client using the specified options
    `NetClient` | `createNetClient()` Create a TCP/SSL client using default options
    `NetServer` | `createNetServer(java.util.Map<java.lang.String, java.lang.Object> options)` Create a TCP/SSL server using the specified options
    `NetServer` | `createNetServer()` Create a TCP/SSL server using default options
    `WorkerExecutor` | `createSharedWorkerExecutor(java.lang.String name)` Like Vertx.createSharedWorkerExecutor but with the | `WorkerExecutor` | `createSharedWorkerExecutor(java.lang.String name, int poolSize)` Like Vertx.createSharedWorkerExecutor but with the | `WorkerExecutor` | `createSharedWorkerExecutor(java.lang.String name, int poolSize, long maxExecuteTime)` Create a named worker executor, the executor should be closed when it's not needed anymore to release resources.
    `static Context` | `currentContext()` Gets the current context
    `void` | `deployVerticle(java.lang.String name)` Deploy a verticle instance given a name.
    `void` | `deployVerticle(java.lang.String name, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler)` Like Vertx.deployVerticle but the completionHandler will be notified when the deployment is complete.
    `void` | `deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options)` Like Vertx.deployVerticle but | `void` | `deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler)` Like Vertx.deployVerticle but | `java.util.Set<java.lang.String>` | `deploymentIDs()` Return a Set of deployment IDs for the currently deployed deploymentIDs.
    `EventBus` | `eventBus()` Get the event bus object.
    `Vertx` | `exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)` Set a default exception handler for Context, set on at creation.
    `void` | `executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, boolean ordered, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)` Safely execute some blocking code.
    `void` | `executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)` Like Vertx.executeBlocking called with ordered = true.
    `FileSystem` | `fileSystem()` Get the filesystem object.
    `java.lang.Object` | `getDelegate()`
    `Context` | `getOrCreateContext()` Gets the current context, or creates one if there isn't one
    `boolean` | `isClustered()` Is this Vert.x instance clustered?
    `boolean` | `isMetricsEnabled()` Whether the metrics are enabled for this measured object
    `TimeoutStream` | `periodicStream(long delay)` Returns a periodic timer as a read stream.
    `void` | `runOnContext(io.vertx.core.Handler<java.lang.Void> action)` Puts the handler on the event queue for the current context so it will be run asynchronously ASAP after all preceeding events have been handled.
    `long` | `setPeriodic(long delay, io.vertx.core.Handler<java.lang.Long> handler)` Set a periodic timer to fire every `delay` milliseconds, at which point `handler` will be called with the id of the timer.
    `long` | `setTimer(long delay, io.vertx.core.Handler<java.lang.Long> handler)` Set a one-shot timer to fire after `delay` milliseconds, at which point `handler` will be called with the id of the timer.
    `SharedData` | `sharedData()` Get the shared data object.
    `TimeoutStream` | `timerStream(long delay)` Returns a one-shot timer as a read stream.
    `void` | `undeploy(java.lang.String deploymentID)` Undeploy a verticle deployment.
    `void` | `undeploy(java.lang.String deploymentID, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler)` Like #undeploy(String) but the completionHandler will be notified when the undeployment is complete.
    `static Vertx` | `vertx()` Creates a non clustered instance using default options.
    `static Vertx` | `vertx(java.util.Map<java.lang.String, java.lang.Object> options)` Creates a non clustered instance using the specified options

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### Vertx(java.lang.Object delegate)

  - ### Method Detail

    - #### boolean cancelTimer(long id)

      Cancels the timer with the specified `id`.

      Returns:
        true if the timer was successfully cancelled, or false if the timer does not exist.
      Parameters:
        `id` - The id of the timer to cancel

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

    - #### void close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler)

      Like Vertx.close but the completionHandler will be called when the close is complete

      Parameters:
        `completionHandler` - The handler will be notified when the close is complete.

    - #### static void clusteredVertx(java.util.Map<java.lang.String, java.lang.Object> options = [:], io.vertx.core.Handler<io.vertx.core.AsyncResult<Vertx>> resultHandler)

      Creates a clustered instance using the specified options.

      The instance is created asynchronously and the resultHandler is called with the result when it is ready.

      Parameters:
        `options` - the options to use (see VertxOptions)
        `resultHandler` - the result handler that will receive the result

    - #### DatagramSocket createDatagramSocket(java.util.Map<java.lang.String, java.lang.Object> options)

      Create a datagram socket using the specified options

      Returns:
        the socket
      Parameters:
        `options` - the options to use (see DatagramSocketOptions)

    - #### DatagramSocket createDatagramSocket()

      Create a datagram socket using default options

      Returns:
        the socket

    - #### DnsClient createDnsClient(int port, java.lang.String host)

      Create a DNS client to connect to a DNS server at the specified host and port

      Returns:
        the DNS client
      Parameters:
        `port` - the port
        `host` - the host

    - #### HttpClient createHttpClient(java.util.Map<java.lang.String, java.lang.Object> options)

      Create a HTTP/HTTPS client using the specified options

      Returns:
        the client
      Parameters:
        `options` - the options to use (see HttpClientOptions)

    - #### HttpClient createHttpClient()

      Create a HTTP/HTTPS client using default options

      Returns:
        the client

    - #### HttpServer createHttpServer(java.util.Map<java.lang.String, java.lang.Object> options)

      Create an HTTP/HTTPS server using the specified options

      Returns:
        the server
      Parameters:
        `options` - the options to use (see HttpServerOptions)

    - #### HttpServer createHttpServer()

      Create an HTTP/HTTPS server using default options

      Returns:
        the server

    - #### NetClient createNetClient(java.util.Map<java.lang.String, java.lang.Object> options)

      Create a TCP/SSL client using the specified options

      Returns:
        the client
      Parameters:
        `options` - the options to use (see NetClientOptions)

    - #### NetClient createNetClient()

      Create a TCP/SSL client using default options

      Returns:
        the client

    - #### NetServer createNetServer(java.util.Map<java.lang.String, java.lang.Object> options)

      Create a TCP/SSL server using the specified options

      Returns:
        the server
      Parameters:
        `options` - the options to use (see NetServerOptions)

    - #### NetServer createNetServer()

      Create a TCP/SSL server using default options

      Returns:
        the server

    - #### WorkerExecutor createSharedWorkerExecutor(java.lang.String name)

      Like Vertx.createSharedWorkerExecutor but with the VertxOptions `poolSize`.

      Returns:
      Parameters:
        name

    - #### WorkerExecutor createSharedWorkerExecutor(java.lang.String name, int poolSize)

      Like Vertx.createSharedWorkerExecutor but with the VertxOptions `maxExecuteTime`.

      Returns:
      Parameters:
        name
        poolSize

    - #### WorkerExecutor createSharedWorkerExecutor(java.lang.String name, int poolSize, long maxExecuteTime)

      Create a named worker executor, the executor should be closed when it's not needed anymore to release resources.

      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.

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

    - #### static Context currentContext()

      Gets the current context

      Returns:
        The current context or null if no current context

    - #### void deployVerticle(java.lang.String name)

      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.

      Parameters:
        `name` - the name.

    - #### void deployVerticle(java.lang.String name, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler)

      Like Vertx.deployVerticle but the completionHandler will be notified when the deployment is complete.

      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

    - #### void deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options)

      Like Vertx.deployVerticle but DeploymentOptions are provided to configure the deployment.

      Parameters:
        `name` - the name
        `options` - the deployment options. (see DeploymentOptions)

    - #### void deployVerticle(java.lang.String name, java.util.Map<java.lang.String, java.lang.Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> completionHandler)

      Like Vertx.deployVerticle but DeploymentOptions are provided to configure the deployment.

      Parameters:
        `name` - the name
        `options` - the deployment options. (see DeploymentOptions)
        `completionHandler` - a handler which will be notified when the deployment is complete

    - #### java.util.Set<java.lang.String> deploymentIDs()

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

      Returns:
        Set of deployment IDs

    - #### EventBus eventBus()

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

      Returns:
        the event bus object

    - #### Vertx exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)

      Set a default exception handler for Context, set on at creation.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `handler` - the exception handler

    - #### void executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, boolean ordered, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)

      Safely execute some blocking code.

      Executes the blocking code in the handler `blockingCodeHandler` using a thread from the worker pool.

      When the code is complete the handler `resultHandler` will be called with the result on the original context (e.g. on the original event loop of the caller).

      A `Future` instance is passed into `blockingCodeHandler`. When the blocking code successfully completes, the handler should call the Future.complete or Future.complete method, or the Future.fail method if it failed.

      In the `blockingCodeHandler` the current context remains the original context and therefore any task scheduled in the `blockingCodeHandler` will be executed on the this context and not on the worker thread.

      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
        `resultHandler` - handler that will be called when the blocking code is complete

    - #### void executeBlocking(io.vertx.core.Handler<Future<T>> blockingCodeHandler, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)

      Like Vertx.executeBlocking called with ordered = true.

      Parameters:
        blockingCodeHandler
        resultHandler

    - #### FileSystem fileSystem()

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

      Returns:
        the filesystem object

    - #### java.lang.Object getDelegate()

    - #### Context getOrCreateContext()

      Gets the current context, or creates one if there isn't one

      Returns:
        The current context (created if didn't exist)

    - #### boolean isClustered()

      Is this Vert.x instance clustered?

      Returns:
        true if clustered

    - #### boolean isMetricsEnabled()

      Whether the metrics are enabled for this measured object

      Returns:
        true if the metrics are enabled

    - #### TimeoutStream periodicStream(long delay)

      Returns a periodic timer as a read stream. The timer will be fired every `delay` milliseconds after the has been called.

      Returns:
        the periodic stream
      Parameters:
        `delay` - the delay in milliseconds, after which the timer will fire

    - #### void runOnContext(io.vertx.core.Handler<java.lang.Void> action)

      Puts the handler on the event queue for the current context so it will be run asynchronously ASAP after all preceeding events have been handled.

      Parameters:
        `action` - - a handler representing the action to execute

    - #### long setPeriodic(long delay, io.vertx.core.Handler<java.lang.Long> handler)

      Set a periodic timer to fire every `delay` milliseconds, at which point `handler` will be called with the id of the timer.

      Returns:
        the unique 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

    - #### long setTimer(long delay, io.vertx.core.Handler<java.lang.Long> handler)

      Set a one-shot timer to fire after `delay` milliseconds, at which point `handler` will be called with the id of the timer.

      Returns:
        the unique 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

    - #### SharedData sharedData()

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

      Returns:
        the shared data object

    - #### TimeoutStream timerStream(long delay)

      Returns a one-shot timer as a read stream. The timer will be fired after `delay` milliseconds after the has been called.

      Returns:
        the timer stream
      Parameters:
        `delay` - the delay in milliseconds, after which the timer will fire

    - #### void undeploy(java.lang.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

    - #### void undeploy(java.lang.String deploymentID, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> completionHandler)

      Like #undeploy(String) but the completionHandler will be notified when the undeployment is complete.

      Parameters:
        `deploymentID` - the deployment ID
        `completionHandler` - a handler which will be notified when the undeployment is complete

    - #### static Vertx vertx()

      Creates a non clustered instance using default options.

      Returns:
        the instance

    - #### static Vertx vertx(java.util.Map<java.lang.String, java.lang.Object> options)

      Creates a non clustered instance using the specified options

      Returns:
        the instance
      Parameters:
        `options` - the options to use (see VertxOptions)