예제 #1
0
  void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    // get container and cache addresses
    final PathAddress cacheAddress = getCacheAddressFromOperation(operation);
    final PathAddress containerAddress = getCacheContainerAddressFromOperation(operation);
    // get container and cache names
    final String cacheName = cacheAddress.getLastElement().getValue();
    final String containerName = containerAddress.getLastElement().getValue();

    // remove all services started by CacheAdd, in reverse order
    // remove the binder service
    ModelNode resolvedValue = null;
    final String jndiNameString =
        (resolvedValue = CommonAttributes.JNDI_NAME.resolveModelAttribute(context, model))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String jndiName =
        InfinispanJndiName.createCacheJndiNameOrDefault(jndiNameString, containerName, cacheName);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    context.removeService(bindInfo.getBinderServiceName());
    // remove the CacheService instance
    context.removeService(CacheService.getServiceName(containerName, cacheName));
    // remove the cache configuration service
    context.removeService(CacheConfigurationService.getServiceName(containerName, cacheName));

    log.debugf("cache %s removed for container %s", cacheName, containerName);
  }
예제 #2
0
  ServiceController<?> installJndiService(
      ServiceTarget target,
      String containerName,
      String jndiName,
      ServiceVerificationHandler verificationHandler) {

    final ServiceName containerServiceName =
        EmbeddedCacheManagerService.getServiceName(containerName);
    final ContextNames.BindInfo binding = createCacheContainerBinding(jndiName, containerName);

    final BinderService binder = new BinderService(binding.getBindName());
    return target
        .addService(binding.getBinderServiceName(), binder)
        .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(binding.getBindName()))
        .addDependency(
            containerServiceName,
            CacheContainer.class,
            new ManagedReferenceInjector<CacheContainer>(binder.getManagedObjectInjector()))
        .addDependency(
            binding.getParentContextServiceName(),
            ServiceBasedNamingStore.class,
            binder.getNamingStoreInjector())
        .setInitialMode(ServiceController.Mode.PASSIVE)
        .install();
  }
예제 #3
0
  Collection<ServiceController<?>> installChannelServices(
      ServiceTarget target,
      String containerName,
      String cluster,
      String stack,
      ServiceVerificationHandler verificationHandler) {

    ServiceName name = ChannelService.getServiceName(containerName);
    ContextNames.BindInfo bindInfo = createChannelBinding(containerName);
    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceController<?> binderService =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(bindInfo.getBindName()))
            .addDependency(
                name,
                Channel.class,
                new ManagedReferenceInjector<Channel>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE)
            .install();

    InjectedValue<ChannelFactory> channelFactory = new InjectedValue<>();
    ServiceController<?> channelService =
        AsynchronousService.addService(target, name, new ChannelService(cluster, channelFactory))
            .addDependency(
                ChannelFactoryService.getServiceName(stack), ChannelFactory.class, channelFactory)
            .setInitialMode(ServiceController.Mode.ON_DEMAND)
            .install();

    return Arrays.asList(binderService, channelService);
  }
