Class SystemContext

java.lang.Object
com.codingchili.core.context.SystemContext
All Implemented Interfaces:
CoreContext
Direct Known Subclasses:
ContextMock, StorageContext

public class SystemContext extends Object implements CoreContext
Implementation of the CoreContext, each context gets its own worker pool.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected io.vertx.core.Vertx
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Creates a new vertx instance to be used for this context.
    protected
    Creates a new system context that shares vertx instance with the given context.
  • Method Summary

    Modifier and Type
    Method
    Description
    <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
    Shuts down the context and underlying pools and connections.
    void
    close​(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
     
    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>
    deploy​(String target)
    Instantiates an object of the given class identifier and determines the type that should be deployed.
    io.vertx.core.Future<String>
    Deploys a new handler in the cluster from given handler with a completion handler.
    io.vertx.core.Future<String>
    Deploys the given verticle with a completion handler.
    logger​(Class aClass)
     
     
    metrics​(String registryName)
    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>
    Deploys the given verticle with a completion handler.
    io.vertx.core.Future<io.vertx.core.CompositeFuture>
     
    void
    stop​(String deploymentId)
    Undeploys a deployed handler by the deployment id.
     
    long
    timer​(long ms, io.vertx.core.Handler<Long> handler)
    Sets a timer that executes the given handler after the given time.
    io.vertx.core.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

      protected SystemContext(CoreContext context)
      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

      public MetricCollector metrics()
      Specified by:
      metrics in interface CoreContext
      Returns:
      the metrics collector.
    • metrics

      public MetricCollector metrics(String registryName)
      Description copied from interface: CoreContext
      Creates a new metric namespace using the registryName.
      Specified by:
      metrics in interface CoreContext
      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 interface CoreContext
      Returns:
      get the EventBus attached to the vertx instance.
    • system

      public SystemSettings system()
      Specified by:
      system in interface CoreContext
      Returns:
      the system configuration.
    • periodic

      public void periodic(TimerSource timeout, io.vertx.core.Handler<Long> handler)
      Description copied from interface: CoreContext
      Set a periodic timer that uses a timersource to adjust interval during runtime.
      Specified by:
      periodic in interface CoreContext
      Parameters:
      timeout - a timer source that may change period during runtime.
      handler - the handler to be invoked when each interval ends.
    • timer

      public long timer(long ms, io.vertx.core.Handler<Long> handler)
      Description copied from interface: CoreContext
      Sets a timer that executes the given handler after the given time.
      Specified by:
      timer in interface CoreContext
      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 interface CoreContext
      Parameters:
      timer - the id of the timer to be stopped.
    • deploy

      public io.vertx.core.Future<String> deploy(String target)
      Description copied from interface: CoreContext
      Instantiates an object of the given class identifier and determines the type that should be deployed. May be a CoreHandler CoreService CoreListener or a plain Verticle.
      Specified by:
      deploy in interface CoreContext
      Parameters:
      target - the target class to deploy.
      Returns:
      future completed on deployment.
    • handler

      public io.vertx.core.Future<String> handler(Supplier<CoreHandler> handler)
      Description copied from interface: CoreContext
      Deploys a new handler in the cluster from given handler with a completion handler.
      Specified by:
      handler in interface CoreContext
      Parameters:
      handler - the handler to be used to handle incoming requests.
      Returns:
      a future to be completed on deployment completion.
    • listener

      public io.vertx.core.Future<String> listener(Supplier<CoreListener> listener)
      Description copied from interface: CoreContext
      Deploys the given verticle with a completion handler.
      Specified by:
      listener in interface CoreContext
      Parameters:
      listener - the verticle to be deployed.
      Returns:
      future completed on deployment completion.
    • service

      public io.vertx.core.Future<String> service(Supplier<CoreService> service)
      Description copied from interface: CoreContext
      Deploys the given verticle with a completion handler.
      Specified by:
      service in interface CoreContext
      Parameters:
      service - the verticle to be deployed.
      Returns:
      future to be completed on deployment completion.
    • stop

      public void stop(String deploymentId)
      Description copied from interface: CoreContext
      Undeploys a deployed handler by the deployment id.
      Specified by:
      stop in interface CoreContext
      Parameters:
      deploymentId - the id of the deployment to undeploy.
    • stop

      public io.vertx.core.Future<io.vertx.core.CompositeFuture> stop()
      Specified by:
      stop in interface CoreContext
    • 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 interface CoreContext
      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 interface CoreContext
      Type Parameters:
      T - type parameter for the result
      Parameters:
      sync - a handler that executes blocking code
      ordered - 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

      public Logger logger(Class aClass)
      Specified by:
      logger in interface CoreContext
      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 interface CoreContext
    • close

      public void close(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      Specified by:
      close in interface CoreContext
      Parameters:
      handler - called when the context has closed or failed closing.
    • vertx

      public io.vertx.core.Vertx vertx()
      Specified by:
      vertx in interface CoreContext
      Returns:
      the vertx instance.