@Override
  public ServiceBuilder<SessionManagerFactory<TransactionBatch>> build(ServiceTarget target) {
    ServiceName templateCacheServiceName = getCacheServiceName(this.configuration.getCacheName());
    String templateCacheName = templateCacheServiceName.getSimpleName();
    String containerName = templateCacheServiceName.getParent().getSimpleName();
    String cacheName = this.configuration.getDeploymentName();

    new TemplateConfigurationBuilder(containerName, cacheName, templateCacheName)
        .build(target)
        .install();

    new CacheBuilder<>(containerName, cacheName)
        .build(target)
        .addAliases(InfinispanRouteLocatorBuilder.getCacheServiceAlias(cacheName))
        .install();

    new AliasServiceBuilder<>(
            InfinispanRouteLocatorBuilder.getNodeFactoryServiceAlias(cacheName),
            CacheGroupServiceName.NODE_FACTORY.getServiceName(
                containerName, RouteCacheGroupBuilderProvider.CACHE_NAME),
            NodeFactory.class)
        .build(target)
        .install();
    new AliasServiceBuilder<>(
            InfinispanRouteLocatorBuilder.getRegistryServiceAlias(cacheName),
            CacheGroupServiceName.REGISTRY.getServiceName(
                containerName, RouteCacheGroupBuilderProvider.CACHE_NAME),
            Registry.class)
        .build(target)
        .install();

    return target
        .addService(this.getServiceName(), new ValueService<>(this))
        .addDependency(
            CacheServiceName.CACHE.getServiceName(containerName, cacheName),
            Cache.class,
            this.cache)
        .addDependency(
            CacheContainerServiceName.AFFINITY.getServiceName(containerName),
            KeyAffinityServiceFactory.class,
            this.affinityFactory)
        .addDependency(
            GroupServiceName.COMMAND_DISPATCHER.getServiceName(containerName),
            CommandDispatcherFactory.class,
            this.dispatcherFactory)
        .addDependency(
            InfinispanRouteLocatorBuilder.getNodeFactoryServiceAlias(cacheName),
            NodeFactory.class,
            this.nodeFactory)
        .setInitialMode(ServiceController.Mode.ON_DEMAND);
  }
 public static ServiceName getServiceName(String contextName) {
   ServiceName deploymentServiceName = Services.deploymentUnitName(contextName);
   return SERVICE_NAME_BASE.append(deploymentServiceName.getSimpleName());
 }
  static void installHttpManagementConnector(
      final OperationContext context,
      final ModelNode model,
      final ServiceTarget serviceTarget,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    ServiceName socketBindingServiceName = null;
    ServiceName secureSocketBindingServiceName = null;
    ServiceName interfaceSvcName = null;
    int port = -1;
    int securePort = -1;

    final ModelNode interfaceModelNode = validateResolvedModel(INTERFACE, context, model);
    if (interfaceModelNode.isDefined()) {
      // Legacy config
      String interfaceName = interfaceModelNode.asString();
      interfaceSvcName = NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(interfaceName);
      final ModelNode portNode = HTTP_PORT.resolveModelAttribute(context, model);
      port = portNode.isDefined() ? portNode.asInt() : -1;
      final ModelNode securePortNode = HTTPS_PORT.resolveModelAttribute(context, model);
      securePort = securePortNode.isDefined() ? securePortNode.asInt() : -1;

      // Log the config
      if (securePort > -1) {
        if (port > -1) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPortAndSecurePort(
              interfaceName, port, securePort);
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecurePort(
              interfaceName, securePort);
        }
      } else if (port > -1) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPort(interfaceName, port);
      }
    } else {
      // Socket-binding reference based config
      final ModelNode socketBindingNode = SOCKET_BINDING.resolveModelAttribute(context, model);
      if (socketBindingNode.isDefined()) {
        final String bindingName = socketBindingNode.asString();
        socketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }
      final ModelNode secureSocketBindingNode =
          SECURE_SOCKET_BINDING.resolveModelAttribute(context, model);
      if (secureSocketBindingNode.isDefined()) {
        final String bindingName = secureSocketBindingNode.asString();
        secureSocketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }

      // Log the config
      if (socketBindingServiceName != null) {
        if (secureSocketBindingServiceName != null) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocketAndSecureSocket(
              socketBindingServiceName.getSimpleName(),
              secureSocketBindingServiceName.getSimpleName());
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocket(
              socketBindingServiceName.getSimpleName());
        }
      } else if (secureSocketBindingServiceName != null) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecureSocket(
            secureSocketBindingServiceName.getSimpleName());
      }
    }

    ServiceName realmSvcName = null;
    final ModelNode realmNode = SECURITY_REALM.resolveModelAttribute(context, model);
    if (realmNode.isDefined()) {
      realmSvcName = SecurityRealmService.BASE_SERVICE_NAME.append(realmNode.asString());
    } else {
      ServerLogger.ROOT_LOGGER.httpManagementInterfaceIsUnsecured();
    }
    boolean consoleEnabled = model.get(ModelDescriptionConstants.CONSOLE_ENABLED).asBoolean(true);
    ConsoleMode consoleMode;
    if (consoleEnabled) {
      consoleMode =
          context.getRunningMode() == RunningMode.ADMIN_ONLY
              ? ConsoleMode.ADMIN_ONLY
              : ConsoleMode.CONSOLE;
    } else {
      consoleMode = ConsoleMode.NO_CONSOLE;
    }

    ServerEnvironment environment =
        (ServerEnvironment)
            context
                .getServiceRegistry(false)
                .getRequiredService(ServerEnvironmentService.SERVICE_NAME)
                .getValue();
    final HttpManagementService service =
        new HttpManagementService(consoleMode, environment.getProductConfig().getConsoleSlot());
    ServiceBuilder<HttpManagement> builder =
        serviceTarget
            .addService(HttpManagementService.SERVICE_NAME, service)
            .addDependency(
                Services.JBOSS_SERVER_CONTROLLER,
                ModelController.class,
                service.getModelControllerInjector())
            .addDependency(
                SocketBindingManagerImpl.SOCKET_BINDING_MANAGER,
                SocketBindingManager.class,
                service.getSocketBindingManagerInjector())
            .addDependency(
                ControlledProcessStateService.SERVICE_NAME,
                ControlledProcessStateService.class,
                service.getControlledProcessStateServiceInjector())
            .addInjection(
                service.getExecutorServiceInjector(),
                Executors.newCachedThreadPool(
                    new JBossThreadFactory(
                        new ThreadGroup("HttpManagementService-threads"),
                        Boolean.FALSE,
                        null,
                        "%G - %t",
                        null,
                        null,
                        AccessController.getContext())));

    if (interfaceSvcName != null) {
      builder
          .addDependency(
              interfaceSvcName, NetworkInterfaceBinding.class, service.getInterfaceInjector())
          .addInjection(service.getPortInjector(), port)
          .addInjection(service.getSecurePortInjector(), securePort);
    } else {
      if (socketBindingServiceName != null) {
        builder.addDependency(
            socketBindingServiceName, SocketBinding.class, service.getSocketBindingInjector());
      }
      if (secureSocketBindingServiceName != null) {
        builder.addDependency(
            secureSocketBindingServiceName,
            SocketBinding.class,
            service.getSecureSocketBindingInjector());
      }
    }

    if (realmSvcName != null) {
      builder.addDependency(
          realmSvcName, SecurityRealmService.class, service.getSecurityRealmInjector());
    }

    if (verificationHandler != null) {
      builder.addListener(verificationHandler);
    }
    ServiceController<?> controller = builder.install();
    if (newControllers != null) {
      newControllers.add(controller);
    }
  }