예제 #4
0
  @SuppressWarnings("rawtypes")
  ServiceController<?> installJndiService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      String jndiNameString,
      ServiceVerificationHandler verificationHandler) {

    final String jndiName =
        InfinispanJndiName.createCacheJndiNameOrDefault(jndiNameString, containerName, cacheName);
    final ServiceName cacheServiceName = CacheService.getServiceName(containerName, cacheName);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binder = new BinderService(bindInfo.getBindName());
    return target
        .addService(bindInfo.getBinderServiceName(), binder)
        .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
        .addDependency(
            cacheServiceName,
            Cache.class,
            new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
        .addDependency(
            bindInfo.getParentContextServiceName(),
            ServiceBasedNamingStore.class,
            binder.getNamingStoreInjector())
        .setInitialMode(ServiceController.Mode.PASSIVE)
        .install();
  }
예제 #5
0
  private void initializeModeShapeEngine(
      final OperationContext context,
      final ModelNode operation,
      ModelNode model,
      final List<ServiceController<?>> newControllers) {
    ServiceTarget target = context.getServiceTarget();

    final JBossLifeCycleListener shutdownListener = new JBossLifeCycleListener();

    engine = buildModeShapeEngine(model);

    // Engine service
    ServiceBuilder<JcrEngine> engineBuilder =
        target.addService(ModeShapeServiceNames.ENGINE, engine);
    engineBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    ServiceController<JcrEngine> controller = engineBuilder.install();
    controller.getServiceContainer().addTerminateListener(shutdownListener);
    newControllers.add(controller);

    // JNDI Binding
    final ReferenceFactoryService<JcrEngine> referenceFactoryService =
        new ReferenceFactoryService<JcrEngine>();
    final ServiceName referenceFactoryServiceName =
        ModeShapeServiceNames.ENGINE.append("reference-factory"); // $NON-NLS-1$
    final ServiceBuilder<?> referenceBuilder =
        target.addService(referenceFactoryServiceName, referenceFactoryService);
    referenceBuilder.addDependency(
        ModeShapeServiceNames.ENGINE, JcrEngine.class, referenceFactoryService.getInjector());
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    final ContextNames.BindInfo bindInfo =
        ContextNames.bindInfoFor(ModeShapeJndiNames.JNDI_BASE_NAME);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder =
        target.addService(bindInfo.getBinderServiceName(), binderService);
    binderBuilder.addDependency(
        ModeShapeServiceNames.ENGINE,
        JcrEngine.class,
        new ManagedReferenceInjector<JcrEngine>(binderService.getManagedObjectInjector()));
    binderBuilder.addDependency(
        bindInfo.getParentContextServiceName(),
        ServiceBasedNamingStore.class,
        binderService.getNamingStoreInjector());
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    Logger.getLogger(getClass())
        .debug("Binding ModeShape to JNDI name '{0}'", bindInfo.getAbsoluteJndiName());

    newControllers.add(referenceBuilder.install());
    newControllers.add(binderBuilder.install());
  }
예제 #6
0
  void removeRuntimeServices(
      OperationContext context, ModelNode operation, ModelNode containerModel, ModelNode cacheModel)
      throws OperationFailedException {
    // get container and cache addresses
    final PathAddress cacheAddress = getCacheAddressFromOperation(operation);
    final PathAddress containerAddress = getCacheContainerAddressFromOperation(operation);

    // get container and cache names
    final String cacheName = cacheAddress.getLastElement().getValue();
    final String containerName = containerAddress.getLastElement().getValue();

    // remove all services started by CacheAdd, in reverse order
    // remove the binder service
    ModelNode resolvedValue = null;
    final String jndiName =
        (resolvedValue =
                    CacheResourceDefinition.JNDI_NAME.resolveModelAttribute(context, cacheModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;

    String defaultCacheName =
        CacheContainerResourceDefinition.DEFAULT_CACHE
            .resolveModelAttribute(context, containerModel)
            .asString();
    boolean defaultCache = cacheName.equals(defaultCacheName);

    ContextNames.BindInfo binding =
        createCacheBinding(
            (jndiName != null)
                ? JndiNameFactory.parse(jndiName)
                : createJndiName(containerName, cacheName));
    context.removeService(binding.getBinderServiceName());
    // remove the CacheService instance
    context.removeService(CacheService.getServiceName(containerName, cacheName));
    // remove the cache configuration service
    context.removeService(CacheConfigurationService.getServiceName(containerName, cacheName));

    for (CacheServiceProvider provider :
        ServiceLoader.load(
            CacheServiceProvider.class, CacheServiceProvider.class.getClassLoader())) {
      for (ServiceName name : provider.getServiceNames(containerName, cacheName, defaultCache)) {
        context.removeService(name);
      }
    }

    log.debugf("cache %s removed for container %s", cacheName, containerName);
  }
  public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      deploymentMD = getDeployer().deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
      }
      sqlDataSource =
          new WildFlyDataSource(
              (javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
      DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
      CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
      final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
      startContext
          .getController()
          .getServiceContainer()
          .addService(cdServiceName, cdService)
          // The dependency added must be the JNDI name which for subsystem resources is an alias.
          // This service
          // is also used in deployments where the capability service name is not registered for the
          // service.
          .addDependency(getServiceName(jndiName))
          .setInitialMode(ServiceController.Mode.ACTIVE)
          .install();
    } catch (Throwable t) {
      throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
  }
예제 #8
0
  @SuppressWarnings("rawtypes")
  ServiceController<?> installJndiService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      boolean defaultCache,
      String jndiName,
      ServiceVerificationHandler verificationHandler) {

    final ServiceName cacheServiceName = CacheService.getServiceName(containerName, cacheName);
    final ContextNames.BindInfo binding =
        createCacheBinding(
            (jndiName != null)
                ? JndiNameFactory.parse(jndiName)
                : createJndiName(containerName, cacheName));
    final BinderService binder = new BinderService(binding.getBindName());
    ServiceBuilder<?> builder =
        target
            .addService(binding.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(binding.getBindName()))
            .addDependency(
                cacheServiceName,
                Cache.class,
                new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
            .addDependency(
                binding.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    if (defaultCache) {
      ContextNames.BindInfo defaultBinding =
          createCacheBinding(createJndiName(containerName, CacheContainer.DEFAULT_CACHE_ALIAS));
      builder.addAliases(
          defaultBinding.getBinderServiceName(),
          ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(defaultBinding.getBindName()));
    }
    return builder.install();
  }
예제 #9
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, replace the
    // local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    // Configuration to hold the operation data
    ConfigurationBuilder builder =
        new ConfigurationBuilder().read(getDefaultConfiguration(this.mode));

    // create a list for dependencies which may need to be added during processing
    List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>();

    // process cache configuration ModelNode describing overrides to defaults
    processModelNode(model, builder, dependencies);

    // get all required addresses, names and service names
    PathAddress cacheAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    PathAddress containerAddress = cacheAddress.subAddress(0, cacheAddress.size() - 1);
    String cacheName = cacheAddress.getLastElement().getValue();
    String containerName = containerAddress.getLastElement().getValue();
    ServiceName containerServiceName = EmbeddedCacheManagerService.getServiceName(containerName);
    ServiceName cacheServiceName = containerServiceName.append(cacheName);
    ServiceName cacheConfigurationServiceName =
        CacheConfigurationService.getServiceName(containerName, cacheName);

    // get container Model
    Resource rootResource = context.getRootResource();
    ModelNode container = rootResource.navigate(containerAddress).getModel();

    // get default cache of the container and start mode
    String defaultCache = container.require(ModelKeys.DEFAULT_CACHE).asString();
    ServiceController.Mode initialMode =
        model.hasDefined(ModelKeys.START)
            ? StartMode.valueOf(model.get(ModelKeys.START).asString()).getMode()
            : ServiceController.Mode.ON_DEMAND;

    // install the cache configuration service (configures a cache)
    ServiceTarget target = context.getServiceTarget();
    InjectedValue<EmbeddedCacheManager> containerInjection =
        new InjectedValue<EmbeddedCacheManager>();
    CacheConfigurationDependencies cacheConfigurationDependencies =
        new CacheConfigurationDependencies(containerInjection);
    CacheConfigurationService cacheConfigurationService =
        new CacheConfigurationService(cacheName, builder, cacheConfigurationDependencies);

    ServiceBuilder<Configuration> configBuilder =
        target
            .addService(cacheConfigurationServiceName, cacheConfigurationService)
            .addDependency(containerServiceName, EmbeddedCacheManager.class, containerInjection)
            .setInitialMode(ServiceController.Mode.PASSIVE);

    Configuration config = builder.build();
    if (config.invocationBatching().enabled()) {
      cacheConfigurationDependencies
          .getTransactionManagerInjector()
          .inject(BatchModeTransactionManager.getInstance());
    } else if (config.transaction().transactionMode()
        == org.infinispan.transaction.TransactionMode.TRANSACTIONAL) {
      configBuilder.addDependency(
          TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
          TransactionManager.class,
          cacheConfigurationDependencies.getTransactionManagerInjector());
      if (config.transaction().useSynchronization()) {
        configBuilder.addDependency(
            TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY,
            TransactionSynchronizationRegistry.class,
            cacheConfigurationDependencies.getTransactionSynchronizationRegistryInjector());
      }
    }

    // add in any additional dependencies resulting from ModelNode parsing
    for (Dependency<?> dependency : dependencies) {
      this.addDependency(configBuilder, dependency);
    }
    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      configBuilder.addAliases(CacheConfigurationService.getServiceName(containerName, null));
    }
    newControllers.add(configBuilder.install());
    log.debugf(
        "Cache configuration service for %s installed for container %s", cacheName, containerName);

    // now install the corresponding cache service (starts a configured cache)
    CacheDependencies cacheDependencies = new CacheDependencies(containerInjection);
    CacheService<Object, Object> cacheService =
        new CacheService<Object, Object>(cacheName, cacheDependencies);

    ServiceBuilder<Cache<Object, Object>> cacheBuilder =
        target
            .addService(cacheServiceName, cacheService)
            .addDependency(cacheConfigurationServiceName)
            .setInitialMode(initialMode);

    if (config.transaction().recovery().enabled()) {
      cacheBuilder.addDependency(
          TxnServices.JBOSS_TXN_ARJUNA_RECOVERY_MANAGER,
          XAResourceRecoveryRegistry.class,
          cacheDependencies.getRecoveryRegistryInjector());
    }

    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      cacheBuilder.addAliases(CacheService.getServiceName(containerName, null));
    }

    if (initialMode == ServiceController.Mode.ACTIVE) {
      cacheBuilder.addListener(verificationHandler);
    }

    newControllers.add(cacheBuilder.install());

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheJndiName(containerName, cacheName))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    @SuppressWarnings("rawtypes")
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                cacheServiceName,
                Cache.class,
                new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    newControllers.add(binderBuilder.install());

    log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName);
  }
 public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) {
   return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName());
 }
