示例#1
0
  public ServiceBuilder<T> build(ServiceTarget target, String containerName, String cacheName) {
    final ServiceBuilder<T> serviceBuilder =
        target
            .addService(this.targetServiceName, this.service)
            .setInitialMode(ServiceController.Mode.NEVER);
    // Remove target service when this service is removed
    final ServiceListener<T> listener =
        new AbstractServiceListener<T>() {
          @Override
          public void serviceRemoveRequested(ServiceController<? extends T> controller) {
            ServiceController<?> service =
                controller
                    .getServiceContainer()
                    .getService(SingletonService.this.targetServiceName);
            if (service != null) {
              service.setMode(ServiceController.Mode.REMOVE);
            }
          }
        };
    final ServiceBuilder<T> singletonBuilder =
        new AsynchronousServiceBuilder<>(this.singletonServiceName, this)
            .build(target)
            .addAliases(this.singletonServiceName.append("singleton"))
            .addDependency(
                CacheGroupServiceName.GROUP.getServiceName(containerName, cacheName),
                Group.class,
                this.group)
            .addDependency(
                CacheGroupServiceName.SERVICE_PROVIDER_REGISTRATION.getServiceName(
                    containerName, cacheName),
                ServiceProviderRegistrationFactory.class,
                this.registrationFactory)
            .addDependency(
                GroupServiceName.COMMAND_DISPATCHER.getServiceName(containerName),
                CommandDispatcherFactory.class,
                this.dispatcherFactory)
            .addListener(listener);
    // Add dependencies to the target service builder, but install should return the installed
    // singleton controller
    return new DelegatingServiceBuilder<T>(serviceBuilder, ServiceControllerFactory.SIMPLE) {
      @Override
      public ServiceBuilder<T> addAliases(ServiceName... aliases) {
        singletonBuilder.addAliases(aliases);
        return this;
      }

      @Override
      public ServiceBuilder<T> setInitialMode(ServiceController.Mode mode) {
        singletonBuilder.setInitialMode(mode);
        return this;
      }

      @Override
      public ServiceController<T> install() {
        super.install();
        return singletonBuilder.install();
      }
    };
  }
  @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);
  }