Class MultiHandler

All Implemented Interfaces:
CoreDeployment, CoreHandler, Receiver<Request>

public class MultiHandler extends Object implements CoreHandler
The MultiHandler is capable of routing a request into any of the given handlers using the The requests target should match the address of the handler. If no handlers matching the processed request is found, then a #HandlerMissingException is thrown.
  • Constructor Details

    • MultiHandler

      public MultiHandler(List<CoreHandler> handlers)
      handlers - same as @see #MultiHandler(CoreHandler...)
    • MultiHandler

      public MultiHandler(CoreHandler... handlers)
      handlers - a list of handlers to mount on the multi-handler. When a request is processed the requests target will be used to lookup a CoreHandler with a matching address.
  • Method Details

    • setAddress

      public MultiHandler setAddress(String address)
      Set the address to use - required when deployed in a cluster listener.
      address - the address to listen on.
    • add

      public io.vertx.core.Future<Void> add(CoreHandler handler)
      Adds a sub-handler to the MultiHandler, may be called when the MultiHandler is already deployed - but then it requires the handlers address not to be registered.
      handler - the handler to add.
      a Future that will be completed when the handler is started if the MultiHandler is already deployed. If the MultiHandler is not deployed - the future is completed.
    • remove

      public io.vertx.core.Future<Void> remove(String address)
      Stops the given handler.
      address - address of the handler to be removed - if the MultiHandler is started then the given handler will be stopped.
      a future that is completed when the handler is removed. If the multihandler is not yet started - then the future will be completed.
    • init

      public void init(CoreContext core)
      Description copied from interface: CoreDeployment
      Init method that is called with the context that the service was deployed from.
      Specified by:
      init in interface CoreDeployment
      core - the core context to use.
    • start

      public void start(io.vertx.core.Promise<Void> start)
      Specified by:
      start in interface CoreDeployment
      start - complete when asynchronous startup is completed.
    • stop

      public void stop(io.vertx.core.Promise<Void> stop)
      Specified by:
      stop in interface CoreDeployment
      stop - complete when asynchronous shutdown is completed.
    • handle

      public void handle(Request request)
      Description copied from interface: Receiver
      Handles an incoming request without exception handling.
      Specified by:
      handle in interface Receiver<Request>
      request - the request to be handled.
    • address

      public String address()
      Specified by:
      address in interface CoreHandler
      the address of the handler. If not implemented the @Address annotation will be used, if missing an error is thrown.

      Could potentially lead to Runtime errors but is allowed here as this is called during deployment. Reconsider this decision later.

    • toString

      public String toString()
      toString in class Object