예제 #11
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);
  }
  public void getResourceValue(
      final ResolutionContext context,
      final ServiceBuilder<?> serviceBuilder,
      final DeploymentPhaseContext phaseContext,
      final Injector<ManagedReferenceFactory> injector)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final EEModuleDescription eeModuleDescription =
        deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final String poolName = uniqueName(context, jndiName);
    final ContextNames.BindInfo bindInfo =
        ContextNames.bindInfoForEnvEntry(
            context.getApplicationName(),
            context.getModuleName(),
            context.getComponentName(),
            !context.isCompUsesModule(),
            jndiName);
    final DeploymentReflectionIndex reflectionIndex =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final boolean securityEnabled =
        phaseContext.getDeploymentUnit().hasAttachment(SecurityAttachments.SECURITY_ENABLED);
    try {
      final Class<?> clazz = module.getClassLoader().loadClass(className);

      clearUnknownProperties(reflectionIndex, clazz, properties);
      populateProperties(reflectionIndex, clazz, properties);
      DsSecurityImpl dsSecurity = new DsSecurityImpl(user, password, null, null);

      if (XADataSource.class.isAssignableFrom(clazz) && transactional) {
        final DsXaPoolImpl xaPool =
            new DsXaPoolImpl(
                minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize),
                initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize),
                maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize),
                Defaults.PREFILL,
                Defaults.USE_STRICT_MIN,
                Defaults.FLUSH_STRATEGY,
                Defaults.IS_SAME_RM_OVERRIDE,
                Defaults.INTERLEAVING,
                Defaults.PAD_XID,
                Defaults.WRAP_XA_RESOURCE,
                Defaults.NO_TX_SEPARATE_POOL,
                Boolean.FALSE,
                null,
                Defaults.FAIR,
                null);
        final ModifiableXaDataSource dataSource =
            new ModifiableXaDataSource(
                transactionIsolation(),
                null,
                dsSecurity,
                null,
                null,
                null,
                null,
                null,
                null,
                poolName,
                true,
                jndiName,
                false,
                false,
                Defaults.CONNECTABLE,
                Defaults.TRACKING,
                Defaults.MCP,
                Defaults.ENLISTMENT_TRACE,
                properties,
                className,
                null,
                null,
                xaPool,
                null);
        final XaDataSourceService xds =
            new XaDataSourceService(
                bindInfo.getBinderServiceName().getCanonicalName(),
                bindInfo,
                module.getClassLoader());
        xds.getDataSourceConfigInjector().inject(dataSource);
        startDataSource(
            xds,
            bindInfo,
            eeModuleDescription,
            context,
            phaseContext.getServiceTarget(),
            serviceBuilder,
            injector,
            securityEnabled);
      } else {
        final DsPoolImpl commonPool =
            new DsPoolImpl(
                minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize),
                initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize),
                maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize),
                Defaults.PREFILL,
                Defaults.USE_STRICT_MIN,
                Defaults.FLUSH_STRATEGY,
                Boolean.FALSE,
                null,
                Defaults.FAIR,
                null);
        final ModifiableDataSource dataSource =
            new ModifiableDataSource(
                url,
                null,
                className,
                null,
                transactionIsolation(),
                properties,
                null,
                dsSecurity,
                null,
                null,
                null,
                null,
                null,
                false,
                poolName,
                true,
                jndiName,
                Defaults.SPY,
                Defaults.USE_CCM,
                transactional,
                Defaults.CONNECTABLE,
                Defaults.TRACKING,
                Defaults.MCP,
                Defaults.ENLISTMENT_TRACE,
                commonPool);
        final LocalDataSourceService ds =
            new LocalDataSourceService(
                bindInfo.getBinderServiceName().getCanonicalName(),
                bindInfo,
                module.getClassLoader());
        ds.getDataSourceConfigInjector().inject(dataSource);
        startDataSource(
            ds,
            bindInfo,
            eeModuleDescription,
            context,
            phaseContext.getServiceTarget(),
            serviceBuilder,
            injector,
            securityEnabled);
      }

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
  }
