/** Registers the Search interceptor in the cache before it gets started */
 @Override
 public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
   if (cfg.indexing().enabled()) {
     log.registeringQueryInterceptor();
     SearchFactoryIntegrator searchFactory = getSearchFactory(cfg.indexing().properties(), cr);
     createQueryInterceptorIfNeeded(cr, cfg, searchFactory);
   }
 }
  @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);
  }
Beispiel #3
0
  @Override
  public byte[] query(AdvancedCache<byte[], byte[]> cache, byte[] query) {
    try {
      SerializationContext serCtx =
          ProtobufMetadataManagerImpl.getSerializationContextInternal(cache.getCacheManager());
      QueryRequest request =
          ProtobufUtil.fromByteArray(serCtx, query, 0, query.length, QueryRequest.class);

      Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache);
      boolean isIndexed = cacheConfiguration.indexing().index().isEnabled();
      boolean isCompatMode = cacheConfiguration.compatibility().enabled();
      SearchManager searchManager =
          isIndexed ? Search.getSearchManager(cache) : null; // this also checks access permissions
      RemoteQueryEngine queryEngine =
          new RemoteQueryEngine(cache, searchManager, isCompatMode, serCtx);

      long startOffset = request.getStartOffset() == null ? -1 : request.getStartOffset();
      int maxResults = request.getMaxResults() == null ? -1 : request.getMaxResults();
      Map<String, Object> namedParameters = getNamedParameters(request);
      Query q =
          queryEngine.buildQuery(
              null, request.getJpqlString(), namedParameters, startOffset, maxResults);

      QueryResponse response = makeResponse(q);
      return ProtobufUtil.toByteArray(serCtx, response);
    } catch (IOException e) {
      throw log.errorExecutingQuery(e);
    }
  }
 private QueryInterceptor buildQueryInterceptor(
     Configuration cfg, SearchFactoryIntegrator searchFactory) {
   if (cfg.indexing().indexLocalOnly()) {
     return new LocalQueryInterceptor(searchFactory);
   } else {
     return new QueryInterceptor(searchFactory);
   }
 }
Beispiel #5
0
 private void writeIndexing(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   IndexingConfiguration indexing = configuration.indexing();
   AttributeSet attributes = indexing.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.INDEXING);
     attributes.write(writer, IndexingConfiguration.INDEX, Attribute.INDEX);
     attributes.write(writer, IndexingConfiguration.AUTO_CONFIG, Attribute.AUTO_CONFIG);
     writeTypedProperties(writer, indexing.properties());
     writer.writeEndElement();
   }
 }
 /** 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);
     }
   }
 }
  @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);
    }
  }
  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);
    }
  }