Class Vertx
- java.lang.Object
-
- io.vertx.rxjava.core.Vertx
-
- All Implemented Interfaces:
Measured
public class Vertx extends Object implements 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()andclusteredVertx(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 theoriginalnon RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<Vertx>__TYPE_ARG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancancelTimer(long id)Cancels the timer with the specifiedid.voidclose()Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is completevoidclose(Handler<AsyncResult<Void>> completionHandler)Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is completestatic voidclusteredVertx(VertxOptions options)Creates a clustered instance using the specified options.static voidclusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler)Creates a clustered instance using the specified options.DatagramSocketcreateDatagramSocket()Create a datagram socket using default optionsDatagramSocketcreateDatagramSocket(DatagramSocketOptions options)Create a datagram socket using the specified optionsDnsClientcreateDnsClient()Create a DNS client to connect to the DNS server configured byVertxOptionsDnsClientcreateDnsClient(int port, String host)Create a DNS client to connect to a DNS server at the specified host and port, with the default query timeout (5 seconds)DnsClientcreateDnsClient(DnsClientOptions options)Create a DNS client to connect to a DNS serverHttpClientcreateHttpClient()Create a HTTP/HTTPS client using default optionsHttpClientcreateHttpClient(HttpClientOptions options)Create a HTTP/HTTPS client using the specified optionsHttpServercreateHttpServer()Create an HTTP/HTTPS server using default optionsHttpServercreateHttpServer(HttpServerOptions options)Create an HTTP/HTTPS server using the specified optionsNetClientcreateNetClient()Create a TCP/SSL client using default optionsNetClientcreateNetClient(NetClientOptions options)Create a TCP/SSL client using the specified optionsNetServercreateNetServer()Create a TCP/SSL server using default optionsNetServercreateNetServer(NetServerOptions options)Create a TCP/SSL server using the specified optionsWorkerExecutorcreateSharedWorkerExecutor(String name)WorkerExecutorcreateSharedWorkerExecutor(String name, int poolSize)WorkerExecutorcreateSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime)WorkerExecutorcreateSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime, TimeUnit maxExecuteTimeUnit)Create a named worker executor, the executor should be closed when it's not needed anymore to release resources.static ContextcurrentContext()Gets the current contextSet<String>deploymentIDs()Return a Set of deployment IDs for the currently deployed deploymentIDs.voiddeployVerticle(Verticle verticle)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.voiddeployVerticle(Verticle verticle, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.voiddeployVerticle(Verticle verticle, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.voiddeployVerticle(Verticle verticle, Handler<AsyncResult<String>> completionHandler)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.voiddeployVerticle(String name)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.voiddeployVerticle(String name, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.voiddeployVerticle(String name, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.voiddeployVerticle(String name, Handler<AsyncResult<String>> completionHandler)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.voiddeployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.voiddeployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.booleanequals(Object o)EventBuseventBus()Get the event bus object.VertxexceptionHandler(Handler<Throwable> handler)Set a default exception handler forContext, set onContext.exceptionHandler(io.vertx.core.Handler<java.lang.Throwable>)at creation.<T> voidexecuteBlocking(Handler<Promise<T>> blockingCodeHandler)<T> voidexecuteBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)Safely execute some blocking code.<T> voidexecuteBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)Safely execute some blocking code.<T> voidexecuteBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)FileSystemfileSystem()Get the filesystem object.VertxgetDelegate()ContextgetOrCreateContext()Gets the current context, or creates one if there isn't oneinthashCode()booleanisClustered()Is this Vert.x instance clustered?booleanisMetricsEnabled()Whether the metrics are enabled for this measured objectbooleanisNativeTransportEnabled()io.netty.channel.EventLoopGroupnettyEventLoopGroup()Return the Netty EventLoopGroup used by Vert.xstatic VertxnewInstance(Vertx arg)TimeoutStreamperiodicStream(long delay)Deprecated.TimeoutStreamperiodicStream(long initialDelay, long delay)Deprecated.voidregisterVerticleFactory(VerticleFactory factory)Register aVerticleFactorythat can be used for deploying Verticles based on an identifier.voidrunOnContext(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.rx.Single<Void>rxClose()Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is completestatic rx.Single<Vertx>rxClusteredVertx(VertxOptions options)Creates a clustered instance using the specified options.rx.Single<String>rxDeployVerticle(Verticle verticle)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.rx.Single<String>rxDeployVerticle(Verticle verticle, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.rx.Single<String>rxDeployVerticle(String name)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)but the completionHandler will be notified when the deployment is complete.rx.Single<String>rxDeployVerticle(String name, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.rx.Single<String>rxDeployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options)LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.<T> rx.Single<T>rxExecuteBlocking(Handler<Promise<T>> blockingCodeHandler)<T> rx.Single<T>rxExecuteBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)Safely execute some blocking code.rx.Single<Void>rxUndeploy(String deploymentID)Like#undeploy(String)but the completionHandler will be notified when the undeployment is complete.longsetPeriodic(long initialDelay, long delay, Handler<Long> handler)Set a periodic timer to fire everydelaymilliseconds with initial delay, at which pointhandlerwill be called with the id of the timer.longsetPeriodic(long delay, Handler<Long> handler)Set a periodic timer to fire everydelaymilliseconds, at which pointhandlerwill be called with the id of the timer.longsetTimer(long delay, Handler<Long> handler)Set a one-shot timer to fire afterdelaymilliseconds, at which pointhandlerwill be called with the id of the timer.SharedDatasharedData()Get the shared data object.TimeoutStreamtimerStream(long delay)Deprecated.StringtoString()ThrowableunavailableNativeTransportCause()voidundeploy(String deploymentID)Like#undeploy(String)but the completionHandler will be notified when the undeployment is complete.voidundeploy(String deploymentID, Handler<AsyncResult<Void>> completionHandler)Like#undeploy(String)but the completionHandler will be notified when the undeployment is complete.voidunregisterVerticleFactory(VerticleFactory factory)Unregister aVerticleFactorySet<VerticleFactory>verticleFactories()Return the Set of currently registered verticle factories.static Vertxvertx()Creates a non clustered instance using default options.static Vertxvertx(VertxOptions options)Creates a non clustered instance using the specified options
-
-
-
Method Detail
-
getDelegate
public Vertx getDelegate()
- Specified by:
getDelegatein interfaceMeasured
-
isMetricsEnabled
public boolean isMetricsEnabled()
Whether the metrics are enabled for this measured object- Specified by:
isMetricsEnabledin interfaceMeasured- Returns:
trueif metrics are enabled
-
vertx
public static Vertx vertx()
Creates a non clustered instance using default options.- Returns:
- the instance
-
vertx
public static Vertx vertx(VertxOptions options)
Creates a non clustered instance using the specified options- Parameters:
options- the options to use- Returns:
- the instance
-
clusteredVertx
public 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 useresultHandler- the result handler that will receive the result
-
clusteredVertx
public static void clusteredVertx(VertxOptions options)
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
-
rxClusteredVertx
public static rx.Single<Vertx> rxClusteredVertx(VertxOptions options)
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- Returns:
-
currentContext
public static Context currentContext()
Gets the current context- Returns:
- The current context or
nullif there is no current context
-
getOrCreateContext
public Context getOrCreateContext()
Gets the current context, or creates one if there isn't one- Returns:
- The current context (created if didn't exist)
-
createNetServer
public NetServer createNetServer(NetServerOptions options)
Create a TCP/SSL server using the specified options- Parameters:
options- the options to use- Returns:
- the server
-
createNetServer
public NetServer createNetServer()
Create a TCP/SSL server using default options- Returns:
- the server
-
createNetClient
public NetClient createNetClient(NetClientOptions options)
Create a TCP/SSL client using the specified options- Parameters:
options- the options to use- Returns:
- the client
-
createNetClient
public NetClient createNetClient()
Create a TCP/SSL client using default options- Returns:
- the client
-
createHttpServer
public HttpServer createHttpServer(HttpServerOptions options)
Create an HTTP/HTTPS server using the specified options- Parameters:
options- the options to use- Returns:
- the server
-
createHttpServer
public HttpServer createHttpServer()
Create an HTTP/HTTPS server using default options- Returns:
- the server
-
createHttpClient
public HttpClient createHttpClient(HttpClientOptions options)
Create a HTTP/HTTPS client using the specified options- Parameters:
options- the options to use- Returns:
- the client
-
createHttpClient
public HttpClient createHttpClient()
Create a HTTP/HTTPS client using default options- Returns:
- the client
-
createDatagramSocket
public DatagramSocket createDatagramSocket(DatagramSocketOptions options)
Create a datagram socket using the specified options- Parameters:
options- the options to use- Returns:
- the socket
-
createDatagramSocket
public DatagramSocket createDatagramSocket()
Create a datagram socket using default options- Returns:
- the socket
-
fileSystem
public FileSystem fileSystem()
Get the filesystem object. There is a single instance of FileSystem per Vertx instance.- Returns:
- the filesystem object
-
eventBus
public EventBus eventBus()
Get the event bus object. There is a single instance of EventBus per Vertx instance.- Returns:
- the event bus object
-
createDnsClient
public DnsClient createDnsClient(int port, String host)
Create a DNS client to connect to a DNS server at the specified host and port, with the default query timeout (5 seconds)- Parameters:
port- the porthost- the host- Returns:
- the DNS client
-
createDnsClient
public DnsClient createDnsClient()
Create a DNS client to connect to the DNS server configured byVertxOptionsDNS client takes the first configured resolver address provided by }
- Returns:
- the DNS client
-
createDnsClient
public DnsClient createDnsClient(DnsClientOptions options)
Create a DNS client to connect to a DNS server- Parameters:
options- the client options- Returns:
- the DNS client
-
sharedData
public SharedData sharedData()
Get the shared data object. There is a single instance of SharedData per Vertx instance.- Returns:
- the shared data object
-
setTimer
public long setTimer(long delay, Handler<Long> handler)Set a one-shot timer to fire afterdelaymilliseconds, at which pointhandlerwill be called with the id of the timer.- Parameters:
delay- the delay in milliseconds, after which the timer will firehandler- the handler that will be called with the timer ID when the timer fires- Returns:
- the unique ID of the timer
-
timerStream
@Deprecated public TimeoutStream timerStream(long delay)
Deprecated.Returns a one-shot timer as a read stream. The timer will be fired afterdelaymilliseconds after the has been called.- Parameters:
delay- the delay in milliseconds, after which the timer will fire- Returns:
- the timer stream
-
setPeriodic
public long setPeriodic(long delay, Handler<Long> handler)Set a periodic timer to fire everydelaymilliseconds, at which pointhandlerwill be called with the id of the timer.- Parameters:
delay- the delay in milliseconds, after which the timer will firehandler- the handler that will be called with the timer ID when the timer fires- Returns:
- the unique ID of the timer
-
setPeriodic
public long setPeriodic(long initialDelay, long delay, Handler<Long> handler)Set a periodic timer to fire everydelaymilliseconds with initial delay, at which pointhandlerwill be called with the id of the timer.- Parameters:
initialDelay- the initial delay in millisecondsdelay- the delay in milliseconds, after which the timer will firehandler- the handler that will be called with the timer ID when the timer fires- Returns:
- the unique ID of the timer
-
periodicStream
@Deprecated public TimeoutStream periodicStream(long delay)
Deprecated.Returns a periodic timer as a read stream. The timer will be fired everydelaymilliseconds after the has been called.- Parameters:
delay- the delay in milliseconds, after which the timer will fire- Returns:
- the periodic stream
-
periodicStream
@Deprecated public TimeoutStream periodicStream(long initialDelay, long delay)
Deprecated.Returns a periodic timer as a read stream. The timer will be fired everydelaymilliseconds after the has been called.- Parameters:
initialDelay- the initial delay in millisecondsdelay- the delay in milliseconds, after which the timer will fire- Returns:
- the periodic stream
-
cancelTimer
public boolean cancelTimer(long id)
Cancels the timer with the specifiedid.- 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
public 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
public void close(Handler<AsyncResult<Void>> completionHandler)
Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is complete- Parameters:
completionHandler- The handler will be notified when the close is complete.
-
close
public void close()
Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is complete
-
rxClose
public rx.Single<Void> rxClose()
Likeclose(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but the completionHandler will be called when the close is complete- Returns:
-
deployVerticle
public void deployVerticle(String name, Handler<AsyncResult<String>> completionHandler)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
name- The identifiercompletionHandler- a handler which will be notified when the deployment is complete
-
deployVerticle
public void deployVerticle(String name)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
name- The identifier
-
rxDeployVerticle
public rx.Single<String> rxDeployVerticle(String name)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
name- The identifier- Returns:
-
deployVerticle
public void deployVerticle(String name, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
name- the nameoptions- the deployment options.completionHandler- a handler which will be notified when the deployment is complete
-
deployVerticle
public void deployVerticle(String name, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
name- the nameoptions- the deployment options.
-
rxDeployVerticle
public rx.Single<String> rxDeployVerticle(String name, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
name- the nameoptions- the deployment options.- Returns:
-
undeploy
public 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 IDcompletionHandler- a handler which will be notified when the undeployment is complete
-
undeploy
public void undeploy(String deploymentID)
Like#undeploy(String)but the completionHandler will be notified when the undeployment is complete.- Parameters:
deploymentID- the deployment ID
-
rxUndeploy
public rx.Single<Void> rxUndeploy(String deploymentID)
Like#undeploy(String)but the completionHandler will be notified when the undeployment is complete.- Parameters:
deploymentID- the deployment ID- Returns:
-
deploymentIDs
public Set<String> deploymentIDs()
Return a Set of deployment IDs for the currently deployed deploymentIDs.- Returns:
- Set of deployment IDs
-
isClustered
public boolean isClustered()
Is this Vert.x instance clustered?- Returns:
- true if clustered
-
executeBlocking
public <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)
Safely execute some blocking code.Executes the blocking code in the handler
blockingCodeHandlerusing a thread from the worker pool.When the code is complete the handler
resultHandlerwill be called with the result on the original context (e.g. on the original event loop of the caller).A
Futureinstance is passed intoblockingCodeHandler. When the blocking code successfully completes, the handler should call thePromise.complete(T)orPromise.complete(T)method, or thePromise.fail(java.lang.Throwable)method if it failed.In the
blockingCodeHandlerthe current context remains the original context and therefore any task scheduled in theblockingCodeHandlerwill be executed on the this context and not on the worker thread.The blocking code should block for a reasonable amount of time (i.e no more than a few seconds). Long blocking operations or polling operations (i.e a thread that spin in a loop polling events in a blocking fashion) are precluded.
When the blocking operation lasts more than the 10 seconds, a message will be printed on the console by the blocked thread checker.
Long blocking operations should use a dedicated thread managed by the application, which can interact with verticles using the event-bus or
Context.runOnContext(io.vertx.core.Handler<java.lang.Void>)- Parameters:
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 complete
-
executeBlocking
public <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)
Safely execute some blocking code.Executes the blocking code in the handler
blockingCodeHandlerusing a thread from the worker pool.When the code is complete the handler
resultHandlerwill be called with the result on the original context (e.g. on the original event loop of the caller).A
Futureinstance is passed intoblockingCodeHandler. When the blocking code successfully completes, the handler should call thePromise.complete(T)orPromise.complete(T)method, or thePromise.fail(java.lang.Throwable)method if it failed.In the
blockingCodeHandlerthe current context remains the original context and therefore any task scheduled in theblockingCodeHandlerwill be executed on the this context and not on the worker thread.The blocking code should block for a reasonable amount of time (i.e no more than a few seconds). Long blocking operations or polling operations (i.e a thread that spin in a loop polling events in a blocking fashion) are precluded.
When the blocking operation lasts more than the 10 seconds, a message will be printed on the console by the blocked thread checker.
Long blocking operations should use a dedicated thread managed by the application, which can interact with verticles using the event-bus or
Context.runOnContext(io.vertx.core.Handler<java.lang.Void>)- Parameters:
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 guarantees
-
rxExecuteBlocking
public <T> rx.Single<T> rxExecuteBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered)
Safely execute some blocking code.Executes the blocking code in the handler
blockingCodeHandlerusing a thread from the worker pool.When the code is complete the handler
resultHandlerwill be called with the result on the original context (e.g. on the original event loop of the caller).A
Futureinstance is passed intoblockingCodeHandler. When the blocking code successfully completes, the handler should call thePromise.complete(T)orPromise.complete(T)method, or thePromise.fail(java.lang.Throwable)method if it failed.In the
blockingCodeHandlerthe current context remains the original context and therefore any task scheduled in theblockingCodeHandlerwill be executed on the this context and not on the worker thread.The blocking code should block for a reasonable amount of time (i.e no more than a few seconds). Long blocking operations or polling operations (i.e a thread that spin in a loop polling events in a blocking fashion) are precluded.
When the blocking operation lasts more than the 10 seconds, a message will be printed on the console by the blocked thread checker.
Long blocking operations should use a dedicated thread managed by the application, which can interact with verticles using the event-bus or
Context.runOnContext(io.vertx.core.Handler<java.lang.Void>)- Parameters:
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 guarantees- Returns:
-
executeBlocking
public <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler)
LikeexecuteBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Promise<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>)called with ordered = true.- Parameters:
blockingCodeHandler-resultHandler-
-
executeBlocking
public <T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler)
LikeexecuteBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Promise<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>)called with ordered = true.- Parameters:
blockingCodeHandler-
-
rxExecuteBlocking
public <T> rx.Single<T> rxExecuteBlocking(Handler<Promise<T>> blockingCodeHandler)
LikeexecuteBlocking(io.vertx.core.Handler<io.vertx.rxjava.core.Promise<T>>, boolean, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>>)called with ordered = true.- Parameters:
blockingCodeHandler-- Returns:
-
createSharedWorkerExecutor
public WorkerExecutor createSharedWorkerExecutor(String name)
- Parameters:
name-- Returns:
-
createSharedWorkerExecutor
public WorkerExecutor createSharedWorkerExecutor(String name, int poolSize)
- Parameters:
name-poolSize-- Returns:
-
createSharedWorkerExecutor
public WorkerExecutor createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime)
- Parameters:
name-poolSize-maxExecuteTime-- Returns:
-
createSharedWorkerExecutor
public WorkerExecutor createSharedWorkerExecutor(String name, int poolSize, long maxExecuteTime, TimeUnit maxExecuteTimeUnit)
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 samename. Executors with the same name will share the same worker pool. The worker pool size , max execute time and unit of max execute time are set when the worker pool is created and won't change after.The worker pool is released when all the
WorkerExecutorsharing the same name are closed.- Parameters:
name- the name of the worker executorpoolSize- the size of the poolmaxExecuteTime- the value of max worker execute timemaxExecuteTimeUnit- the value of unit of max worker execute time- Returns:
- the named worker executor
-
isNativeTransportEnabled
public boolean isNativeTransportEnabled()
- Returns:
- whether the native transport is used
-
unavailableNativeTransportCause
public Throwable unavailableNativeTransportCause()
- Returns:
- the error (if any) that cause the unavailability of native transport when
isNativeTransportEnabled()returnsfalse.
-
exceptionHandler
public Vertx exceptionHandler(Handler<Throwable> handler)
Set a default exception handler forContext, set onContext.exceptionHandler(io.vertx.core.Handler<java.lang.Throwable>)at creation.- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
deployVerticle
public void deployVerticle(Verticle verticle, Handler<AsyncResult<String>> completionHandler)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
verticle- the verticle instance to deploycompletionHandler- a handler which will be notified when the deployment is complete
-
deployVerticle
public void deployVerticle(Verticle verticle)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
verticle- the verticle instance to deploy
-
rxDeployVerticle
public rx.Single<String> rxDeployVerticle(Verticle verticle)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.
- Parameters:
verticle- the verticle instance to deploy- Returns:
-
deployVerticle
public void deployVerticle(Verticle verticle, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
verticle- the verticle instance to deployoptions- the deployment options.completionHandler- a handler which will be notified when the deployment is complete
-
deployVerticle
public void deployVerticle(Verticle verticle, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
verticle- the verticle instance to deployoptions- the deployment options.
-
rxDeployVerticle
public rx.Single<String> rxDeployVerticle(Verticle verticle, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butDeploymentOptionsare provided to configure the deployment.- Parameters:
verticle- the verticle instance to deployoptions- the deployment options.- Returns:
-
deployVerticle
public void deployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options, Handler<AsyncResult<String>> completionHandler)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.The supplier will be invoked as many times as
DeploymentOptions. It must not return the same instance twice.Note that the supplier will be invoked on the caller thread.
- Parameters:
verticleSupplier-options-completionHandler-
-
deployVerticle
public void deployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.The supplier will be invoked as many times as
DeploymentOptions. It must not return the same instance twice.Note that the supplier will be invoked on the caller thread.
- Parameters:
verticleSupplier-options-
-
rxDeployVerticle
public rx.Single<String> rxDeployVerticle(Supplier<Verticle> verticleSupplier, DeploymentOptions options)
LikedeployVerticle(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>)butVerticleinstance is created by invoking theverticleSupplier.The supplier will be invoked as many times as
DeploymentOptions. It must not return the same instance twice.Note that the supplier will be invoked on the caller thread.
- Parameters:
verticleSupplier-options-- Returns:
-
registerVerticleFactory
public void registerVerticleFactory(VerticleFactory factory)
Register aVerticleFactorythat can be used for deploying Verticles based on an identifier.- Parameters:
factory- the factory to register
-
unregisterVerticleFactory
public void unregisterVerticleFactory(VerticleFactory factory)
Unregister aVerticleFactory- Parameters:
factory- the factory to unregister
-
verticleFactories
public Set<VerticleFactory> verticleFactories()
Return the Set of currently registered verticle factories.- Returns:
- the set of verticle factories
-
nettyEventLoopGroup
public io.netty.channel.EventLoopGroup nettyEventLoopGroup()
Return the Netty EventLoopGroup used by Vert.x- Returns:
- the EventLoopGroup
-
-