예제 #13
0
  private void performObjectStoreBoottime(OperationContext context, ModelNode model)
      throws OperationFailedException {
    boolean useJournalStore =
        model.hasDefined(USE_JOURNAL_STORE) && model.get(USE_JOURNAL_STORE).asBoolean();
    final boolean enableAsyncIO =
        TransactionSubsystemRootResourceDefinition.JOURNAL_STORE_ENABLE_ASYNC_IO
            .resolveModelAttribute(context, model)
            .asBoolean();
    final String objectStorePathRef =
        TransactionSubsystemRootResourceDefinition.OBJECT_STORE_RELATIVE_TO
            .resolveModelAttribute(context, model)
            .asString();
    final String objectStorePath =
        TransactionSubsystemRootResourceDefinition.OBJECT_STORE_PATH
            .resolveModelAttribute(context, model)
            .asString();

    final boolean useJdbcStore =
        model.hasDefined(USE_JDBC_STORE) && model.get(USE_JDBC_STORE).asBoolean();
    final String dataSourceJndiName =
        TransactionSubsystemRootResourceDefinition.JDBC_STORE_DATASOURCE
            .resolveModelAttribute(context, model)
            .asString();

    ArjunaObjectStoreEnvironmentService.JdbcStoreConfigBulder confiBuilder =
        new ArjunaObjectStoreEnvironmentService.JdbcStoreConfigBulder();
    confiBuilder
        .setActionDropTable(
            TransactionSubsystemRootResourceDefinition.JDBC_ACTION_STORE_DROP_TABLE
                .resolveModelAttribute(context, model)
                .asBoolean())
        .setStateDropTable(
            TransactionSubsystemRootResourceDefinition.JDBC_STATE_STORE_DROP_TABLE
                .resolveModelAttribute(context, model)
                .asBoolean())
        .setCommunicationDropTable(
            TransactionSubsystemRootResourceDefinition.JDBC_COMMUNICATION_STORE_DROP_TABLE
                .resolveModelAttribute(context, model)
                .asBoolean());

    if (model.hasDefined(
        TransactionSubsystemRootResourceDefinition.JDBC_ACTION_STORE_TABLE_PREFIX.getName()))
      confiBuilder.setActionTablePrefix(
          TransactionSubsystemRootResourceDefinition.JDBC_ACTION_STORE_TABLE_PREFIX
              .resolveModelAttribute(context, model)
              .asString());
    if (model.hasDefined(
        TransactionSubsystemRootResourceDefinition.JDBC_STATE_STORE_TABLE_PREFIX.getName()))
      confiBuilder.setStateTablePrefix(
          TransactionSubsystemRootResourceDefinition.JDBC_STATE_STORE_TABLE_PREFIX
              .resolveModelAttribute(context, model)
              .asString());

    if (model.hasDefined(
        TransactionSubsystemRootResourceDefinition.JDBC_COMMUNICATION_STORE_TABLE_PREFIX.getName()))
      confiBuilder.setCommunicationTablePrefix(
          TransactionSubsystemRootResourceDefinition.JDBC_COMMUNICATION_STORE_TABLE_PREFIX
              .resolveModelAttribute(context, model)
              .asString());

    TransactionLogger.ROOT_LOGGER.debugf(
        "objectStorePathRef=%s, objectStorePath=%s%n", objectStorePathRef, objectStorePath);

    ServiceTarget target = context.getServiceTarget();
    // Configure the ObjectStoreEnvironmentBeans
    final ArjunaObjectStoreEnvironmentService objStoreEnvironmentService =
        new ArjunaObjectStoreEnvironmentService(
            useJournalStore,
            enableAsyncIO,
            objectStorePath,
            objectStorePathRef,
            useJdbcStore,
            dataSourceJndiName,
            confiBuilder.build());
    ServiceBuilder<Void> builder =
        target
            .addService(
                TxnServices.JBOSS_TXN_ARJUNA_OBJECTSTORE_ENVIRONMENT, objStoreEnvironmentService)
            .addDependency(
                PathManagerService.SERVICE_NAME,
                PathManager.class,
                objStoreEnvironmentService.getPathManagerInjector())
            .addDependency(TxnServices.JBOSS_TXN_CORE_ENVIRONMENT);
    if (useJdbcStore) {
      final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(dataSourceJndiName);
      builder.addDependency(bindInfo.getBinderServiceName());
    }
    builder.setInitialMode(ServiceController.Mode.ACTIVE).install();

    TransactionManagerService.addService(target);
    UserTransactionService.addService(target);
    target
        .addService(
            TxnServices.JBOSS_TXN_USER_TRANSACTION_REGISTRY, new UserTransactionRegistryService())
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .install();
    TransactionSynchronizationRegistryService.addService(target);
  }
