Esempio n. 1
0
 private void writeCommonCacheAttributesElements(
     XMLExtendedStreamWriter writer, String name, Configuration configuration)
     throws XMLStreamException {
   writer.writeAttribute(Attribute.NAME, name);
   configuration
       .jmxStatistics()
       .attributes()
       .write(writer, JMXStatisticsConfiguration.ENABLED, Attribute.STATISTICS);
   if (configuration.deadlockDetection().enabled()) {
     writer.writeAttribute(
         Attribute.SPIN_DURATION, Long.toString(configuration.deadlockDetection().spinDuration()));
   }
   configuration.unsafe().attributes().write(writer);
   writeBackup(writer, configuration);
   configuration.sites().backupFor().attributes().write(writer, Element.BACKUP_FOR.getLocalName());
   configuration.locking().attributes().write(writer, Element.LOCKING.getLocalName());
   writeTransaction(writer, configuration);
   configuration.eviction().attributes().write(writer, Element.EVICTION.getLocalName());
   configuration.expiration().attributes().write(writer, Element.EXPIRATION.getLocalName());
   if (configuration.compatibility().enabled())
     configuration
         .compatibility()
         .attributes()
         .write(writer, Element.COMPATIBILITY.getLocalName());
   if (configuration.storeAsBinary().enabled())
     configuration
         .storeAsBinary()
         .attributes()
         .write(writer, Element.STORE_AS_BINARY.getLocalName());
   writePersistence(writer, configuration);
   configuration.versioning().attributes().write(writer, Element.VERSIONING.getLocalName());
   writeDataContainer(writer, configuration);
   writeIndexing(writer, configuration);
   writeCustomInterceptors(writer, configuration);
   writeSecurity(writer, configuration);
   if (configuration.clustering().cacheMode().needsStateTransfer()) {
     configuration
         .clustering()
         .stateTransfer()
         .attributes()
         .write(writer, Element.STATE_TRANSFER.getLocalName());
   }
   configuration
       .clustering()
       .partitionHandling()
       .attributes()
       .write(writer, Element.PARTITION_HANDLING.getLocalName());
 }
Esempio n. 2
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);
    }
  }
Esempio n. 3
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);
     }
   }
 }
Esempio n. 4
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);
    }
  }