Ejemplo n.º 1
0
 public static SearchFactoryIntegrator extractSearchFactory(Cache cache) {
   ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry();
   SearchFactoryIntegrator component =
       componentRegistry.getComponent(SearchFactoryIntegrator.class);
   Assert.assertNotNull(component);
   return component;
 }
 public static void replicateCommand(Cache cache, VisitableCommand command) throws Throwable {
   ComponentRegistry cr = extractComponentRegistry(cache);
   InterceptorChain ic = cr.getComponent(InterceptorChain.class);
   InvocationContextContainer icc = cr.getComponent(InvocationContextContainer.class);
   InvocationContext ctxt = icc.createInvocationContext(true, -1);
   ic.invoke(ctxt, command);
 }
Ejemplo n.º 3
0
  @Override
  public void cacheStarted(ComponentRegistry cr, String cacheName) {
    Configuration configuration = cr.getComponent(Configuration.class);
    boolean indexingEnabled = configuration.indexing().enabled();
    if (!indexingEnabled) {
      if (verifyChainContainsQueryInterceptor(cr)) {
        throw new IllegalStateException(
            "It was NOT expected to find the Query interceptor registered in the InterceptorChain as indexing was disabled, but it was found");
      }
      return;
    }
    if (!verifyChainContainsQueryInterceptor(cr)) {
      throw new IllegalStateException(
          "It was expected to find the Query interceptor registered in the InterceptorChain but it wasn't found");
    }

    // initializing the query module command initializer.
    // we can t inject Cache and CacheManager with @inject in there
    Cache<?, ?> cache = cr.getComponent(Cache.class);
    CommandInitializer initializer = cr.getComponent(CommandInitializer.class);
    EmbeddedCacheManager cacheManager =
        cr.getGlobalComponentRegistry().getComponent(EmbeddedCacheManager.class);
    initializer.setCache(cache, cacheManager);

    QueryBox queryBox = new QueryBox();
    queryBox.setCache(cache.getAdvancedCache());
    cr.registerComponent(queryBox, QueryBox.class);

    // Register query mbeans
    registerQueryMBeans(cache.getAdvancedCache(), cr, cacheName);
  }
 private void replaceLockManager(ComponentRegistry componentRegistry) {
   LockManager oldLockManager = componentRegistry.getComponent(LockManager.class);
   LockManager newLockManager =
       new ExtendedStatisticLockManager(oldLockManager, cacheStatisticManager, timeService);
   log.replaceComponent("LockManager", oldLockManager, newLockManager);
   componentRegistry.registerComponent(newLockManager, LockManager.class);
 }
Ejemplo n.º 5
0
 protected static GMUVersionGenerator getGMUVersionGenerator(
     GlobalComponentRegistry globalComponentRegistry, String cacheName) {
   ComponentRegistry componentRegistry =
       globalComponentRegistry.getNamedComponentRegistry(cacheName);
   VersionGenerator versionGenerator = componentRegistry.getComponent(VersionGenerator.class);
   return toGMUVersionGenerator(versionGenerator);
 }
Ejemplo n.º 6
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());
    }
  }
Ejemplo n.º 7
0
 @Override
 public CompletableFuture<Object> invokeAsync() throws Throwable {
   GlobalComponentRegistry globalComponentRegistry = cacheManager.getGlobalComponentRegistry();
   ComponentRegistry cacheComponentRegistry =
       globalComponentRegistry.getNamedComponentRegistry(cacheName);
   String name = cacheName.toString();
   if (cacheComponentRegistry != null) {
     cacheComponentRegistry.getComponent(PersistenceManager.class).setClearOnStop(true);
     cacheComponentRegistry.getComponent(CacheJmxRegistration.class).setUnregisterCacheMBean(true);
     cacheComponentRegistry.getComponent(PassivationManager.class).skipPassivationOnStop(true);
     Cache<?, ?> cache = cacheManager.getCache(name, false);
     if (cache != null) {
       cache.stop();
     }
   }
   globalComponentRegistry.removeCache(name);
   // Remove cache configuration and remove it from the computed cache name list
   globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
   // Remove cache from dependency graph
   //noinspection unchecked
   globalComponentRegistry
       .getComponent(DependencyGraph.class, CACHE_DEPENDENCY_GRAPH)
       .remove(cacheName);
   return CompletableFutures.completedNull();
 }
 /**
  * Replaces a component in a running cache
  *
  * @param cache cache in which to replace component
  * @param componentType component type of which to replace
  * @param replacementComponent new instance
  * @param rewire if true, ComponentRegistry.rewire() is called after replacing.
  * @return the original component that was replaced
  */
 public static <T> T replaceComponent(
     Cache<?, ?> cache, Class<T> componentType, T replacementComponent, boolean rewire) {
   ComponentRegistry cr = extractComponentRegistry(cache);
   T old = cr.getComponent(componentType);
   cr.registerComponent(replacementComponent, componentType);
   if (rewire) cr.rewire();
   return old;
 }
  private void replace() {
    log.replaceComponents();
    ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry();

    replaceRpcManager(componentRegistry);
    replaceLockManager(componentRegistry);
    componentRegistry.rewire();
  }