예제 #14
0
  static void installRuntimeServices(
      OperationContext context,
      PathAddress address,
      ModelNode fullModel,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> controllers)
      throws OperationFailedException {
    String name = address.getLastElement().getValue();

    final String jndiName = getJndiName(fullModel, context);
    final ServiceTarget serviceTarget = context.getServiceTarget();

    final MailSessionConfig config = from(context, fullModel);
    final MailSessionService service = new MailSessionService(config);
    final ServiceName serviceName = MAIL_SESSION_SERVICE_NAME.append(name);
    final ServiceBuilder<?> mailSessionBuilder = serviceTarget.addService(serviceName, service);
    addOutboundSocketDependency(service, mailSessionBuilder, config.getImapServer());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getPop3Server());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getSmtpServer());
    for (CustomServerConfig server : config.getCustomServers()) {
      if (server.getOutgoingSocketBinding() != null) {
        addOutboundSocketDependency(service, mailSessionBuilder, server);
      }
    }

    final ManagedReferenceFactory valueManagedReferenceFactory =
        new MailSessionManagedReferenceFactory(service);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder =
        serviceTarget
            .addService(bindInfo.getBinderServiceName(), binderService)
            .addInjection(binderService.getManagedObjectInjector(), valueManagedReferenceFactory)
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binderService.getNamingStoreInjector())
            .addListener(
                new AbstractServiceListener<Object>() {
                  public void transition(
                      final ServiceController<? extends Object> controller,
                      final ServiceController.Transition transition) {
                    switch (transition) {
                      case STARTING_to_UP:
                        {
                          MailLogger.ROOT_LOGGER.boundMailSession(jndiName);
                          break;
                        }
                      case START_REQUESTED_to_DOWN:
                        {
                          MailLogger.ROOT_LOGGER.unboundMailSession(jndiName);
                          break;
                        }
                      case REMOVING_to_REMOVED:
                        {
                          MailLogger.ROOT_LOGGER.removedMailSession(jndiName);
                          break;
                        }
                    }
                  }
                });

    mailSessionBuilder
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .addListener(verificationHandler);
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).addListener(verificationHandler);
    controllers.add(mailSessionBuilder.install());
    controllers.add(binderBuilder.install());
  }
