Package com.codingchili.core.context
Class SystemContext
java.lang.Object
com.codingchili.core.context.SystemContext
- All Implemented Interfaces:
CoreContext
- Direct Known Subclasses:
ContextMock
,StorageContext
Implementation of the CoreContext, each context gets its own worker pool.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionCreates a new vertx instance to be used for this context.protected
SystemContext(CoreContext context)
Creates a new system context that shares vertx instance with the given context. -
Method Summary
Modifier and TypeMethodDescription<T> void
blocking(io.vertx.core.Handler<io.vertx.core.Promise<T>> sync, boolean ordered, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> result)
Call to execute the given blocking handler on a worker thread that is scoped to the current context.<T> void
blocking(io.vertx.core.Handler<io.vertx.core.Promise<T>> sync, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> result)
Call to execute the given blocking handler on a worker thread that is scoped to the current context.io.vertx.core.eventbus.EventBus
bus()
void
cancel(long timer)
Cancels a running timer.void
close()
Shuts down the context and underlying pools and connections.void
static void
clustered(io.vertx.core.Handler<io.vertx.core.AsyncResult<CoreContext>> handler)
Creates a clustered instance of a context.io.vertx.core.Future<String>
Instantiates an object of the given class identifier and determines the type that should be deployed.io.vertx.core.Future<String>
handler(Supplier<CoreHandler> handler)
Deploys a new handler in the cluster from given handler with a completion handler.io.vertx.core.Future<String>
listener(Supplier<CoreListener> listener)
Deploys the given verticle with a completion handler.metrics()
Creates a new metric namespace using the registryName.void
periodic(TimerSource timeout, io.vertx.core.Handler<Long> handler)
Set a periodic timer that uses a timersource to adjust interval during runtime.io.vertx.core.Future<String>
service(Supplier<CoreService> service)
Deploys the given verticle with a completion handler.io.vertx.core.Future<io.vertx.core.CompositeFuture>
stop()
void
Undeploys a deployed handler by the deployment id.system()
long
Sets a timer that executes the given handler after the given time.io.vertx.core.Vertx
vertx()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.codingchili.core.context.CoreContext
fileSystem
-
Field Details
-
vertx
protected io.vertx.core.Vertx vertx
-
-
Constructor Details
-
SystemContext
public SystemContext()Creates a new vertx instance to be used for this context. -
SystemContext
Creates a new system context that shares vertx instance with the given context.- Parameters:
context
- context to clone vertx instance from.
-
-
Method Details
-
clustered
public static void clustered(io.vertx.core.Handler<io.vertx.core.AsyncResult<CoreContext>> handler)Creates a clustered instance of a context.- Parameters:
handler
- called with the context on creation.
-
metrics
- Specified by:
metrics
in interfaceCoreContext
- Returns:
- the metrics collector.
-
metrics
Description copied from interface:CoreContext
Creates a new metric namespace using the registryName.- Specified by:
metrics
in interfaceCoreContext
- Parameters:
registryName
- the name of the registry to attach metrics to.- Returns:
- a new metric collector using the default timer.
-
bus
public io.vertx.core.eventbus.EventBus bus()- Specified by:
bus
in interfaceCoreContext
- Returns:
- get the EventBus attached to the vertx instance.
-
system
- Specified by:
system
in interfaceCoreContext
- Returns:
- the system configuration.
-
periodic
Description copied from interface:CoreContext
Set a periodic timer that uses a timersource to adjust interval during runtime.- Specified by:
periodic
in interfaceCoreContext
- Parameters:
timeout
- a timer source that may change period during runtime.handler
- the handler to be invoked when each interval ends.
-
timer
Description copied from interface:CoreContext
Sets a timer that executes the given handler after the given time.- Specified by:
timer
in interfaceCoreContext
- Parameters:
ms
- time unit in ms.handler
- the handler to be invoken when the timer runs out.- Returns:
- the id of the created timer so that it may be cancelled.
-
cancel
public void cancel(long timer)Description copied from interface:CoreContext
Cancels a running timer.- Specified by:
cancel
in interfaceCoreContext
- Parameters:
timer
- the id of the timer to be stopped.
-
deploy
Description copied from interface:CoreContext
Instantiates an object of the given class identifier and determines the type that should be deployed. May be aCoreHandler
CoreService
CoreListener
or a plainVerticle
.- Specified by:
deploy
in interfaceCoreContext
- Parameters:
target
- the target class to deploy.- Returns:
- future completed on deployment.
-
handler
Description copied from interface:CoreContext
Deploys a new handler in the cluster from given handler with a completion handler.- Specified by:
handler
in interfaceCoreContext
- Parameters:
handler
- the handler to be used to handle incoming requests.- Returns:
- a future to be completed on deployment completion.
-
listener
Description copied from interface:CoreContext
Deploys the given verticle with a completion handler.- Specified by:
listener
in interfaceCoreContext
- Parameters:
listener
- the verticle to be deployed.- Returns:
- future completed on deployment completion.
-
service
Description copied from interface:CoreContext
Deploys the given verticle with a completion handler.- Specified by:
service
in interfaceCoreContext
- Parameters:
service
- the verticle to be deployed.- Returns:
- future to be completed on deployment completion.
-
stop
Description copied from interface:CoreContext
Undeploys a deployed handler by the deployment id.- Specified by:
stop
in interfaceCoreContext
- Parameters:
deploymentId
- the id of the deployment to undeploy.
-
stop
public io.vertx.core.Future<io.vertx.core.CompositeFuture> stop()- Specified by:
stop
in interfaceCoreContext
-
blocking
public <T> void blocking(io.vertx.core.Handler<io.vertx.core.Promise<T>> sync, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> result)Description copied from interface:CoreContext
Call to execute the given blocking handler on a worker thread that is scoped to the current context.- Specified by:
blocking
in interfaceCoreContext
- Type Parameters:
T
- type parameter.- Parameters:
sync
- a method that is blocking, to be executed on worker thread.result
- handler for the result of the blocking execution.
-
blocking
public <T> void blocking(io.vertx.core.Handler<io.vertx.core.Promise<T>> sync, boolean ordered, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> result)Description copied from interface:CoreContext
Call to execute the given blocking handler on a worker thread that is scoped to the current context.- Specified by:
blocking
in interfaceCoreContext
- Type Parameters:
T
- type parameter for the result- Parameters:
sync
- a handler that executes blocking codeordered
- if true, indicates that the tasks must be completed in the same order as they are started.result
- handler for the result that is called asynchronously
-
logger
- Specified by:
logger
in interfaceCoreContext
- Parameters:
aClass
- added as metadata to all logged events.- Returns:
- get a new instance of a logger.
-
close
public void close()Description copied from interface:CoreContext
Shuts down the context and underlying pools and connections.- Specified by:
close
in interfaceCoreContext
-
close
- Specified by:
close
in interfaceCoreContext
- Parameters:
handler
- called when the context has closed or failed closing.
-
vertx
public io.vertx.core.Vertx vertx()- Specified by:
vertx
in interfaceCoreContext
- Returns:
- the vertx instance.
-