Ejemplo n.º 10
0
 protected void assertIndexingKnows(BasicCache<?, ?> cache, Class<?>... types) {
   ComponentRegistry cr = ((Cache) cache).getAdvancedCache().getComponentRegistry();
   SearchIntegrator searchIntegrator = cr.getComponent(SearchIntegrator.class);
   assertNotNull(searchIntegrator);
   HashSet<Class<?>> expectedTypes = new HashSet<Class<?>>(Arrays.asList(types));
   HashSet<Class<?>> indexedTypes = new HashSet<Class<?>>(searchIntegrator.getIndexedTypes());
   assertEquals(expectedTypes, indexedTypes);
 }
  /**
   * Replaces the existing interceptor chain in the cache wih one represented by the interceptor
   * passed in. This utility updates dependencies on all components that rely on the interceptor
   * chain as well.
   *
   * @param cache cache that needs to be altered
   * @param interceptor the first interceptor in the new chain.
   */
  public static void replaceInterceptorChain(Cache cache, CommandInterceptor interceptor) {
    ComponentRegistry cr = extractComponentRegistry(cache);
    // make sure all interceptors here are wired.
    CommandInterceptor i = interceptor;
    do {
      cr.wireDependencies(i);
    } while ((i = i.getNext()) != null);

    InterceptorChain inch = cr.getComponent(InterceptorChain.class);
    inch.setFirstInChain(interceptor);
  }
 /**
  * Verifies if the indexing interceptor is aware of a specific list of types.
  *
  * @param cache the cache containing the indexes
  * @param types vararg listing the types the indexing engine should know
  */
 private void assertIndexingKnows(Cache<Object, Object> cache, Class<?>... types) {
   ComponentRegistry cr = cache.getAdvancedCache().getComponentRegistry();
   SearchIntegrator searchIntegrator = cr.getComponent(SearchIntegrator.class);
   assertNotNull(searchIntegrator);
   Map<Class<?>, EntityIndexBinding> indexBindingForEntity =
       searchIntegrator.unwrap(ExtendedSearchIntegrator.class).getIndexBindings();
   assertNotNull(indexBindingForEntity);
   Set<Class<?>> keySet = indexBindingForEntity.keySet();
   assertEquals(types.length, keySet.size());
   assertTrue(keySet.containsAll(Arrays.asList(types)));
 }
 private void replaceRpcManager(ComponentRegistry componentRegistry) {
   RpcManager oldRpcManager = componentRegistry.getComponent(RpcManager.class);
   if (oldRpcManager == null) {
     // local mode
     return;
   }
   RpcManager newRpcManager =
       new ExtendedStatisticRpcManager(oldRpcManager, cacheStatisticManager, timeService);
   log.replaceComponent("RpcManager", oldRpcManager, newRpcManager);
   componentRegistry.registerComponent(newRpcManager, RpcManager.class);
   this.rpcManager = newRpcManager;
 }
 /**
  * Replaces an existing interceptor of the given type in the interceptor chain with a new
  * interceptor instance passed as parameter.
  *
  * @param replacingInterceptor the interceptor to add to the interceptor chain
  * @param toBeReplacedInterceptorType the type of interceptor that should be swapped with the new
  *     one
  * @return true if the interceptor was replaced
  */
 public static boolean replaceInterceptor(
     Cache cache,
     CommandInterceptor replacingInterceptor,
     Class<? extends CommandInterceptor> toBeReplacedInterceptorType) {
   ComponentRegistry cr = extractComponentRegistry(cache);
   // make sure all interceptors here are wired.
   CommandInterceptor i = replacingInterceptor;
   do {
     cr.wireDependencies(i);
   } while ((i = i.getNext()) != null);
   InterceptorChain inch = cr.getComponent(InterceptorChain.class);
   return inch.replaceInterceptor(replacingInterceptor, toBeReplacedInterceptorType);
 }
