public class Vertx extends Object implements Measured
You use an instance of this class for functionality including:
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, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.Vertx>>)
.
Please see the user manual for more detailed usage information.
NOTE: This class has been automatically generated from theoriginal
non RX-ified interface using Vert.x codegen.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 |
Observable<Void> |
closeObservable()
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.
|
static Observable<Vertx> |
clusteredVertxObservable(VertxOptions options)
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)
|
WorkerExecutor |
createSharedWorkerExecutor(String name,
int poolSize)
|
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(java.lang.String) but DeploymentOptions are provided to configure the
deployment. |
void |
deployVerticle(String name,
DeploymentOptions options,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(java.lang.String) but DeploymentOptions are provided to configure the
deployment. |
void |
deployVerticle(String name,
Handler<AsyncResult<String>> completionHandler)
Like
deployVerticle(java.lang.String) but the completionHandler will be notified when the deployment is complete. |
Observable<String> |
deployVerticleObservable(String name)
Like
deployVerticle(java.lang.String) but the completionHandler will be notified when the deployment is complete. |
Observable<String> |
deployVerticleObservable(String name,
DeploymentOptions options)
Like
deployVerticle(java.lang.String) but DeploymentOptions are provided to configure the
deployment. |
EventBus |
eventBus()
Get the event bus object.
|
Vertx |
exceptionHandler(Handler<Throwable> handler)
Set a default exception handler for
Context , set on 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(io.vertx.core.Handler<io.vertx.rxjava.core.Future<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>) called with ordered = true. |
<T> Observable<T> |
executeBlockingObservable(Handler<Future<T>> blockingCodeHandler)
Like
executeBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Future<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>) called with ordered = true. |
<T> Observable<T> |
executeBlockingObservable(Handler<Future<T>> blockingCodeHandler,
boolean ordered)
Safely execute some blocking code.
|
FileSystem |
fileSystem()
Get the filesystem object.
|
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
|
static Vertx |
newInstance(Vertx arg) |
TimeoutStream |
periodicStream(long delay)
Returns a periodic timer as a read stream.
|
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. |
Observable<Void> |
undeployObservable(String deploymentID)
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(VertxOptions options)
Creates a non clustered instance using the specified options
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
newInstance
public Vertx(Vertx delegate)
public Object getDelegate()
getDelegate
in interface Measured
public boolean isMetricsEnabled()
isMetricsEnabled
in interface Measured
public static Vertx vertx()
public static Vertx vertx(VertxOptions options)
options
- the options to usepublic static void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler)
The instance is created asynchronously and the resultHandler is called with the result when it is ready.
options
- the options to useresultHandler
- the result handler that will receive the resultpublic static Observable<Vertx> clusteredVertxObservable(VertxOptions options)
The instance is created asynchronously and the resultHandler is called with the result when it is ready.
options
- the options to usepublic static Context currentContext()
public Context getOrCreateContext()
public NetServer createNetServer(NetServerOptions options)
options
- the options to usepublic NetServer createNetServer()
public NetClient createNetClient(NetClientOptions options)
options
- the options to usepublic NetClient createNetClient()
public HttpServer createHttpServer(HttpServerOptions options)
options
- the options to usepublic HttpServer createHttpServer()
public HttpClient createHttpClient(HttpClientOptions options)
options
- the options to usepublic HttpClient createHttpClient()
public DatagramSocket createDatagramSocket(DatagramSocketOptions options)
options
- the options to usepublic DatagramSocket createDatagramSocket()
public FileSystem fileSystem()
public EventBus eventBus()
public DnsClient createDnsClient(int port, String host)
port
- the porthost
- the hostpublic SharedData sharedData()
public long setTimer(long delay, Handler<Long> handler)
delay
milliseconds, at which point handler
will be called with
the id of the timer.delay
- the delay in milliseconds, after which the timer will firehandler
- the handler that will be called with the timer ID when the timer firespublic TimeoutStream timerStream(long delay)
delay
milliseconds after
the has been called.delay
- the delay in milliseconds, after which the timer will firepublic long setPeriodic(long delay, Handler<Long> handler)
delay
milliseconds, at which point handler
will be called with
the id of the timer.delay
- the delay in milliseconds, after which the timer will firehandler
- the handler that will be called with the timer ID when the timer firespublic TimeoutStream periodicStream(long delay)
delay
milliseconds after
the has been called.delay
- the delay in milliseconds, after which the timer will firepublic boolean cancelTimer(long id)
id
.id
- The id of the timer to cancelpublic void runOnContext(Handler<Void> action)
action
- - a handler representing the action to executepublic void close()
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.
public void close(Handler<AsyncResult<Void>> completionHandler)
close()
but the completionHandler will be called when the close is completecompletionHandler
- The handler will be notified when the close is complete.public Observable<Void> closeObservable()
close()
but the completionHandler will be called when the close is completepublic void deployVerticle(String 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.
name
- the name.public void deployVerticle(String name, Handler<AsyncResult<String>> completionHandler)
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.
name
- The identifiercompletionHandler
- a handler which will be notified when the deployment is completepublic Observable<String> deployVerticleObservable(String name)
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.
name
- The identifierpublic void deployVerticle(String name, DeploymentOptions options)
deployVerticle(java.lang.String)
but DeploymentOptions
are provided to configure the
deployment.name
- the nameoptions
- the deployment options.public void deployVerticle(String name, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
deployVerticle(java.lang.String)
but DeploymentOptions
are provided to configure the
deployment.name
- the nameoptions
- the deployment options.completionHandler
- a handler which will be notified when the deployment is completepublic Observable<String> deployVerticleObservable(String name, DeploymentOptions options)
deployVerticle(java.lang.String)
but DeploymentOptions
are provided to configure the
deployment.name
- the nameoptions
- the deployment options.public void undeploy(String deploymentID)
The actual undeployment happens asynchronously and may not complete until after the method has returned.
deploymentID
- the deployment IDpublic void undeploy(String deploymentID, Handler<AsyncResult<Void>> completionHandler)
#undeploy(String)
but the completionHandler will be notified when the undeployment is complete.deploymentID
- the deployment IDcompletionHandler
- a handler which will be notified when the undeployment is completepublic Observable<Void> undeployObservable(String deploymentID)
#undeploy(String)
but the completionHandler will be notified when the undeployment is complete.deploymentID
- the deployment IDpublic Set<String> deploymentIDs()
public boolean isClustered()
public <T> void executeBlocking(Handler<Future<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)
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(T)
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.
blockingCodeHandler
- handler representing the blocking code to runordered
- 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 guaranteesresultHandler
- handler that will be called when the blocking code is completepublic <T> Observable<T> executeBlockingObservable(Handler<Future<T>> blockingCodeHandler, boolean ordered)
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(T)
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.
blockingCodeHandler
- handler representing the blocking code to runordered
- 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 guaranteespublic <T> void executeBlocking(Handler<Future<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)
executeBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Future<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>)
called with ordered = true.blockingCodeHandler
- resultHandler
- public <T> Observable<T> executeBlockingObservable(Handler<Future<T>> blockingCodeHandler)
executeBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Future<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>)
called with ordered = true.blockingCodeHandler
- public WorkerExecutor createSharedWorkerExecutor(String name)
name
- public WorkerExecutor createSharedWorkerExecutor(String name, int poolSize)
name
- poolSize
- public WorkerExecutor createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime)
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.
name
- the name of the worker executorpoolSize
- the size of the poolmaxExecuteTime
- the value of max worker execute time, in mspublic Vertx exceptionHandler(Handler<Throwable> handler)
Context
, set on at creation.handler
- the exception handlerCopyright © 2016. All rights reserved.