コード例 #1
0
  ServiceController<?> installContainerConfigurationService(
      ServiceTarget target,
      String containerName,
      String defaultCache,
      boolean statistics,
      ModuleIdentifier moduleId,
      String stack,
      Transport transportConfig,
      String transportExecutor,
      String listenerExecutor,
      String evictionExecutor,
      String replicationQueueExecutor,
      ServiceVerificationHandler verificationHandler) {

    final ServiceName configServiceName =
        EmbeddedCacheManagerConfigurationService.getServiceName(containerName);
    final EmbeddedCacheManagerDependencies dependencies =
        new EmbeddedCacheManagerDependencies(transportConfig);
    final Service<EmbeddedCacheManagerConfiguration> service =
        new EmbeddedCacheManagerConfigurationService(
            containerName, defaultCache, statistics, moduleId, dependencies);
    final ServiceBuilder<EmbeddedCacheManagerConfiguration> configBuilder =
        target
            .addService(configServiceName, service)
            .addDependency(
                Services.JBOSS_SERVICE_MODULE_LOADER,
                ModuleLoader.class,
                dependencies.getModuleLoaderInjector())
            .addDependency(
                MBeanServerService.SERVICE_NAME,
                MBeanServer.class,
                dependencies.getMBeanServerInjector())
            .setInitialMode(ServiceController.Mode.ON_DEMAND);

    // add these dependencies only if we have a transport defined
    if (transportConfig != null) {
      if (transportExecutor != null) {
        addExecutorDependency(
            configBuilder, transportExecutor, transportConfig.getExecutorInjector());
      }
      configBuilder.addDependency(
          ChannelFactoryService.getServiceName(stack),
          ChannelFactory.class,
          transportConfig.getChannelFactoryInjector());
    }

    addExecutorDependency(
        configBuilder, listenerExecutor, dependencies.getListenerExecutorInjector());
    addScheduledExecutorDependency(
        configBuilder, evictionExecutor, dependencies.getEvictionExecutorInjector());
    addScheduledExecutorDependency(
        configBuilder,
        replicationQueueExecutor,
        dependencies.getReplicationQueueExecutorInjector());

    return configBuilder.install();
  }
コード例 #2
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    // Because we use child resources in a read-only manner to configure the cache container,
    // replace the local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();

    String defaultCache = model.require(ModelKeys.DEFAULT_CACHE).asString();

    boolean hasTransport =
        model.hasDefined(ModelKeys.TRANSPORT)
            && model.get(ModelKeys.TRANSPORT).hasDefined(ModelKeys.TRANSPORT_NAME);
    Transport transportConfig = hasTransport ? new Transport() : null;
    EmbeddedCacheManagerDependencies dependencies =
        new EmbeddedCacheManagerDependencies(transportConfig);

    ServiceName[] aliases = null;
    if (model.hasDefined(ModelKeys.ALIASES)) {
      List<ModelNode> list = operation.get(ModelKeys.ALIASES).asList();
      aliases = new ServiceName[list.size()];
      for (int i = 0; i < list.size(); i++) {
        aliases[i] = EmbeddedCacheManagerService.getServiceName(list.get(i).asString());
      }
    }

    ServiceTarget target = context.getServiceTarget();
    ServiceName serviceName = EmbeddedCacheManagerService.getServiceName(name);
    ServiceBuilder<EmbeddedCacheManager> containerBuilder =
        target
            .addService(
                serviceName, new EmbeddedCacheManagerService(name, defaultCache, dependencies))
            .addDependency(
                DependencyType.OPTIONAL,
                ServiceName.JBOSS.append("mbean", "server"),
                MBeanServer.class,
                dependencies.getMBeanServerInjector())
            .addAliases(aliases)
            .setInitialMode(ServiceController.Mode.ON_DEMAND);

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheContainerJndiName(name))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                serviceName,
                CacheContainer.class,
                new ManagedReferenceInjector<CacheContainer>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.ON_DEMAND);
    newControllers.add(binderBuilder.install());

    if (hasTransport) {
      String stack = null;
      ModelNode transport = model.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);
      if (transport.hasDefined(ModelKeys.STACK)) {
        stack = transport.get(ModelKeys.STACK).asString();
      }
      if (transport.hasDefined(ModelKeys.LOCK_TIMEOUT)) {
        transportConfig.setLockTimeout(transport.get(ModelKeys.LOCK_TIMEOUT).asLong());
      }
      addExecutorDependency(
          containerBuilder, transport, ModelKeys.EXECUTOR, transportConfig.getExecutorInjector());

      ServiceName channelServiceName = ChannelService.getServiceName(name);
      containerBuilder.addDependency(
          channelServiceName, Channel.class, transportConfig.getChannelInjector());

      InjectedValue<ChannelFactory> channelFactory = new InjectedValue<ChannelFactory>();
      ServiceBuilder<Channel> channelBuilder =
          target
              .addService(channelServiceName, new ChannelService(name, channelFactory))
              .addDependency(
                  ChannelFactoryService.getServiceName(stack), ChannelFactory.class, channelFactory)
              .setInitialMode(ServiceController.Mode.ON_DEMAND);
      newControllers.add(channelBuilder.install());
    }

    addExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.LISTENER_EXECUTOR,
        dependencies.getListenerExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.EVICTION_EXECUTOR,
        dependencies.getEvictionExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.REPLICATION_QUEUE_EXECUTOR,
        dependencies.getReplicationQueueExecutorInjector());

    newControllers.add(containerBuilder.install());

    log.debugf("%s cache container installed", name);
  }