Ejemplo n.º 15
0
 @Override
 public void initialize(
     String indexName,
     Properties properties,
     Similarity similarity,
     WorkerBuildContext buildContext) {
   super.initialize(indexName, properties, similarity, buildContext);
   ServiceManager serviceManager = buildContext.getServiceManager();
   ComponentRegistryService componentRegistryService =
       serviceManager.requestService(ComponentRegistryService.class);
   ComponentRegistry componentRegistry = componentRegistryService.getComponentRegistry();
   Cache cache = componentRegistry.getComponent(Cache.class);
   cache.addListener(new TopologyChangeListener());
   closeIndexWriter();
 }
  @Override
  protected void start() {
    super.start();
    log.startStreamSummaryInterceptor();
    streamSummaryContainer = StreamSummaryContainer.getOrCreateStreamLibContainer(cache);
    streamSummaryContainer.setEnabled(true);
    distributionManager = cache.getAdvancedCache().getDistributionManager();

    ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry();
    LockManager oldLockManager = componentRegistry.getComponent(LockManager.class);
    LockManager newLockManager = new TopKeyLockManager(oldLockManager, streamSummaryContainer);
    log.replaceComponent("LockManager", oldLockManager, newLockManager);
    componentRegistry.registerComponent(newLockManager, LockManager.class);
    componentRegistry.rewire();
  }
Ejemplo n.º 17
0
  public static ControlledCommandFactory registerControlledCommandFactory(
      Cache cache, Class<? extends ReplicableCommand> toBlock) {
    ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry();
    final ControlledCommandFactory ccf =
        new ControlledCommandFactory(componentRegistry.getCommandsFactory(), toBlock);
    TestingUtil.replaceField(ccf, "commandsFactory", componentRegistry, ComponentRegistry.class);
    componentRegistry.registerComponent(ccf, CommandsFactory.class);

    // hack: re-add the component registry to the GlobalComponentRegistry's "namedComponents" (CHM)
    // in order to correctly publish it for
    // when it will be read by the InboundInvocationHandlder. InboundInvocationHandlder reads the
    // value from the GlobalComponentRegistry.namedComponents before using it
    componentRegistry
        .getGlobalComponentRegistry()
        .registerNamedComponentRegistry(componentRegistry, EmbeddedCacheManager.DEFAULT_CACHE_NAME);
    return ccf;
  }
Ejemplo n.º 18
0
  @Override
  public void cacheStopping(ComponentRegistry cr, String cacheName) {
    // TODO move this to cacheStopped event (won't work right now as the ComponentRegistry is half
    // empty at that point: ISPN-1006)
    Object searchFactoryIntegrator = cr.getComponent(SearchFactoryIntegrator.class);
    if (searchFactoryIntegrator != null && searchFactoryIntegrator != REMOVED_REGISTRY_COMPONENT) {
      searchFactoriesToShutdown.put(cacheName, (SearchFactoryIntegrator) searchFactoryIntegrator);
      // free some memory by de-registering the SearchFactory
      cr.registerComponent(REMOVED_REGISTRY_COMPONENT, SearchFactoryIntegrator.class);
    }

    // Unregister MBeans
    if (mbeanServer != null) {
      String queryMBeanFilter = jmxDomain + ":" + getQueryGroupName(cacheName) + ",*";
      JmxUtil.unregisterMBeans(queryMBeanFilter, mbeanServer);
    }
  }
