Search in sources :

Example 1 with SearchMappingCommonBuilding

use of org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding 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 SearchMappingCommonBuilding

use of org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding in project infinispan by infinispan.

the class LifecycleManager method createSearchMapping.

private SearchMapping createSearchMapping(LocalQueryStatistics queryStatistics, IndexingConfiguration indexingConfiguration, Map<String, Class<?>> indexedClasses, ComponentRegistry cr, AdvancedCache<?, ?> cache, KeyTransformationHandler keyTransformationHandler, ClassLoader aggregatedClassLoader) {
    SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
    if (searchMapping != null && !searchMapping.isClose()) {
        // a paranoid check against an unlikely failure
        throw new IllegalStateException("SearchIntegrator already initialized!");
    }
    GlobalConfiguration globalConfiguration = cr.getGlobalComponentRegistry().getGlobalConfiguration();
    // load ProgrammaticSearchMappingProviders from classpath
    Collection<ProgrammaticSearchMappingProvider> mappingProviders = ServiceFinder.load(ProgrammaticSearchMappingProvider.class, aggregatedClassLoader);
    SearchMappingCommonBuilding commonBuilding = new SearchMappingCommonBuilding(KeyTransformationHandlerIdentifierBridge.createReference(keyTransformationHandler), extractProperties(globalConfiguration, indexingConfiguration, aggregatedClassLoader), aggregatedClassLoader, mappingProviders);
    Set<Class<?>> types = new HashSet<>(indexedClasses.values());
    if (!types.isEmpty()) {
        // use the common builder to create the mapping now
        SearchMappingBuilder builder = commonBuilding.builder(SearchMappingBuilder.introspector(MethodHandles.lookup()));
        builder.setEntityLoader(new EntityLoader<>(queryStatistics, cache, keyTransformationHandler));
        builder.addEntityTypes(types);
        searchMapping = builder.build();
        cr.registerComponent(searchMapping, SearchMapping.class);
    }
    if (searchMapping == null) {
        // register the common builder to create the mapping at a later time
        cr.registerComponent(commonBuilding, SearchMappingCommonBuilding.class);
    }
    return searchMapping;
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) ProgrammaticSearchMappingProvider(org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)2 SearchMappingCommonBuilding (org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 AdvancedCache (org.infinispan.AdvancedCache)1 Cache (org.infinispan.Cache)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 KeyTransformationHandler (org.infinispan.query.backend.KeyTransformationHandler)1 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)1 LocalQueryStatistics (org.infinispan.query.core.stats.impl.LocalQueryStatistics)1 EntityLoader (org.infinispan.query.impl.EntityLoader)1 LocalIndexStatistics (org.infinispan.query.stats.impl.LocalIndexStatistics)1 InternalCacheRegistry (org.infinispan.registry.InternalCacheRegistry)1 ProgrammaticSearchMappingProvider (org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider)1 SearchMappingBuilder (org.infinispan.search.mapper.mapping.SearchMappingBuilder)1