Search in sources :

Example 1 with KeyTransformationHandler

use of org.infinispan.query.backend.KeyTransformationHandler in project infinispan by infinispan.

the class LifecycleManager method cacheStarting.

/**
 * Registers the interceptor in the ___protobuf_metadata cache before it gets started. Also creates query components
 * for user caches.
 */
@Override
public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
    BasicComponentRegistry gcr = cr.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class);
    LocalQueryStatistics queryStatistics = cr.getComponent(LocalQueryStatistics.class);
    if (PROTOBUF_METADATA_CACHE_NAME.equals(cacheName)) {
        // a protobuf metadata cache is starting, need to register the interceptor
        ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
        protobufMetadataManager.addProtobufMetadataManagerInterceptor(cr.getComponent(BasicComponentRegistry.class));
    }
    InternalCacheRegistry icr = gcr.getComponent(InternalCacheRegistry.class).running();
    if (!icr.isInternalCache(cacheName)) {
        // a stop dependency must be added for each non-internal cache
        ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
        protobufMetadataManager.addCacheDependency(cacheName);
        // a remote query manager must be added for each non-internal cache
        SerializationContext serCtx = protobufMetadataManager.getSerializationContext();
        RemoteQueryManager remoteQueryManager = buildQueryManager(cfg, serCtx, cr);
        cr.registerComponent(remoteQueryManager, RemoteQueryManager.class);
        SearchMappingCommonBuilding commonBuilding = cr.getComponent(SearchMappingCommonBuilding.class);
        SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
        if (commonBuilding != null && searchMapping == null) {
            AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache().withStorageMediaType().withWrapping(ByteArrayWrapper.class, ProtobufWrapper.class);
            KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils.getKeyTransformationHandler(cache);
            EntityLoader<?> entityLoader = new EntityLoader<>(queryStatistics, cache, keyTransformationHandler);
            searchMapping = new LazySearchMapping(commonBuilding, entityLoader, serCtx, cache, protobufMetadataManager);
            cr.registerComponent(searchMapping, SearchMapping.class);
            BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
            bcr.replaceComponent(IndexStatistics.class.getName(), new LocalIndexStatistics(), true);
            bcr.rewire();
        }
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) EntityLoader(org.infinispan.query.impl.EntityLoader) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) KeyTransformationHandler(org.infinispan.query.backend.KeyTransformationHandler) LocalQueryStatistics(org.infinispan.query.core.stats.impl.LocalQueryStatistics) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache)

Example 2 with KeyTransformationHandler

use of org.infinispan.query.backend.KeyTransformationHandler in project infinispan by infinispan.

the class LifecycleManager method cacheStarting.

/**
 * Registers the Search 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);
    LocalQueryStatistics queryStatistics = cr.getComponent(LocalQueryStatistics.class);
    if (!icr.isInternalCache(cacheName) || icr.internalCacheHasFlag(cacheName, Flag.QUERYABLE)) {
        AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
        SecurityActions.addCacheDependency(cache.getCacheManager(), cacheName, QueryCache.QUERY_CACHE_NAME);
        ClassLoader aggregatedClassLoader = makeAggregatedClassLoader(cr.getGlobalComponentRegistry().getGlobalConfiguration().classLoader());
        boolean isIndexed = cfg.indexing().enabled();
        SearchMapping searchMapping = null;
        if (isIndexed) {
            Map<String, Class<?>> indexedClasses = makeIndexedClassesMap(cache);
            KeyTransformationHandler keyTransformationHandler = new KeyTransformationHandler(aggregatedClassLoader);
            cr.registerComponent(keyTransformationHandler, KeyTransformationHandler.class);
            for (Map.Entry<Class<?>, Class<?>> kt : cfg.indexing().keyTransformers().entrySet()) {
                keyTransformationHandler.registerTransformer(kt.getKey(), (Class<? extends Transformer>) kt.getValue());
            }
            searchMapping = createSearchMapping(queryStatistics, cfg.indexing(), indexedClasses, cr, cache, keyTransformationHandler, aggregatedClassLoader);
            createQueryInterceptorIfNeeded(cr, cfg, cache, indexedClasses);
            Indexer massIndexer = new DistributedExecutorMassIndexer(cache);
            cr.registerComponent(massIndexer, Indexer.class);
            if (searchMapping != null) {
                BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
                bcr.replaceComponent(IndexStatistics.class.getName(), new LocalIndexStatistics(), true);
                bcr.rewire();
            }
        }
        cr.registerComponent(ObjectReflectionMatcher.create(new ReflectionEntityNamesResolver(aggregatedClassLoader), searchMapping), ObjectReflectionMatcher.class);
        cr.registerComponent(new QueryEngine<>(cache, isIndexed), QueryEngine.class);
    }
}
Also used : ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) DistributedExecutorMassIndexer(org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) DistributedExecutorMassIndexer(org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer) Indexer(org.infinispan.query.Indexer) KeyTransformationHandler(org.infinispan.query.backend.KeyTransformationHandler) AggregatedClassLoader(org.infinispan.commons.util.AggregatedClassLoader) LocalQueryStatistics(org.infinispan.query.core.stats.impl.LocalQueryStatistics) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Cache(org.infinispan.Cache) QueryCache(org.infinispan.query.core.impl.QueryCache) AdvancedCache(org.infinispan.AdvancedCache)

Aggregations

AdvancedCache (org.infinispan.AdvancedCache)2 Cache (org.infinispan.Cache)2 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)2 KeyTransformationHandler (org.infinispan.query.backend.KeyTransformationHandler)2 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)2 LocalQueryStatistics (org.infinispan.query.core.stats.impl.LocalQueryStatistics)2 LocalIndexStatistics (org.infinispan.query.stats.impl.LocalIndexStatistics)2 InternalCacheRegistry (org.infinispan.registry.InternalCacheRegistry)2 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AggregatedClassLoader (org.infinispan.commons.util.AggregatedClassLoader)1 ReflectionEntityNamesResolver (org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 Indexer (org.infinispan.query.Indexer)1 QueryCache (org.infinispan.query.core.impl.QueryCache)1 EntityLoader (org.infinispan.query.impl.EntityLoader)1 DistributedExecutorMassIndexer (org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer)1