Ejemplo n.º 19
0
  void stop(EnumSet<Flag> explicitFlags, ClassLoader explicitClassLoader) {
    if (log.isDebugEnabled())
      log.debugf("Stopping cache %s on %s", getName(), getCacheManager().getAddress());

    // Create invocation context to pass flags
    createNonTxInvocationContext(explicitFlags, explicitClassLoader);
    componentRegistry.stop();
  }
Ejemplo n.º 20
0
 @ManagedOperation(description = "Starts the cache.")
 @Operation(displayName = "Starts cache.")
 public void start() {
   componentRegistry.start();
   defaultLifespan = config.getExpirationLifespan();
   defaultMaxIdleTime = config.getExpirationMaxIdle();
   if (log.isDebugEnabled())
     log.debugf("Started cache %s on %s", getName(), getCacheManager().getAddress());
 }
Ejemplo n.º 21
0
  @Override
  public void cacheStopped(ComponentRegistry cr, String cacheName) {
    SearchFactoryIntegrator searchFactoryIntegrator = searchFactoriesToShutdown.remove(cacheName);
    if (searchFactoryIntegrator != null) {
      searchFactoryIntegrator.close();
    }

    Configuration cfg = cr.getComponent(Configuration.class);
    removeQueryInterceptorFromConfiguration(cfg);
  }
  @Start(priority = 11) // after Transport
  public void start() {
    SecurityActions.addCacheManagerListener(cache.getCacheManager(), new RankCalculator());

    isClustered =
        SecurityActions.getCacheConfiguration(cache.getAdvancedCache())
            .clustering()
            .cacheMode()
            .isClustered();

    if (isClustered) {
      // Use component registry to avoid keeping an instance ref simply used on start
      ComponentRegistry componentRegistry =
          SecurityActions.getCacheComponentRegistry(cache.getAdvancedCache());
      Transport transport =
          componentRegistry.getGlobalComponentRegistry().getComponent(Transport.class);
      calculateRank(transport.getAddress(), transport.getMembers(), transport.getViewId());
    }
  }
 @Override
 public void executeRuntimeStep(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
   final String cacheContainerName = address.getElement(address.size() - 2).getValue();
   final String cacheName = address.getElement(address.size() - 1).getValue();
   final ServiceController<?> controller =
       context
           .getServiceRegistry(false)
           .getService(CacheServiceName.CACHE.getServiceName(cacheContainerName, cacheName));
   if (controller != null) {
     Cache<?, ?> cache = (Cache<?, ?>) controller.getValue();
     if (cache != null) {
       ComponentRegistry registry = SecurityActions.getComponentRegistry(cache.getAdvancedCache());
       LocalTopologyManagerImpl localTopologyManager =
           (LocalTopologyManagerImpl)
               registry.getGlobalComponentRegistry().getComponent(LocalTopologyManager.class);
       if (localTopologyManager != null) {
         try {
           if (operation.hasDefined(VALUE)) {
             ModelNode newValue = operation.get(VALUE);
             localTopologyManager.setCacheAvailability(
                 cacheName, AvailabilityMode.valueOf(newValue.asString()));
           } else {
             context
                 .getResult()
                 .set(
                     new ModelNode()
                         .set(localTopologyManager.getCacheAvailability(cacheName).toString()));
           }
         } catch (Exception e) {
           throw new OperationFailedException(
               new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
         }
       }
     }
   }
   context.stepCompleted();
 }
Ejemplo n.º 24
0
 /** Registers the remote value wrapper interceptor in the cache before it gets started. */
 @Override
 public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
   InternalCacheRegistry icr =
       cr.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class);
   if (!icr.isInternalCache(cacheName)) {
     boolean isIndexed = cfg.indexing().index().isEnabled();
     boolean isCompatMode = cfg.compatibility().enabled();
     if (isIndexed && !isCompatMode) {
       log.infof("Registering RemoteValueWrapperInterceptor for cache %s", cacheName);
       createRemoteValueWrapperInterceptor(cr, cfg);
     }
   }
 }
