vertx.core documentation
Vert.x core functionality.
*container*
var
The currently active default vertx container instance.
The root binding will be set on verticle deployment by Vert.x.
You should only need to bind this for advanced usage.
*vertx*
var
The currently active default vertx instance.
When inside a Vert.x container, the root binding will
be set on verticle deployment. When embeded, you will
need to either bind this when needed, or alter its
root binding by calling vertx.embed/set-vertx!.
as-async-result-handler
(as-async-result-handler f)(as-async-result-handler f include-result-or-result-fn)
Wraps the given fn in a org.vertx.java.core.Handler for handling an AsyncResult.
If include-result-or-result-fn is true (the default), the fn will
be passed an exception-map and the result from the AsyncResult,
otherwise just the exception-map. If include-result-or-result-fn is a
fn, it will be passed the result before passing it to the handler
fn. Returns f unmodified if it is nil or already a Handler.
as-handler
(as-handler f)(as-handler f result-fn)
Wraps the given single-arity f in a org.vertx.java.core.Handler.
Returns f unmodified if it is nil or already a Handler. If provided,
result-fn will be applied to the event before passing it to f.
as-void-handler
(as-void-handler f)
Wraps the given fn in a Handler that ignores the event.
f is expected to be a zero-arity fn or a Handler.
Returns f unmodified if it is nil or already a Handler.
cancel-timer
(cancel-timer id)
Cancels the timer specified by id using *vertx*.
config
(config)
Returns the configuration map from the current *container*, with the keys converted to keywords.
current-context
(current-context)
Returns the current Context for *vertx*.
defhandler
macro
(defhandler name bindings & body)
Creates a named (def'ed) handler.
deploy-module
(deploy-module module-name & {:keys [config instances handler], :or {config {}, instances 1}})
Deploys the module with the given name to *container*.
Takes the following keyword arguments [default]:
:config A configuration map for the module [{}]
:handler Either be a two-arity fn that will be passed
the exception-map (if any) and module id from the
result of the deploy call, or a
org.vertx.java.core.Handler that will be
called with the AsyncResult object that wraps
the exception and id [nil]
:instances The number of instances of the module to
deploy [1]deploy-verticle
(deploy-verticle main & {:keys [config instances handler], :or {config {}, instances 1}})
Deploys the verticle with the given main file path to *container*.
main must be on the effective classpath.
Takes the following keyword arguments [default]:
:config A configuration map for the verticle [{}]
:handler Either be a two-arity fn that will be passed
the exception (if any) and verticle id from the
result of the deploy call, or a
org.vertx.java.core.Handler that will be
called with the AsyncResult object that wraps
the exception and id [nil]
:instances The number of instances of the verticle to
deploy [1]deploy-worker-verticle
(deploy-worker-verticle main & {:keys [config instances multi-threaded? handler], :or {config {}, instances 1}})
Deploys the worker verticle with the given main file path to *container*.
main must be on the effective classpath.
Takes the following keyword arguments [default]:
:config A configuration map for the verticle [{}]
:handler Either be a two-arity fn that will be passed
the exception-map (if any) and verticle id from the
result of the deploy call, or a
org.vertx.java.core.Handler that will be
called with the AsyncResult object that wraps
the exception and id [nil]
:instances The number of instances of the verticle to
deploy [1]
:multi-threaded? When true, the verticle will be accessed
by multiple threads concurrently [false]env
(env)
Returns a map of environment variables.
event-loop?
(event-loop?)
Is the current thread an event loop thread?
exit
(exit)
Causes the Vert.x instance to shutdown.
get-container
(get-container)(get-container throw?)
Returns the currently active vertx container instance (*container*).
If throw? is truthy, throws when the container isn't available.
get-vertx
(get-vertx)
Returns the currently active vertx instance (*vertx*), throwing if not set.
handler
macro
(handler bindings & body)
Wraps the given bindings and body in a org.vertx.java.core.Handler.
Calling (handler [foo] (bar foo)) is analogous to calling
(as-handler (fn [foo] (bar foo))).
on-stop
macro
(on-stop & body)
Registers code to be called when vertx undeploys the verticle.
Can be called multiple times to register multiple bodies.
Calling (on-stop (foo)) is analogous to calling (on-stop* (fn
[] (foo))).
on-stop*
(on-stop* f)
Registers a fn to be called when vertx undeploys the verticle.
Can be called multiple times to register multiple fns.
periodic
macro
(periodic interval & body)
Invokes the body every interval ms until cancelled.
Returns the id of the timer. Calling (periodic 1 (foo)) is
analogous to calling (periodic* 1 (fn [_] (foo))).
periodic*
(periodic* interval handler)
Registers a handler with *vertx* to be called every interval ms until cancelled.
handler can either be a single-arity fn or an
org.vertx.java.core.Handler that will be passed the id of the
timer. Returns the id of the timer.
run-on-context
(run-on-context f)(run-on-context context f)
Put the zero-arity fn on the event queue for the context so it will
be run asynchronously ASAP after this event has been processed.
If no context is provided, the context from *vertx* is used.
timer
macro
(timer delay & body)
Invokes the body in delay ms.
Returns the id of the timer. Calling (timer 1 (foo)) is analogous
to calling (timer* 1 (fn [_] (foo))).
timer*
(timer* delay handler)
Registers a handler with *vertx* to be called once in delay ms.
handler can either be a single-arity fn or an
org.vertx.java.core.Handler that will be passed the id of the
timer. Returns the id of the timer.
undeploy-module
(undeploy-module id)(undeploy-module id handler)
Undeploys the module identified by id from *container*.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the deploy call, or a
org.vertx.java.core.Handler that will be called with the
AsyncResult object that wraps the exception.
undeploy-verticle
(undeploy-verticle id)(undeploy-verticle id handler)
Undeploys the verticle identified by id from *container*.
handler can either be a single-arity fn that will be passed the
exception-map (if any) from the result of the deploy call, or a
org.vertx.java.core.Handler that will be called with the
AsyncResult object that wraps the exception.