Groovy Documentation

## org.vertx.groovy.core
[Groovy] Class Vertx

    java.lang.Object
      org.vertx.groovy.core.Vertx

    class Vertx

The control centre of vert.x

You should normally only use a single instance of this class throughout your application. If you are running in the vert.x container an instance will be provided to you.

If you are using vert.x embedded, you can create an instance using one of the static `newVertx` methods.

This class acts as a factory for TCP/SSL and HTTP/HTTPS servers and clients, SockJS servers, and provides an instance of the event bus, file system and shared data classes, as well as methods for setting and cancelling timers.

Authors:
  Tim Fox

Constructor Summary
`Vertx(VertxInternal jVertex)`

Method Summary
`boolean` | `cancelTimer(long timerID)` Cancel the timer with the specified `id`.
`HttpClient` | `createHttpClient(java.util.Map props = null)` Create a HTTP/HTTPS client
`HttpServer` | `createHttpServer(java.util.Map props = null)`
`NetClient` | `createNetClient(java.util.Map props = null)` Create a TCP/SSL client
`NetServer` | `createNetServer(java.util.Map props = null)` Create a TCP/SSL server
`SockJSServer` | `createSockJSServer(HttpServer httpServer)` Create a SockJS server that wraps an HTTP server
`EventBus` | `getEventBus()` The event bus
`FileSystem` | `getFileSystem()` The File system object
`SharedData` | `getSharedData()` The shared data object
`boolean` | `isEventLoop()` Is the current thread an event loop thread?
`boolean` | `isWorker()` Is the current thread an worker thread?
`static Vertx` | `newVertx()` Create a non clustered Vertx instance
`static Vertx` | `newVertx(java.lang.String hostname)` Create a clustered Vertx instance listening for cluster connections on the default port 25500
`static Vertx` | `newVertx(int port, java.lang.String hostname)` Create a clustered Vertx instance
`void` | `runOnLoop(groovy.lang.Closure handler)` Put the handler on the event queue for this loop so it will be run asynchronously ASAP after this event has been processed
`long` | `setPeriodic(long delay, groovy.lang.Closure 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, groovy.lang.Closure handler)` Set a one-shot timer to fire after `delay` milliseconds, at which point `handler` will be called with the id of the timer.
`Vertx` | `toJavaVertx()`

Methods inherited from 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

    Vertx(VertxInternal jVertex)

Method Detail

### cancelTimer

    boolean cancelTimer(long timerID)

  Cancel the timer with the specified `id`. Returns {@code} true if the timer was successfully cancelled, or `false` if the timer does not exist.

### createHttpClient

    HttpClient createHttpClient(java.util.Map props = null)

  Create a HTTP/HTTPS client

### createHttpServer

    HttpServer createHttpServer(java.util.Map props = null)

### createNetClient

    NetClient createNetClient(java.util.Map props = null)

  Create a TCP/SSL client

### createNetServer

    NetServer createNetServer(java.util.Map props = null)

  Create a TCP/SSL server

### createSockJSServer

    SockJSServer createSockJSServer(HttpServer httpServer)

  Create a SockJS server that wraps an HTTP server

### getEventBus

    EventBus getEventBus()

  The event bus

### getFileSystem

    FileSystem getFileSystem()

  The File system object

### getSharedData

    SharedData getSharedData()

  The shared data object

### isEventLoop

    boolean isEventLoop()

  Is the current thread an event loop thread?
  Returns:
    true if current thread is an event loop thread

### isWorker

    boolean isWorker()

  Is the current thread an worker thread?
  Returns:
    true if current thread is an worker thread

### newVertx

    static Vertx newVertx()

  Create a non clustered Vertx instance

### newVertx

    static Vertx newVertx(java.lang.String hostname)

  Create a clustered Vertx instance listening for cluster connections on the default port 25500
  Parameters:
    `hostname` - The hostname or ip address to listen for cluster connections

### newVertx

    static Vertx newVertx(int port, java.lang.String hostname)

  Create a clustered Vertx instance
  Parameters:
    `port` - The port to listen for cluster connections
    `hostname` - The hostname or ip address to listen for cluster connections

### runOnLoop

    void runOnLoop(groovy.lang.Closure handler)

  Put the handler on the event queue for this loop so it will be run asynchronously ASAP after this event has been processed

### setPeriodic

    long setPeriodic(long delay, groovy.lang.Closure 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

### setTimer

    long setTimer(long delay, groovy.lang.Closure 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

### toJavaVertx

    Vertx toJavaVertx()

Groovy Documentation