Ejemplo n.º 25
0
 protected AbstractCacheStream(
     Address localAddress,
     boolean parallel,
     DistributionManager dm,
     Supplier<CacheStream<CacheEntry>> supplier,
     ClusterStreamManager<Object> csm,
     boolean includeLoader,
     int distributedBatchSize,
     Executor executor,
     ComponentRegistry registry) {
   this.localAddress = localAddress;
   this.parallel = parallel;
   this.dm = dm;
   this.supplier = supplier;
   this.csm = csm;
   this.includeLoader = includeLoader;
   this.distributedBatchSize = distributedBatchSize;
   this.executor = executor;
   this.registry = registry;
   this.partition = registry.getComponent(PartitionHandlingManager.class);
   keyEquivalence = registry.getComponent(Configuration.class).dataContainer().keyEquivalence();
   intermediateOperations = new ArrayDeque<>();
 }
Ejemplo n.º 26
0
  private void createQueryInterceptorIfNeeded(
      ComponentRegistry cr, Configuration cfg, SearchFactoryIntegrator searchFactory) {
    QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class);
    if (queryInterceptor == null) {
      queryInterceptor = buildQueryInterceptor(cfg, searchFactory);

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

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

      if (!cfg.transaction().transactionMode().isTransactional()) {
        if (ic != null)
          ic.addInterceptorAfter(queryInterceptor, NonTransactionalLockingInterceptor.class);
        interceptorBuilder.after(NonTransactionalLockingInterceptor.class);
      } else if (cfg.transaction().lockingMode() == LockingMode.OPTIMISTIC) {
        if (ic != null)
          ic.addInterceptorAfter(queryInterceptor, OptimisticLockingInterceptor.class);
        interceptorBuilder.after(OptimisticLockingInterceptor.class);
      } else {
        if (ic != null)
          ic.addInterceptorAfter(queryInterceptor, PessimisticLockingInterceptor.class);
        interceptorBuilder.after(PessimisticLockingInterceptor.class);
      }
      if (ic != null) {
        cr.registerComponent(queryInterceptor, QueryInterceptor.class);
        cr.registerComponent(queryInterceptor, queryInterceptor.getClass().getName(), true);
      }
      cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors());
    }
  }
Ejemplo n.º 27
0
 private SearchFactoryIntegrator getSearchFactory(
     Properties indexingProperties, ComponentRegistry cr) {
   Object component = cr.getComponent(SearchFactoryIntegrator.class);
   SearchFactoryIntegrator searchFactory = null;
   if (component
       instanceof
       SearchFactoryIntegrator) { // could be the placeholder Object REMOVED_REGISTRY_COMPONENT
     searchFactory = (SearchFactoryIntegrator) component;
   }
   // defend against multiple initialization:
   if (searchFactory == null) {
     GlobalComponentRegistry globalComponentRegistry = cr.getGlobalComponentRegistry();
     EmbeddedCacheManager uninitializedCacheManager =
         globalComponentRegistry.getComponent(EmbeddedCacheManager.class);
     indexingProperties = addProgrammaticMappings(indexingProperties, cr);
     // Set up the search factory for Hibernate Search first.
     SearchConfiguration config =
         new SearchableCacheConfiguration(
             new Class[0], indexingProperties, uninitializedCacheManager, cr);
     searchFactory = new SearchFactoryBuilder().configuration(config).buildSearchFactory();
     cr.registerComponent(searchFactory, SearchFactoryIntegrator.class);
   }
   return searchFactory;
 }
