コード例 #1
0
ファイル: Serializer.java プロジェクト: andyuk1986/infinispan
 private void writeTransaction(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   TransactionConfiguration transaction = configuration.transaction();
   AttributeSet attributes = transaction.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.TRANSACTION);
     TransactionMode mode =
         TransactionMode.fromConfiguration(
             transaction.transactionMode(),
             !transaction.useSynchronization(),
             transaction.recovery().enabled(),
             configuration.invocationBatching().enabled());
     writer.writeAttribute(Attribute.MODE, mode.toString());
     attributes.write(writer);
     if (mode != TransactionMode.NONE) {
       attributes.write(writer, TransactionConfiguration.TRANSACTION_MANAGER_LOOKUP);
     }
     if (transaction.recovery().enabled())
       transaction
           .recovery()
           .attributes()
           .write(
               writer,
               RecoveryConfiguration.RECOVERY_INFO_CACHE_NAME,
               Attribute.RECOVERY_INFO_CACHE_NAME);
     writer.writeEndElement();
   }
 }
コード例 #2
0
  private void createRemoteValueWrapperInterceptor(ComponentRegistry cr, Configuration cfg) {
    RemoteValueWrapperInterceptor wrapperInterceptor =
        cr.getComponent(RemoteValueWrapperInterceptor.class);
    if (wrapperInterceptor == null) {
      wrapperInterceptor = new RemoteValueWrapperInterceptor();

      // Interceptor registration not needed, core configuration handling
      // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in
      // the component registry!
      AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class);

      ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg);
      InterceptorConfigurationBuilder interceptorBuilder =
          builder.customInterceptors().addInterceptor();
      interceptorBuilder.interceptor(wrapperInterceptor);

      if (cfg.invocationBatching().enabled()) {
        if (ic != null) ic.addInterceptorAfter(wrapperInterceptor, BatchingInterceptor.class);
        interceptorBuilder.after(BatchingInterceptor.class);
      } else {
        if (ic != null)
          ic.addInterceptorAfter(wrapperInterceptor, InvocationContextInterceptor.class);
        interceptorBuilder.after(InvocationContextInterceptor.class);
      }
      if (ic != null) {
        cr.registerComponent(wrapperInterceptor, RemoteValueWrapperInterceptor.class);
      }
      cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors());
    }
  }
コード例 #3
0
ファイル: CacheAdd.java プロジェクト: riteshh05/jboss-as
  ServiceController<?> installCacheConfigurationService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      String defaultCache,
      ModuleIdentifier moduleId,
      ConfigurationBuilder builder,
      Configuration config,
      List<Dependency<?>> dependencies,
      ServiceVerificationHandler verificationHandler) {

    final InjectedValue<EmbeddedCacheManager> container = new InjectedValue<EmbeddedCacheManager>();
    final CacheConfigurationDependencies cacheConfigurationDependencies =
        new CacheConfigurationDependencies(container);
    final Service<Configuration> service =
        new CacheConfigurationService(cacheName, builder, moduleId, cacheConfigurationDependencies);
    final ServiceBuilder<?> configBuilder =
        target
            .addService(CacheConfigurationService.getServiceName(containerName, cacheName), service)
            .addDependency(
                EmbeddedCacheManagerService.getServiceName(containerName),
                EmbeddedCacheManager.class,
                container)
            .addDependency(
                Services.JBOSS_SERVICE_MODULE_LOADER,
                ModuleLoader.class,
                cacheConfigurationDependencies.getModuleLoaderInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    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));
    }
    return configBuilder.install();
  }
コード例 #4
0
ファイル: CacheAdd.java プロジェクト: mbogoevici/jboss-as
  @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);
  }