@Override
 public HttpHandler createHttpHandler(Predicate predicate, final HttpHandler next) {
   // this is a bit of a hack at the moment. Basically we only want to create a single mod_cluster
   // instance
   // not matter how many filter refs use it, also mod_cluster at this point has no way
   // to specify the next handler. To get around this we invoke the mod_proxy handler
   // and then if it has not dispatched or handled the request then we know that we can
   // just pass it on to the next handler
   final HttpHandler mcmp =
       managementAccessPredicate != null
           ? Handlers.predicate(managementAccessPredicate, config.create(modCluster, next), next)
           : config.create(modCluster, next);
   final HttpHandler proxyHandler = modCluster.getProxyHandler();
   HttpHandler theHandler =
       new HttpHandler() {
         @Override
         public void handleRequest(HttpServerExchange exchange) throws Exception {
           proxyHandler.handleRequest(exchange);
           if (!exchange.isDispatched() && !exchange.isComplete()) {
             exchange.setResponseCode(200);
             mcmp.handleRequest(exchange);
           }
         }
       };
   UndertowLogger.ROOT_LOGGER.debug("HttpHandler for mod_cluster MCMP created.");
   if (predicate != null) {
     return new PredicateHandler(predicate, theHandler, next);
   } else {
     return theHandler;
   }
 }
  @Override
  public synchronized void start(StartContext context) throws StartException {
    super.start(context);

    SecurityRealm realm = securityRealm.getOptionalValue();

    // TODO: SSL support for the client
    // TODO: wire up idle timeout when new version of undertow arrives
    final ModCluster.Builder modClusterBuilder;
    final XnioWorker worker = workerInjectedValue.getValue();
    if (realm == null) {
      modClusterBuilder = ModCluster.builder(worker);
    } else {
      SSLContext sslContext = realm.getSSLContext();
      OptionMap.Builder builder = OptionMap.builder();
      builder.set(Options.USE_DIRECT_BUFFERS, true);
      OptionMap combined = builder.getMap();

      XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
      modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
    }
    modClusterBuilder
        .setHealthCheckInterval(healthCheckInterval)
        .setMaxRequestTime(maxRequestTime)
        .setCacheConnections(cachedConnections)
        .setQueueNewRequests(requestQueueSize > 0)
        .setRequestQueueSize(requestQueueSize)
        .setRemoveBrokenNodes(removeBrokenNodes)
        .setTtl(connectionIdleTimeout)
        .setMaxConnections(connectionsPerThread)
        .setUseAlias(useAlias);

    modCluster = modClusterBuilder.build();

    MCMPConfig.Builder builder = MCMPConfig.builder();
    InetAddress multicastAddress = advertiseSocketBinding.getValue().getMulticastAddress();
    if (multicastAddress == null) {
      throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
    }
    if (advertiseFrequency > 0) {
      builder
          .enableAdvertise()
          .setAdvertiseAddress(
              advertiseSocketBinding.getValue().getSocketAddress().getAddress().getHostAddress())
          .setAdvertiseGroup(multicastAddress.getHostAddress())
          .setAdvertisePort(advertiseSocketBinding.getValue().getPort())
          .setAdvertiseFrequency(advertiseFrequency)
          .setPath(advertisePath)
          .setProtocol(advertiseProtocol)
          .setSecurityKey(securityKey);
    }
    builder.setManagementHost(managementSocketBinding.getValue().getSocketAddress().getHostName());
    builder.setManagementPort(managementSocketBinding.getValue().getSocketAddress().getPort());

    config = builder.build();

    if (advertiseFrequency > 0) {
      try {
        modCluster.advertise(config);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    modCluster.start();
  }