Ejemplo n.º 28
0
  @Override
  public void cacheStarted(ComponentRegistry cr, String cacheName) {
    InternalCacheRegistry icr =
        cr.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class);
    if (!icr.isInternalCache(cacheName)) {
      Configuration cfg = cr.getComponent(Configuration.class);
      boolean isIndexed = cfg.indexing().index().isEnabled();
      boolean isCompatMode = cfg.compatibility().enabled();
      if (isIndexed && !isCompatMode) {
        if (!verifyChainContainsRemoteValueWrapperInterceptor(cr)) {
          throw new IllegalStateException(
              "It was expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain but it wasn't found");
        }
      } else if (verifyChainContainsRemoteValueWrapperInterceptor(cr)) {
        throw new IllegalStateException(
            "It was NOT expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain as indexing was disabled, but it was found");
      }

      ProtobufMetadataManagerImpl protobufMetadataManager =
          (ProtobufMetadataManagerImpl)
              cr.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class);
      SerializationContext serCtx = protobufMetadataManager.getSerializationContext();
      cr.registerComponent(new ProtobufMatcher(serCtx), ProtobufMatcher.class);

      if (isCompatMode) {
        SearchIntegrator searchFactory = cr.getComponent(SearchIntegrator.class);
        CompatibilityReflectionMatcher compatibilityReflectionMatcher;
        if (searchFactory == null) {
          compatibilityReflectionMatcher = new CompatibilityReflectionMatcher(serCtx);
        } else {
          compatibilityReflectionMatcher =
              new CompatibilityReflectionMatcher(serCtx, searchFactory);
        }
        cr.registerComponent(compatibilityReflectionMatcher, CompatibilityReflectionMatcher.class);
      }

      AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
      RemoteQueryEngine remoteQueryEngine =
          new RemoteQueryEngine(cache, isIndexed, isCompatMode, serCtx);
      cr.registerComponent(remoteQueryEngine, RemoteQueryEngine.class);
    }
  }
Ejemplo n.º 29
0
  private Properties addProgrammaticMappings(Properties indexingProperties, ComponentRegistry cr) {
    Iterator<ProgrammaticSearchMappingProvider> providers =
        ServiceLoader.load(ProgrammaticSearchMappingProvider.class).iterator();
    if (providers.hasNext()) {
      SearchMapping mapping = (SearchMapping) indexingProperties.get(Environment.MODEL_MAPPING);
      if (mapping == null) {
        mapping = new SearchMapping();
        Properties amendedProperties = new Properties();
        amendedProperties.putAll(indexingProperties);
        amendedProperties.put(Environment.MODEL_MAPPING, mapping);
        indexingProperties = amendedProperties;
      }
      Cache cache = cr.getComponent(Cache.class);

      while (providers.hasNext()) {
        ProgrammaticSearchMappingProvider provider = providers.next();
        provider.defineMappings(cache, mapping);
      }
    }
    return indexingProperties;
  }
Ejemplo n.º 30
0
  private void registerQueryMBeans(AdvancedCache cache, ComponentRegistry cr, String cacheName) {
    Configuration cfg = cache.getCacheConfiguration();
    SearchFactoryIntegrator sf = getSearchFactory(cfg.indexing().properties(), cr);

    // Resolve MBean server instance
    GlobalConfiguration globalCfg = cr.getGlobalComponentRegistry().getGlobalConfiguration();
    mbeanServer = JmxUtil.lookupMBeanServer(globalCfg);

    // Resolve jmx domain to use for query mbeans
    String queryGroupName = getQueryGroupName(cacheName);
    jmxDomain = JmxUtil.buildJmxDomain(globalCfg, mbeanServer, queryGroupName);

    // Register statistics MBean, but only enable if Infinispan config says so
    Statistics stats = sf.getStatistics();
    stats.setStatisticsEnabled(cfg.jmxStatistics().enabled());
    try {
      ObjectName statsObjName =
          new ObjectName(jmxDomain + ":" + queryGroupName + ",component=Statistics");
      JmxUtil.registerMBean(new StatisticsInfo(stats), statsObjName, mbeanServer);
    } catch (Exception e) {
      throw new CacheException("Unable to register query module statistics mbean", e);
    }

    // Register mass indexer MBean, picking metadata from repo
    ManageableComponentMetadata metadata =
        metadataRepo.findComponentMetadata(MassIndexer.class).toManageableComponentMetadata();
    try {
      // TODO: MassIndexer should be some kind of query cache component?
      MapReduceMassIndexer maxIndexer = new MapReduceMassIndexer(cache, sf);
      ResourceDMBean mbean = new ResourceDMBean(maxIndexer, metadata);
      ObjectName massIndexerObjName =
          new ObjectName(
              jmxDomain + ":" + queryGroupName + ",component=" + metadata.getJmxObjectName());
      JmxUtil.registerMBean(mbean, massIndexerObjName, mbeanServer);
    } catch (Exception e) {
      throw new CacheException("Unable to create ", e);
    }
  }