@Override public void initCache() { this.workCache.getAdvancedCache().getComponentRegistry().registerComponent(sessionFactory, KeycloakSessionFactory.class); }
public void initCache() { this.cache.getAdvancedCache().getComponentRegistry().registerComponent(sessionFactory, KeycloakSessionFactory.class); cache.getCacheManager().addListener(new ViewChangeListener()); }
private SearchIntegrator createSearchIntegrator(IndexingConfiguration indexingConfiguration, ComponentRegistry cr, ClassLoader aggregatedClassLoader) { SearchIntegrator searchIntegrator = cr.getComponent(SearchIntegrator.class); if (searchIntegrator != null && !searchIntegrator.isStopped()) { // a paranoid check against an unlikely failure throw new IllegalStateException("SearchIntegrator already initialized!"); } // load ProgrammaticSearchMappingProviders from classpath Collection<ProgrammaticSearchMappingProvider> programmaticSearchMappingProviders = new LinkedHashSet<>(); programmaticSearchMappingProviders.add(new DefaultSearchMappingProvider()); // make sure our DefaultSearchMappingProvider is first programmaticSearchMappingProviders.addAll(ServiceFinder.load(ProgrammaticSearchMappingProvider.class, aggregatedClassLoader)); // load LuceneAnalysisDefinitionProvider from classpath Collection<LuceneAnalysisDefinitionProvider> analyzerDefProviders = ServiceFinder.load(LuceneAnalysisDefinitionProvider.class, aggregatedClassLoader); // Set up the search factory for Hibernate Search first. SearchConfiguration config = new SearchableCacheConfiguration(indexingConfiguration.indexedEntities(), indexingConfiguration.properties(), programmaticSearchMappingProviders, analyzerDefProviders, cr, aggregatedClassLoader); searchIntegrator = new SearchIntegratorBuilder().configuration(config).buildSearchIntegrator(); cr.registerComponent(searchIntegrator, SearchIntegrator.class); return searchIntegrator; }
public static StreamSummaryContainer getOrCreateStreamLibContainer(Cache cache) { ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); StreamSummaryContainer streamLibContainer = componentRegistry.getComponent(StreamSummaryContainer.class); if (streamLibContainer == null) { String cacheName = cache.getName(); String address = String.valueOf(cache.getCacheManager().getAddress()); componentRegistry.registerComponent(new StreamSummaryContainer(cacheName, address), StreamSummaryContainer.class); } return componentRegistry.getComponent(StreamSummaryContainer.class); }
private EntryVersion generateVersion(Cache<byte[], byte[]> cache) { ComponentRegistry registry = getCacheRegistry(); VersionGenerator cacheVersionGenerator = registry.getComponent(VersionGenerator.class); if (cacheVersionGenerator == null) { NumericVersionGenerator newVersionGenerator = new NumericVersionGenerator() .clustered(registry.getComponent(RpcManager.class) != null); registry.registerComponent(newVersionGenerator, VersionGenerator.class); return newVersionGenerator.generateNew(); } else { return cacheVersionGenerator.generateNew(); } }
private void registerMatcher(ComponentRegistry cr, SearchIntegrator searchFactory, ClassLoader classLoader) { ReflectionMatcher reflectionMatcher = searchFactory == null ? new ReflectionMatcher(classLoader) : new ReflectionMatcher(new HibernateSearchPropertyHelper(searchFactory, new ReflectionEntityNamesResolver(classLoader))); cr.registerComponent(reflectionMatcher, ReflectionMatcher.class); }
private void registerMatcher(ComponentRegistry cr, SearchIntegrator searchFactory) { ClassLoader classLoader = cr.getGlobalComponentRegistry().getComponent(ClassLoader.class); ReflectionMatcher reflectionMatcher; if (searchFactory == null) { reflectionMatcher = new ReflectionMatcher(classLoader); } else { ReflectionEntityNamesResolver entityNamesResolver = new ReflectionEntityNamesResolver(classLoader); reflectionMatcher = new ReflectionMatcher(new HibernateSearchPropertyHelper(searchFactory, entityNamesResolver)); } cr.registerComponent(reflectionMatcher, ReflectionMatcher.class); }
private SearchIntegrator getSearchFactory(String cacheName, IndexingConfiguration indexingConfiguration, ComponentRegistry cr) { Object component = cr.getComponent(SearchIntegrator.class); SearchIntegrator searchFactory = null; if (component instanceof SearchIntegrator) { //could be the placeholder Object REMOVED_REGISTRY_COMPONENT searchFactory = (SearchIntegrator) component; } //defend against multiple initialization: if (searchFactory == null) { GlobalComponentRegistry globalComponentRegistry = cr.getGlobalComponentRegistry(); EmbeddedCacheManager uninitializedCacheManager = globalComponentRegistry.getComponent(EmbeddedCacheManager.class); Properties indexingProperties = addProgrammaticMappings(indexingConfiguration.properties(), cr); Class<?>[] indexedEntities = indexingConfiguration.indexedEntities().toArray(new Class<?>[indexingConfiguration.indexedEntities().size()]); if (indexedEntities.length > 0 && hasInfinispanDirectory(indexingProperties)) { String metadataCacheName = getMetadataCacheName(indexingProperties); String lockingCacheName = getLockingCacheName(indexingProperties); String dataCacheName = getDataCacheName(indexingProperties); if (cacheName.equals(dataCacheName) || cacheName.equals(metadataCacheName) || cacheName.equals(lockingCacheName)) { // Infinispan Directory causes runtime circular dependencies so we need to postpone creation of indexes until all components are initialised indexedEntities = new Class[0]; } } allowDynamicSortingByDefault(indexingProperties); // Set up the search factory for Hibernate Search first. SearchConfiguration config = new SearchableCacheConfiguration(indexedEntities, indexingProperties, uninitializedCacheManager, cr); searchFactory = new SearchIntegratorBuilder().configuration(config).buildSearchIntegrator(); cr.registerComponent(searchFactory, SearchIntegrator.class); } return searchFactory; }
/** * 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); } }
private void createQueryInterceptorIfNeeded(ComponentRegistry cr, Configuration cfg, SearchIntegrator searchFactory) { QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class); if (queryInterceptor == null) { queryInterceptor = buildQueryInterceptor(cfg, searchFactory, cr.getComponent(Cache.class)); // Interceptor registration not needed, core configuration handling // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry! AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); interceptorBuilder.interceptor(queryInterceptor); boolean txVersioned = Configurations.isTxVersioned(cfg); boolean isTotalOrder = cfg.transaction().transactionProtocol().isTotalOrder(); Class<? extends DDAsyncInterceptor> wrappingInterceptor = EntryWrappingInterceptor.class; if (txVersioned) { wrappingInterceptor = isTotalOrder ? TotalOrderVersionedEntryWrappingInterceptor.class : VersionedEntryWrappingInterceptor.class; } if (ic != null) ic.addInterceptorAfter(queryInterceptor, wrappingInterceptor); interceptorBuilder.after(wrappingInterceptor); if (ic != null) { cr.registerComponent(queryInterceptor, QueryInterceptor.class); cr.registerComponent(queryInterceptor, queryInterceptor.getClass().getName(), true); } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
public void testTaskCancellation() throws Exception { CyclicBarrier barrier = new CyclicBarrier(2); cache(1, cacheName()).getAdvancedCache().getComponentRegistry().registerComponent(barrier, "barrier"); DistributedExecutorService des = createDES(getCache()); List<Address> cacheMembers = getCache().getAdvancedCache().getRpcManager().getMembers(); assertEquals(caches(cacheName()).size(), cacheMembers.size()); DistributedTaskBuilder<Integer> tb = des.createDistributedTaskBuilder(new LongRunningCallable()); final Future<Integer> future = des.submit(address(1), tb.build()); // Will unblock when LongRunningCallable starts running barrier.await(10, TimeUnit.SECONDS); future.cancel(true); boolean taskCancelled = false; try { future.get(); } catch (Exception e) { taskCancelled = e instanceof CancellationException; } assert taskCancelled : "Dist task not cancelled "; // Will unblock when LongRunningCallable is interrupted barrier.await(10, TimeUnit.SECONDS); assert future.isCancelled(); assert future.isDone(); //Testing whether the cancellation already happened. boolean isCanceled = future.cancel(true); assert !isCanceled; }
/** * 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); } }
@Override public void cacheStopping(ComponentRegistry cr, String cacheName) { final QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class); if (queryInterceptor != null) { queryInterceptor.prepareForStopping(); } //TODO move this to cacheStopped event (won't work right now as the ComponentRegistry is half empty at that point: ISPN-1006) Object searchFactoryIntegrator = cr.getComponent(SearchIntegrator.class); if (searchFactoryIntegrator != null && searchFactoryIntegrator != REMOVED_REGISTRY_COMPONENT) { ((SearchIntegrator) searchFactoryIntegrator).close(); //free some memory by de-registering the SearchFactory cr.registerComponent(REMOVED_REGISTRY_COMPONENT, SearchIntegrator.class); } // Unregister MBeans if (mbeanServer != null) { String cacheManagerName = cr.getGlobalComponentRegistry().getGlobalConfiguration().globalJmxStatistics().cacheManagerName(); String queryMBeanFilter = jmxDomain + ":" + getQueryGroupName(cacheManagerName, cacheName) + ",*"; JmxUtil.unregisterMBeans(queryMBeanFilter, mbeanServer); } }
public void testBasicTargetLocalDistributedCallableWithTimeout() throws Exception { Cache<Object, Object> cache1 = getCache(); Cache<Object, Object> cache2 = cache(1, cacheName()); CyclicBarrier barrier = new CyclicBarrier(2); cache2.getAdvancedCache().getComponentRegistry().registerComponent(barrier, "barrier"); // initiate task from cache1 and execute on same node DistributedExecutorService des = createDES(cache1); Address target = address(0); DistributedTaskBuilder builder = des.createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); builder.timeout(100, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); expectException(ExecutionException.class, () -> future.get()); }
private void createRemoteIndexingInterceptor(ComponentRegistry cr, Configuration cfg) { BaseTypeConverterInterceptor wrapperInterceptor = cr.getComponent(RemoteValueWrapperInterceptor.class); if (wrapperInterceptor == null) { wrapperInterceptor = new RemoteValueWrapperInterceptor(); // Interceptor registration not needed, core configuration handling // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry! InterceptorChain ic = cr.getComponent(InterceptorChain.class); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); interceptorBuilder.interceptor(wrapperInterceptor); if (ic != null) ic.addInterceptorAfter(wrapperInterceptor, InvocationContextInterceptor.class); interceptorBuilder.after(InvocationContextInterceptor.class); if (ic != null) { cr.registerComponent(wrapperInterceptor, RemoteValueWrapperInterceptor.class); } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
cr.registerComponent(stats, InfinispanQueryStatisticsInfo.class); } catch (Exception e) { throw new CacheException("Unable to register query statistics MBean", e);