예제 #15
0
  @Override
  protected void performRuntime(
      final OperationContext context,
      final ModelNode operation,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    final ServiceTarget target = context.getServiceTarget();
    final AddressContext addressContext = AddressContext.forOperation(operation);
    final String repositoryName = addressContext.repositoryName();
    final String cacheName = attribute(context, model, ModelAttributes.CACHE_NAME, repositoryName);
    String infinispanConfig = attribute(context, model, ModelAttributes.CACHE_CONFIG, null);
    String configRelativeTo =
        attribute(context, model, ModelAttributes.CONFIG_RELATIVE_TO).asString();
    final boolean enableMonitoring =
        attribute(context, model, ModelAttributes.ENABLE_MONITORING).asBoolean();
    final String gcThreadPool =
        attribute(context, model, ModelAttributes.GARBAGE_COLLECTION_THREAD_POOL, null);
    final String gcInitialTime =
        attribute(context, model, ModelAttributes.GARBAGE_COLLECTION_INITIAL_TIME, null);
    final int gcIntervalInHours =
        attribute(context, model, ModelAttributes.GARBAGE_COLLECTION_INTERVAL).asInt();
    final String optThreadPool =
        attribute(context, model, ModelAttributes.DOCUMENT_OPTIMIZATION_THREAD_POOL, null);
    final String optInitialTime =
        attribute(context, model, ModelAttributes.DOCUMENT_OPTIMIZATION_INITIAL_TIME, null);
    final int optIntervalInHours =
        attribute(context, model, ModelAttributes.DOCUMENT_OPTIMIZATION_INTERVAL).asInt();
    final Integer optTarget =
        intAttribute(
            context, model, ModelAttributes.DOCUMENT_OPTIMIZATION_CHILD_COUNT_TARGET, null);
    final Integer eventBusSize = intAttribute(context, model, ModelAttributes.EVENT_BUS_SIZE, null);
    final Integer optTolerance =
        intAttribute(
            context, model, ModelAttributes.DOCUMENT_OPTIMIZATION_CHILD_COUNT_TOLERANCE, null);

    // Create a document for the repository configuration ...
    EditableDocument configDoc = Schematic.newDocument();
    configDoc.set(FieldName.NAME, repositoryName);

    // Determine the JNDI name ...
    configDoc.set(
        FieldName.JNDI_NAME,
        ""); // always set to empty string, since we'll register in JNDI here ...
    final String jndiName = ModeShapeJndiNames.JNDI_BASE_NAME + repositoryName;
    String jndiAlias = ModeShapeJndiNames.jndiNameFrom(model, repositoryName);
    if (jndiName.equals(jndiAlias)) {
      jndiAlias = null;
    }

    if (eventBusSize != null) {
      configDoc.setNumber(FieldName.EVENT_BUS_SIZE, eventBusSize);
    }

    // Parse the cache configuration
    if (StringUtil.isBlank(infinispanConfig)) {
      infinispanConfig = "modeshape/" + repositoryName + "-cache-config.xml";
    } else {
      // check if it's a system property
      String infinispanConfigSystemProperty = System.getProperty(infinispanConfig);
      if (!StringUtil.isBlank(infinispanConfigSystemProperty)) {
        infinispanConfig = infinispanConfigSystemProperty;
      }
    }
    // Set the storage information (that was set on the repository ModelNode) ...
    setRepositoryStorageConfiguration(infinispanConfig, cacheName, configDoc);

    // Always set whether monitoring is enabled ...
    enableMonitoring(enableMonitoring, configDoc);

    // Initial node-types if configured
    parseCustomNodeTypes(model, configDoc);

    // Workspace information is on the repository model node (unlike the XML) ...
    EditableDocument workspacesDoc = parseWorkspaces(context, model, configDoc);

    // security
    parseSecurity(context, model, configDoc);

    // Now create the repository service that manages the lifecycle of the JcrRepository instance
    // ...
    RepositoryConfiguration repositoryConfig =
        new RepositoryConfiguration(configDoc, repositoryName);
    String configRelativeToSystemProperty = System.getProperty(configRelativeTo);
    if (!StringUtil.isBlank(configRelativeToSystemProperty)) {
      configRelativeTo = configRelativeToSystemProperty;
    }
    if (!configRelativeTo.endsWith("/")) {
      configRelativeTo = configRelativeTo + "/";
    }
    RepositoryService repositoryService =
        new RepositoryService(repositoryConfig, infinispanConfig, configRelativeTo);
    ServiceName repositoryServiceName = ModeShapeServiceNames.repositoryServiceName(repositoryName);

    // Sequencing
    parseSequencing(model, configDoc);

    // Text Extraction
    parseTextExtraction(model, configDoc);

    // Reindexing
    parseReindexing(model, configDoc);

    // Journaling
    parseJournaling(repositoryService, context, model, configDoc);

    // Add the EngineService's dependencies ...
    ServiceBuilder<JcrRepository> repositoryServiceBuilder =
        target.addService(repositoryServiceName, repositoryService);

    // Add dependency to the ModeShape engine service ...
    repositoryServiceBuilder.addDependency(
        ModeShapeServiceNames.ENGINE, ModeShapeEngine.class, repositoryService.getEngineInjector());
    repositoryServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    // Add garbage collection information ...
    if (gcThreadPool != null) {
      configDoc
          .getOrCreateDocument(FieldName.GARBAGE_COLLECTION)
          .setString(FieldName.THREAD_POOL, gcThreadPool);
    }
    if (gcInitialTime != null) {
      configDoc
          .getOrCreateDocument(FieldName.GARBAGE_COLLECTION)
          .setString(FieldName.INITIAL_TIME, gcInitialTime);
    }
    configDoc
        .getOrCreateDocument(FieldName.GARBAGE_COLLECTION)
        .setNumber(FieldName.INTERVAL_IN_HOURS, gcIntervalInHours);

    // Add document optimization information ...
    if (optTarget != null) {
      EditableDocument docOpt =
          configDoc
              .getOrCreateDocument(FieldName.STORAGE)
              .getOrCreateDocument(FieldName.DOCUMENT_OPTIMIZATION);
      if (optThreadPool != null) {
        docOpt.setString(FieldName.THREAD_POOL, optThreadPool);
      }
      if (optInitialTime != null) {
        docOpt.setString(FieldName.INITIAL_TIME, optInitialTime);
      }
      docOpt.setNumber(FieldName.INTERVAL_IN_HOURS, optIntervalInHours);
      docOpt.setNumber(FieldName.OPTIMIZATION_CHILD_COUNT_TARGET, optTarget.intValue());
      if (optTolerance != null) {
        docOpt.setNumber(FieldName.OPTIMIZATION_CHILD_COUNT_TOLERANCE, optTolerance.intValue());
      }
    }

    // Add the dependency to the Security Manager
    repositoryServiceBuilder.addDependency(
        SecurityManagementService.SERVICE_NAME,
        ISecurityManagement.class,
        repositoryService.getSecurityManagementServiceInjector());

    // Add dependency, if necessary, to the workspaces cache container
    String workspacesInfinispanConfig =
        attribute(context, model, ModelAttributes.WORKSPACES_CACHE_CONTAINER, null);
    if (workspacesInfinispanConfig != null
        && !workspacesInfinispanConfig.toLowerCase().equalsIgnoreCase(infinispanConfig)) {
      workspacesDoc.set(FieldName.WORKSPACE_CACHE_CONFIGURATION, workspacesInfinispanConfig);
    }

    repositoryServiceBuilder.addDependency(
        Services.JBOSS_SERVICE_MODULE_LOADER,
        ModuleLoader.class,
        repositoryService.getModuleLoaderInjector());

    // Set up the JNDI binder service ...
    final ReferenceFactoryService<JcrRepository> referenceFactoryService =
        new ReferenceFactoryService<JcrRepository>();
    ServiceName referenceFactoryServiceName =
        ModeShapeServiceNames.referenceFactoryServiceName(repositoryName);
    final ServiceBuilder<?> referenceBuilder =
        target.addService(referenceFactoryServiceName, referenceFactoryService);
    referenceBuilder.addDependency(
        repositoryServiceName, JcrRepository.class, referenceFactoryService.getInjector());
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceBuilder<?> binderBuilder = target.addService(bindInfo.getBinderServiceName(), binder);
    if (jndiAlias != null) {
      ContextNames.BindInfo aliasInfo = ContextNames.bindInfoFor(jndiAlias);
      ServiceName alias = aliasInfo.getBinderServiceName();
      binderBuilder.addAliases(alias);
      LOG.debugv(
          "Binding repository {0} to JNDI name {1} and {2}",
          repositoryName, bindInfo.getAbsoluteJndiName(), aliasInfo.getAbsoluteJndiName());
    } else {
      LOG.debugv(
          "Binding repository {0} to JNDI name {1}",
          repositoryName, bindInfo.getAbsoluteJndiName());
    }
    binderBuilder.addDependency(
        referenceFactoryServiceName,
        ManagedReferenceFactory.class,
        binder.getManagedObjectInjector());
    binderBuilder.addDependency(
        bindInfo.getParentContextServiceName(),
        ServiceBasedNamingStore.class,
        binder.getNamingStoreInjector());
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    // Add dependency to the data directory ...
    ServiceName dataDirServiceName = ModeShapeServiceNames.dataDirectoryServiceName(repositoryName);
    ServiceController<String> dataDirServiceController =
        RelativePathService.addService(
            dataDirServiceName,
            "modeshape/" + repositoryName,
            ModeShapeExtension.JBOSS_DATA_DIR_VARIABLE,
            target);
    newControllers.add(dataDirServiceController);
    repositoryServiceBuilder.addDependency(
        dataDirServiceName, String.class, repositoryService.getDataDirectoryPathInjector());

    // Add the default binary storage service which will provide the binary configuration
    BinaryStorageService defaultBinaryService = BinaryStorageService.createDefault();
    ServiceName defaultBinaryStorageServiceName =
        ModeShapeServiceNames.binaryStorageDefaultServiceName(repositoryName);
    ServiceBuilder<BinaryStorage> binaryStorageBuilder =
        target.addService(defaultBinaryStorageServiceName, defaultBinaryService);
    binaryStorageBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    // Add dependency to the binaries storage service, which captures the properties for the
    // binaries storage
    repositoryServiceBuilder.addDependency(
        defaultBinaryStorageServiceName,
        BinaryStorage.class,
        repositoryService.getBinaryStorageInjector());

    // Add monitor service
    final MonitorService monitorService = new MonitorService();
    final ServiceBuilder<RepositoryMonitor> monitorBuilder =
        target.addService(ModeShapeServiceNames.monitorServiceName(repositoryName), monitorService);
    monitorBuilder.addDependency(
        ModeShapeServiceNames.repositoryServiceName(repositoryName),
        JcrRepository.class,
        monitorService.getJcrRepositoryInjector());
    monitorBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    // Now add the controller for the RepositoryService ...
    newControllers.add(repositoryServiceBuilder.install());
    newControllers.add(referenceBuilder.install());
    newControllers.add(binderBuilder.install());
    newControllers.add(binaryStorageBuilder.install());
    newControllers.add(monitorBuilder.install());
  }
  private void startDataSource(
      final AbstractDataSourceService dataSourceService,
      final ContextNames.BindInfo bindInfo,
      final EEModuleDescription moduleDescription,
      final ResolutionContext context,
      final ServiceTarget serviceTarget,
      final ServiceBuilder valueSourceServiceBuilder,
      final Injector<ManagedReferenceFactory> injector,
      boolean securityEnabled) {

    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder =
        Services.addServerExecutorDependency(
                serviceTarget.addService(dataSourceServiceName, dataSourceService),
                dataSourceService.getExecutorServiceInjector(),
                false)
            .addDependency(
                ConnectorServices.IRONJACAMAR_MDR,
                MetadataRepository.class,
                dataSourceService.getMdrInjector())
            .addDependency(
                ConnectorServices.RA_REPOSITORY_SERVICE,
                ResourceAdapterRepository.class,
                dataSourceService.getRaRepositoryInjector())
            .addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME))
            .addDependency(
                ConnectorServices.TRANSACTION_INTEGRATION_SERVICE,
                TransactionIntegration.class,
                dataSourceService.getTransactionIntegrationInjector())
            .addDependency(
                ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE,
                ManagementRepository.class,
                dataSourceService.getManagementRepositoryInjector())
            .addDependency(
                ConnectorServices.CCM_SERVICE,
                CachedConnectionManager.class,
                dataSourceService.getCcmInjector())
            .addDependency(
                ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE,
                DriverRegistry.class,
                dataSourceService.getDriverRegistryInjector())
            .addDependency(NamingService.SERVICE_NAME);

    if (securityEnabled) {
      dataSourceServiceBuilder.addDependency(
          SubjectFactoryService.SERVICE_NAME,
          SubjectFactory.class,
          dataSourceService.getSubjectFactoryInjector());
    }

    final DataSourceReferenceFactoryService referenceFactoryService =
        new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName =
        DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    final ServiceBuilder<?> referenceBuilder =
        serviceTarget
            .addService(referenceFactoryServiceName, referenceFactoryService)
            .addDependency(
                dataSourceServiceName,
                javax.sql.DataSource.class,
                referenceFactoryService.getDataSourceInjector());

    final BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    final ServiceBuilder<?> binderBuilder =
        serviceTarget
            .addService(bindInfo.getBinderServiceName(), binderService)
            .addDependency(
                referenceFactoryServiceName,
                ManagedReferenceFactory.class,
                binderService.getManagedObjectInjector())
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binderService.getNamingStoreInjector())
            .addListener(
                new AbstractServiceListener<Object>() {
                  public void transition(
                      final ServiceController<? extends Object> controller,
                      final ServiceController.Transition transition) {
                    switch (transition) {
                      case STARTING_to_UP:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                          break;
                        }
                      case START_REQUESTED_to_DOWN:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                          break;
                        }
                      case REMOVING_to_REMOVED:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.debugf(
                              "Removed JDBC Data-source [%s]", jndiName);
                          break;
                        }
                    }
                  }
                });

    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();

    valueSourceServiceBuilder.addDependency(
        bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector);
  }
