private static void ensureIndexed(Cache<?, ?> cache) { Configuration cfg = SecurityActions.getCacheConfiguration(cache); if (!cfg.indexing().index().isEnabled()) { throw new IllegalStateException("Indexing was not enabled on cache " + cache.getName()); } }
Configuration configuration = cr.getComponent(Configuration.class); IndexingConfiguration indexingConfiguration = configuration.indexing(); if (!indexingConfiguration.index().isEnabled()) { 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");
/** * For a given configuration, define which IndexModificationStrategy is going to be used. * @param searchFactory * @param cfg * @return the appropriate IndexModificationStrategy */ public static IndexModificationStrategy configuredStrategy(SearchIntegrator searchFactory, Configuration cfg) { IndexingMode indexingMode = searchFactory.unwrap(SearchIntegrator.class).getIndexingMode(); if (indexingMode == IndexingMode.MANUAL) { return MANUAL; } else { if (cfg.indexing().index().isLocalOnly()) { return LOCAL_ONLY; } else if (cfg.indexing().index().isPrimaryOwner()) { return PRIMARY_OWNER; } else { return ALL; } } }
Configuration configuration = cr.getComponent(Configuration.class); IndexingConfiguration indexingConfiguration = configuration.indexing(); if (!indexingConfiguration.index().isEnabled()) { 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");
/** * For a given configuration, define which IndexModificationStrategy is going to be used. * @param searchFactory * @param cfg * @return the appropriate IndexModificationStrategy */ public static IndexModificationStrategy configuredStrategy(SearchIntegrator searchFactory, Configuration cfg) { IndexingMode indexingMode = searchFactory.unwrap(SearchIntegrator.class).getIndexingMode(); if (indexingMode == IndexingMode.MANUAL) { return MANUAL; } else { if (cfg.indexing().index().isLocalOnly()) { return LOCAL_ONLY; } else if (cfg.indexing().index().isPrimaryOwner()) { return PRIMARY_OWNER; } else { return ALL; } } }
/** * Registers the remote value wrapper interceptor in the cache before it gets started. */ @Override public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) { if (!cacheName.equals(Support.AVRO_METADATA_CACHE_NAME)) { if (cfg.indexing().index().isEnabled() && !cfg.compatibility().enabled()) { log.infof("Registering RemoteAvroValueWrapperInterceptor for cache %s", cacheName); createRemoteIndexingInterceptor(cr, cfg); } } }
@Override public void cacheStarted(ComponentRegistry cr, String cacheName) { Configuration configuration = cr.getComponent(Configuration.class); boolean remoteValueWrappingEnabled = configuration.indexing().index().isEnabled() && !configuration.compatibility().enabled(); if (!remoteValueWrappingEnabled) { if (verifyChainContainsRemoteAvroValueWrapperInterceptor(cr)) { throw new IllegalStateException("It was NOT expected to find the RemoteAvroValueWrapperInterceptor registered in the InterceptorChain as indexing was disabled, but it was found"); } return; } if (!verifyChainContainsRemoteAvroValueWrapperInterceptor(cr)) { throw new IllegalStateException("It was expected to find the RemoteAvroValueWrapperInterceptor registered in the InterceptorChain but it wasn't found"); } }
public TreeCacheImpl(AdvancedCache<?, ?> cache) { super(cache, cache.getBatchContainer()); if (cache.getCacheConfiguration().indexing().index().isEnabled()) throw new CacheConfigurationException("TreeCache cannot be used with a Cache instance configured to use indexing!"); assertBatchingSupported(cache.getCacheConfiguration()); createRoot(); }
assertTrue(defaultConfiguration.indexing().index().isEnabled()); assertEquals(defaultConfiguration.indexing().properties().getProperty("hibernate.search.default.directory_provider"), "someDefault"); assertFalse(nonSearchableCfg.indexing().index().isEnabled()); assertTrue(simpleCfg.indexing().index().isEnabled()); assertEquals(simpleCfg.indexing().properties().size(), 2); assertTrue(memoryCfg.indexing().index().isEnabled()); assertFalse(memoryCfg.indexing().index().isLocalOnly()); assertEquals(memoryCfg.indexing().properties().size(), 2); assertEquals(memoryCfg.indexing().properties().getProperty("hibernate.search.default.directory_provider"), "local-heap"); assertTrue(diskCfg.indexing().index().isEnabled()); assertTrue(diskCfg.indexing().index().isLocalOnly()); assertEquals(diskCfg.indexing().properties().size(), 3); assertEquals(diskCfg.indexing().properties().getProperty("hibernate.search.default.directory_provider"), "filesystem");
public void testConfigurationFileParsing() throws IOException { ParserRegistry parserRegistry = new ParserRegistry(Thread.currentThread().getContextClassLoader()); ConfigurationBuilderHolder holder = parserRegistry.parseFile("configuration-parsing-test.xml"); Map<String, ConfigurationBuilder> namedConfigurations = holder.getNamedConfigurationBuilders(); Configuration defaultConfiguration = namedConfigurations.get("default").build(); assertEquals(defaultConfiguration.indexing().properties().size(), 0); assertFalse(defaultConfiguration.indexing().index().isEnabled()); Configuration simpleCfg = namedConfigurations.get("simple").build(); assertFalse(simpleCfg.indexing().index().isEnabled()); assertEquals(simpleCfg.indexing().properties().size(), 0); Configuration memoryCfg = namedConfigurations.get("memory-searchable").build(); assertTrue(memoryCfg.indexing().index().isEnabled()); assertEquals(2, memoryCfg.indexing().properties().size()); assertEquals(memoryCfg.indexing().properties().getProperty("default.directory_provider"), "local-heap"); Configuration diskCfg = namedConfigurations.get("disk-searchable").build(); assertTrue(diskCfg.indexing().index().isEnabled()); assertEquals(diskCfg.indexing().properties().size(), 3); assertEquals(diskCfg.indexing().properties().getProperty("hibernate.search.default.directory_provider"), "filesystem"); assertEquals(diskCfg.indexing().properties().getProperty("hibernate.search.cats.exclusive_index_use"), "true"); Configuration replDefaults = namedConfigurations.get("repl-with-default").build(); assertTrue(replDefaults.indexing().index().isEnabled()); assertFalse(replDefaults.indexing().properties().isEmpty()); Configuration affinity = namedConfigurations.get("dist-with-affinity").build(); assertTrue(affinity.indexing().index().isEnabled()); assertTrue(affinity.indexing().index().isPrimaryOwner()); assertEquals(affinity.indexing().properties().getProperty("default.indexmanager"), AffinityIndexManager.class.getName()); }
public CacheInfo getCacheInfo(AdvancedCache<byte[], byte[]> cache, HotRodHeader header) { // Fetching persistence manager would require security action, and would be too expensive CacheInfo info = cacheInfo.get(cache.getName() + header.getKeyMediaType().getTypeSubtype() + header.getValueMediaType().getTypeSubtype()); if (info == null) { AdvancedCache<byte[], byte[]> localNonBlocking = SecurityActions.anonymizeSecureCache(cache) .noFlags().withFlags(LOCAL_NON_BLOCKING_GET); if (cache.getStatus() != ComponentStatus.RUNNING) { // stay on the safe side return new CacheInfo(localNonBlocking, true, true, true); } ComponentRegistry cr = SecurityActions.getCacheComponentRegistry(cache); PersistenceManager pm = cr.getComponent(PersistenceManager.class); boolean hasIndexing = SecurityActions.getCacheConfiguration(cache).indexing().index().isEnabled(); CacheNotifierImpl cacheNotifier = (CacheNotifierImpl) cr.getComponent(CacheNotifier.class); info = new CacheInfo(localNonBlocking, pm.isEnabled(), hasIndexing, hasSyncListener(cacheNotifier)); cacheInfo.put(cache.getName() + header.getKeyMediaType().getTypeSubtype() + header.getValueMediaType().getTypeSubtype(), info); } return info; }
/** * 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); if (!icr.isInternalCache(cacheName) || icr.internalCacheHasFlag(cacheName, Flag.QUERYABLE)) { boolean isIndexed = cfg.indexing().index().isEnabled(); AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache(); SearchIntegrator searchFactory = null; if (isIndexed) { log.registeringQueryInterceptor(cacheName); cr.registerComponent(new ShardAllocationManagerImpl(), ShardAllocatorManager.class); searchFactory = getSearchFactory(cacheName, cfg.indexing(), cr); createQueryInterceptorIfNeeded(cr, cfg, searchFactory); addCacheDependencyIfNeeded(cacheName, cache.getCacheManager(), cfg.indexing()); // initializing the query module command initializer. // we can t inject Cache and CacheManager with @inject in there CommandInitializer initializer = cr.getComponent(CommandInitializer.class); initializer.setCacheManager(cache.getCacheManager()); QueryBox queryBox = new QueryBox(); queryBox.setCache(cache); cr.registerComponent(queryBox, QueryBox.class); } registerMatcher(cr, searchFactory); EmbeddedQueryEngine queryEngine = new EmbeddedQueryEngine(cache, isIndexed); cr.registerComponent(queryEngine, EmbeddedQueryEngine.class); } }
/** * 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); if (!icr.isInternalCache(cacheName) || icr.internalCacheHasFlag(cacheName, Flag.QUERYABLE)) { AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache(); ClassLoader aggregatedClassLoader = makeAggregatedClassLoader(cr.getGlobalComponentRegistry().getGlobalConfiguration().classLoader()); SearchIntegrator searchFactory = null; boolean isIndexed = cfg.indexing().index().isEnabled(); if (isIndexed) { setBooleanQueryMaxClauseCount(); cr.registerComponent(new ShardAllocationManagerImpl(), ShardAllocatorManager.class); searchFactory = createSearchIntegrator(cfg.indexing(), cr, aggregatedClassLoader); KeyTransformationHandler keyTransformationHandler = new KeyTransformationHandler(aggregatedClassLoader); cr.registerComponent(keyTransformationHandler, KeyTransformationHandler.class); createQueryInterceptorIfNeeded(cr.getComponent(BasicComponentRegistry.class), cfg, cache, searchFactory, keyTransformationHandler); addCacheDependencyIfNeeded(cacheName, cache.getCacheManager(), cfg.indexing()); cr.registerComponent(new QueryBox(), QueryBox.class); } registerMatcher(cr, searchFactory, aggregatedClassLoader); cr.registerComponent(new EmbeddedQueryEngine(cache, isIndexed), EmbeddedQueryEngine.class); } }
assertEquals(2048, fileStore.async().modificationQueueSize()); assertEquals(1, fileStore.async().threadPoolSize()); assertEquals(Index.NONE, c.indexing().index()); assertEquals(11, c.expiration().lifespan()); assertEquals(11, c.expiration().maxIdle()); assertEquals(Index.NONE, c.indexing().index()); assertEquals(35000, clusterLoader.remoteCallTimeout()); assertFalse(clusterLoader.preload()); assertEquals(Index.NONE, c.indexing().index()); assertTrue(fileStore.preload()); assertFalse(fileStore.purgeOnStartup()); assertEquals(Index.NONE, c.indexing().index()); assertTrue(fileStore.preload()); assertFalse(fileStore.purgeOnStartup()); assertEquals(Index.NONE, c.indexing().index());