public PrepareCoordinator(AdvancedCache<byte[], byte[]> cache, XidImpl xid, boolean recoverable, long transactionTimeout) { this.xid = xid; this.recoverable = recoverable; this.transactionTimeout = transactionTimeout; this.cache = cache; ComponentRegistry registry = cache.getComponentRegistry(); this.transactionTable = registry.getComponent(TransactionTable.class); this.perCacheTxTable = registry.getComponent(PerCacheTxTable.class); this.globalTxTable = registry.getGlobalComponentRegistry().getComponent(GlobalTxTable.class); this.cacheXid = new CacheXid(ByteString.fromString(cache.getName()), xid); }
/** * Unregister query related MBeans for a cache, primarily the statistics, but also all other MBeans from the same * related group. */ private void unregisterQueryMBeans(ComponentRegistry cr, String cacheName) { if (mbeanServer != null) { try { InfinispanQueryStatisticsInfo stats = cr.getComponent(InfinispanQueryStatisticsInfo.class); if (stats != null) { GlobalJmxStatisticsConfiguration jmxConfig = cr.getGlobalComponentRegistry().getGlobalConfiguration().globalJmxStatistics(); String queryGroupName = getQueryGroupName(jmxConfig.cacheManagerName(), cacheName); String queryMBeanFilter = stats.getObjectName().getDomain() + ":" + queryGroupName + ",*"; JmxUtil.unregisterMBeans(queryMBeanFilter, mbeanServer); } } catch (Exception e) { throw new CacheException("Unable to unregister query MBeans", e); } } }
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); }
/** * Registers the {@link PerCacheTxTable} to a transactional cache. */ private void registerServerTransactionTable(ComponentRegistry componentRegistry, String cacheName) { //skip for global tx table and non-transactional cache if (GLOBAL_TX_TABLE_CACHE_NAME.equals(cacheName) || !componentRegistry.getComponent(Configuration.class).transaction().transactionMode().isTransactional()) { return; } EmbeddedCacheManager cacheManager = componentRegistry.getGlobalComponentRegistry() .getComponent(EmbeddedCacheManager.class); createGlobalTxTable(cacheManager); // TODO We need a way for a module to install a factory before the default implementation is instantiated BasicComponentRegistry basicComponentRegistry = componentRegistry.getComponent(BasicComponentRegistry.class); basicComponentRegistry.replaceComponent(PerCacheTxTable.class.getName(), new PerCacheTxTable(cacheManager.getAddress()), true); basicComponentRegistry.replaceComponent(TransactionOriginatorChecker.class.getName(), new ServerTransactionOriginatorChecker(), true); basicComponentRegistry.rewire(); }
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; }
@Override public void init(InitializationContext ctx) { this.configuration = ctx.getConfiguration(); this.emfRegistry = ctx.getCache().getAdvancedCache().getComponentRegistry().getGlobalComponentRegistry().getComponent(EntityManagerFactoryRegistry.class); this.marshallerEntryFactory = ctx.getMarshalledEntryFactory(); this.marshaller = ctx.getMarshaller(); this.timeService = ctx.getTimeService(); this.executorService = ctx.getExecutor(); }
public void registerEncoder(Encoder encoder) { EncoderRegistry encoderRegistry = embeddedCache.getAdvancedCache().getComponentRegistry() .getGlobalComponentRegistry().getComponent(EncoderRegistry.class); encoderRegistry.registerEncoder(encoder); } }
@Override public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String cacheContainerName = address.getElement(address.size() - 2).getValue(); final String cacheName = address.getElement(address.size() - 1).getValue(); final ServiceController<?> controller = context.getServiceRegistry(false).getService( CacheServiceName.CACHE.getServiceName(cacheContainerName, cacheName)); if (controller != null) { Cache<?, ?> cache = (Cache<?, ?>) controller.getValue(); if (cache != null) { ComponentRegistry registry = SecurityActions.getComponentRegistry(cache.getAdvancedCache()); LocalTopologyManagerImpl localTopologyManager = (LocalTopologyManagerImpl) registry .getGlobalComponentRegistry().getComponent(LocalTopologyManager.class); if (localTopologyManager != null) { try { if (operation.hasDefined(VALUE)) { ModelNode newValue = operation.get(VALUE); localTopologyManager.setCacheAvailability(cacheName, AvailabilityMode.valueOf(newValue.asString())); } else { context.getResult().set(new ModelNode().set(localTopologyManager.getCacheAvailability(cacheName).toString())); } } catch (Exception e) { throw new OperationFailedException(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())); } } } } } }
@Override public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String cacheContainerName = address.getElement(address.size() - 2).getValue(); final String cacheName = address.getElement(address.size() - 1).getValue(); final ServiceController<?> controller = context.getServiceRegistry(false).getService( CacheServiceName.CACHE.getServiceName(cacheContainerName, cacheName)); if (controller != null) { Cache<?, ?> cache = (Cache<?, ?>) controller.getValue(); if (cache != null) { ComponentRegistry registry = SecurityActions.getComponentRegistry(cache.getAdvancedCache()); LocalTopologyManagerImpl localTopologyManager = (LocalTopologyManagerImpl) registry .getGlobalComponentRegistry().getComponent(LocalTopologyManager.class); if (localTopologyManager != null) { try { if (operation.hasDefined(VALUE)) { ModelNode newValue = operation.get(VALUE); localTopologyManager.setCacheRebalancingEnabled(cacheName, newValue.asBoolean()); } else { context.getResult().set(new ModelNode().set(localTopologyManager.isCacheRebalancingEnabled(cacheName))); } } catch (Exception e) { throw new OperationFailedException(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())); } } } } } }
public static ControlledCommandFactory registerControlledCommandFactory(Cache cache, Class<? extends ReplicableCommand> toBlock) { ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); final ControlledCommandFactory ccf = new ControlledCommandFactory(componentRegistry.getCommandsFactory(), toBlock); TestingUtil.replaceComponent(cache, CommandsFactory.class, ccf, true); //hack: re-add the component registry to the GlobalComponentRegistry's "namedComponents" (CHM) in order to correctly publish it for // when it will be read by the InboundInvocationHandlder. InboundInvocationHandlder reads the value from the GlobalComponentRegistry.namedComponents before using it componentRegistry.getGlobalComponentRegistry().registerNamedComponentRegistry(componentRegistry, EmbeddedCacheManager.DEFAULT_CACHE_NAME); return ccf; }
private void registerQueryMBeans(ComponentRegistry cr, Configuration cfg, SearchIntegrator sf) { AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache(); GlobalConfiguration globalCfg = cr.getGlobalComponentRegistry().getGlobalConfiguration(); mbeanServer = JmxUtil.lookupMBeanServer(globalCfg); ManageableComponentMetadata massIndexerCompMetadata = cr.getGlobalComponentRegistry().getComponentMetadataRepo() .findComponentMetadata(MassIndexer.class) .toManageableComponentMetadata();
@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); } }
private static void completeLocalTransaction(AdvancedCache<?, ?> cache, XidImpl xid, long timeout, boolean commit) throws HeuristicRollbackException, HeuristicMixedException, RollbackException { PerCacheTxTable perCacheTxTable = cache.getComponentRegistry().getComponent(PerCacheTxTable.class); GlobalTxTable globalTxTable = cache.getComponentRegistry().getGlobalComponentRegistry() .getComponent(GlobalTxTable.class); try { //local transaction EmbeddedTransaction tx = perCacheTxTable.getLocalTx(xid); tx.runCommit(!commit); CacheXid cacheXid = new CacheXid(ByteString.fromString(cache.getName()), xid); TxFunction function = new SetCompletedTransactionFunction(commit); globalTxTable.update(cacheXid, function, timeout); } finally { perCacheTxTable.removeLocalTx(xid); } }
AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache(); GlobalJmxStatisticsConfiguration jmxConfig = cr.getGlobalComponentRegistry().getGlobalConfiguration().globalJmxStatistics(); if (mbeanServer == null) { mbeanServer = JmxUtil.lookupMBeanServer(jmxConfig.mbeanServerLookup(), jmxConfig.properties()); ManageableComponentMetadata massIndexerCompMetadata = cr.getGlobalComponentRegistry().getComponentMetadataRepo() .findComponentMetadata(MassIndexer.class) .toManageableComponentMetadata();
/** * 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); } }
public void testRollbackNoCommit() throws Throwable { String key = key("LON"); String val = val("LON"); ComponentRegistry cr = backup("LON").getAdvancedCache().getComponentRegistry(); GlobalComponentRegistry gcr = cr.getGlobalComponentRegistry(); BackupReceiverRepositoryImpl brr = (BackupReceiverRepositoryImpl) gcr.getComponent(BackupReceiverRepository.class); BackupReceiver backupCacheManager = brr.getBackupReceiver("LON", CacheContainer.DEFAULT_CACHE_NAME); BackupReceiverWrapper brWrapper = new BackupReceiverWrapper(backupCacheManager); brr.replace("LON", CacheContainer.DEFAULT_CACHE_NAME, brWrapper); assertNull(brWrapper.received); cache("LON", 0).put(key, val); assertNotNull(brWrapper.received); assertEquals(backup("LON").get(key), val); brWrapper.received = null; TransactionManager tmLon0 = cache("LON", 0).getAdvancedCache().getTransactionManager(); assertNull(brWrapper.received); tmLon0.begin(); cache("LON", 0).put(key, val); log.trace("Before rollback!"); tmLon0.rollback(); assertNull(brWrapper.received); }
/** * 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); } }
public void testCacheStopped() { final String site = "LON"; String key = key(site); String val = val(site); cache(site, 0).put(key, val); Cache<Object,Object> backup = backup(site); final GlobalComponentRegistry gcr = backup.getAdvancedCache().getComponentRegistry().getGlobalComponentRegistry(); assertEquals(backup.get(key), val); assertTrue(backup.getStatus().allowInvocations()); backup.stop(); eventually(new Condition() { @Override public boolean isSatisfied() throws Exception { BackupReceiverRepositoryImpl component = (BackupReceiverRepositoryImpl) gcr.getComponent(BackupReceiverRepository.class); return component.get(site, EmbeddedCacheManager.DEFAULT_CACHE_NAME) == null; } }); assertFalse(backup.getStatus().allowInvocations()); backup.start(); log.trace("About to put the 2nd value"); cache(site, 0).put(key, "v2"); assertEquals(backup(site).get(key), "v2"); assertTrue(backup.getStatus().allowInvocations()); }