예제 #17
0
  /**
   * Make any runtime changes necessary to effect the changes indicated by the given {@code
   * operation}. E
   *
   * <p>It constructs a MailSessionService that provides mail session and registers it to Naming
   * service.
   *
   * @param context the operation context
   * @param operation the operation being executed
   * @param model persistent configuration model node that corresponds to the address of {@code
   *     operation}
   * @param verificationHandler step handler that can be added as a listener to any new services
   *     installed in order to validate the services installed correctly during the {@link
   *     org.jboss.as.controller.OperationContext.Stage#VERIFY VERIFY stage}
   * @param controllers holder for the {@link org.jboss.msc.service.ServiceController} for any new
   *     services installed by the method. The method should add the {@code ServiceController} for
   *     any new services to this list. If the overall operation needs to be rolled back, the list
   *     will be used in {@link #rollbackRuntime(org.jboss.as.controller.OperationContext,
   *     org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, java.util.List)} to automatically removed
   *     the newly added services
   * @throws org.jboss.as.controller.OperationFailedException if {@code operation} is invalid or
   *     updating the runtime otherwise fails
   */
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> controllers)
      throws OperationFailedException {
    final String jndiName = getJndiName(operation);
    final ServiceTarget serviceTarget = context.getServiceTarget();

    ModelNode fullTree = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final MailSessionConfig config = from(context, fullTree);
    final MailSessionService service = new MailSessionService(config);
    final ServiceName serviceName = SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder<?> mailSessionBuilder = serviceTarget.addService(serviceName, service);
    addOutboundSocketDependency(service, mailSessionBuilder, config.getImapServer());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getPop3Server());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getSmtpServer());
    for (CustomServerConfig server : config.getCustomServers()) {
      if (server.getOutgoingSocketBinding() != null) {
        addOutboundSocketDependency(service, mailSessionBuilder, server);
      }
    }

    final ManagedReferenceFactory valueManagedReferenceFactory =
        new ContextListAndJndiViewManagedReferenceFactory() {

          @Override
          public String getJndiViewInstanceValue() {
            return String.valueOf(getReference().getInstance());
          }

          @Override
          public String getInstanceClassName() {
            final Object value = getReference().getInstance();
            return value != null
                ? value.getClass().getName()
                : ContextListManagedReferenceFactory.DEFAULT_INSTANCE_CLASS_NAME;
          }

          @Override
          public ManagedReference getReference() {
            return new ValueManagedReference(new ImmediateValue<Object>(service.getValue()));
          }
        };
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder =
        serviceTarget
            .addService(bindInfo.getBinderServiceName(), binderService)
            .addInjection(binderService.getManagedObjectInjector(), valueManagedReferenceFactory)
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binderService.getNamingStoreInjector())
            .addListener(
                new AbstractServiceListener<Object>() {
                  public void transition(
                      final ServiceController<? extends Object> controller,
                      final ServiceController.Transition transition) {
                    switch (transition) {
                      case STARTING_to_UP:
                        {
                          MailLogger.ROOT_LOGGER.boundMailSession(jndiName);
                          break;
                        }
                      case START_REQUESTED_to_DOWN:
                        {
                          MailLogger.ROOT_LOGGER.unboundMailSession(jndiName);
                          break;
                        }
                      case REMOVING_to_REMOVED:
                        {
                          MailLogger.ROOT_LOGGER.removedMailSession(jndiName);
                          break;
                        }
                    }
                  }
                });

    mailSessionBuilder
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .addListener(verificationHandler);
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).addListener(verificationHandler);
    controllers.add(mailSessionBuilder.install());
    controllers.add(binderBuilder.install());
  }