@Override public EmbeddedCacheManager get() { GlobalConfiguration config = this.configuration.get(); String defaultCacheName = config.defaultCacheName().orElse(null); // We need to create a dummy default configuration if cache has a default cache Configuration defaultConfiguration = (defaultCacheName != null) ? new ConfigurationBuilder().build() : null; EmbeddedCacheManager manager = new DefaultCacheManager(config, defaultConfiguration, false); // Undefine the default cache, if we defined one if (defaultCacheName != null) { manager.undefineConfiguration(defaultCacheName); } // Override GlobalConfigurationManager with a local implementation @SuppressWarnings("deprecation") BasicComponentRegistry registry = manager.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class); registry.replaceComponent(GlobalConfigurationManager.class.getName(), new LocalGlobalConfigurationManager(), false); registry.rewire(); manager.start(); manager.addListener(this); InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name); return manager; }
public ServerTaskEngine(ServerTaskRegistry manager, EmbeddedCacheManager cacheManager, ScriptConversions scriptConversions) { this.registry = manager; this.globalAuthzHelper = cacheManager.getGlobalComponentRegistry().getComponent(AuthorizationHelper.class); this.scriptConversions = scriptConversions; }
private synchronized void createGlobalTxTable(EmbeddedCacheManager cacheManager) { if (!registered) { Cache<CacheXid, TxState> cache = cacheManager.getCache(GLOBAL_TX_TABLE_CACHE_NAME); GlobalTxTable txTable = new GlobalTxTable(cache, cacheManager.getGlobalComponentRegistry()); cacheManager.getGlobalComponentRegistry().registerComponent(txTable, GlobalTxTable.class); registered = true; } }
private CacheCommandFactory getCacheCommandFactory() { final GlobalComponentRegistry globalCr = manager.getGlobalComponentRegistry(); final Map<Byte, ModuleCommandFactory> factories = globalCr.getComponent( "org.infinispan.modules.command.factories" ); for ( ModuleCommandFactory factory : factories.values() ) { if ( factory instanceof CacheCommandFactory ) { return (CacheCommandFactory) factory; } } throw log.cannotInstallCommandFactory(); }
private ServerTaskRegistry getRegistry(TaskContext context) { Cache<?, ?> cache = context.getCache().get(); return cache.getCacheManager().getGlobalComponentRegistry().getComponent(ServerTaskRegistry.class); } }
@Override protected ModelNode invokeCommand(EmbeddedCacheManager cacheManager, OperationContext context, ModelNode operation) throws Exception { ScriptingManager scriptManager = cacheManager.getGlobalComponentRegistry().getComponent(ScriptingManager.class); String scriptName = CacheContainerResource.SCRIPT_NAME.resolveModelAttribute(context, operation).asString(); scriptManager.removeScript(scriptName); return null; } }
@Override protected ModelNode invokeCommand(EmbeddedCacheManager cacheManager, OperationContext context, ModelNode operation) { final String siteNameParameter = CacheContainerResource.SITE_NAME.getName(); final ModelNode siteName = operation.require(siteNameParameter); GlobalXSiteAdminOperations xsiteAdminOperations = cacheManager.getGlobalComponentRegistry().getComponent(GlobalXSiteAdminOperations.class); return toOperationResult(xsiteAdminOperations.cancelPushState(siteName.asString())); } }
@Override public void setEnvironment(Cache<Object, Object> cache, Set<Object> inputKeys) { this.cache = cache; // todo inject global component registry to be independent of existence of cache. GlobalComponentRegistry componentRegistry = cache.getCacheManager().getGlobalComponentRegistry(); taskRegistry = componentRegistry.getComponent(ServerTaskRegistry.class); marshaller = componentRegistry.getComponent(StreamingMarshaller.class); }
void forgetTransaction(HotRodHeader header, Subject subject, XidImpl xid) { //TODO authentication? GlobalTxTable txTable = server.getCacheManager().getGlobalComponentRegistry().getComponent(GlobalTxTable.class); executor.execute(() -> { try { txTable.forgetTransaction(xid); writeSuccess(header); } catch (Throwable t) { writeException(header, t); } }); }
private void validateGlobalConfiguration() { boolean globalConfigIsEnabled = cacheManager.getGlobalComponentRegistry() .getGlobalConfiguration().globalState() .enabled(); if ( !globalConfigIsEnabled ) { throw LOG.counterCannotBeCreatedWithoutGlobalConfiguration(); } }
@AfterClass public void tearDown() { if (cacheManager != null) { cacheManager.getGlobalComponentRegistry().getComponent(ExecutorService.class, KnownComponentNames.REMOTE_COMMAND_EXECUTOR).shutdownNow(); cacheManager.stop(); } }
/** * Acquires a Matcher instance from the ComponentRegistry of the given Cache object. */ @Inject protected void injectDependencies(Cache cache) { this.queryCache = cache.getCacheManager().getGlobalComponentRegistry().getComponent(QueryCache.class); ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); matcher = componentRegistry.getComponent(matcherImplClass); if (matcher == null) { throw new CacheException("Expected component not found in registry: " + matcherImplClass.getName()); } }
@BeforeClass private void init() { cacheManager = TestCacheManagerFactory.createClusteredCacheManager(); internalCacheRegistry = cacheManager.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class); clusterHealth = new ClusterHealthImpl(cacheManager); }
protected void replaceComponent() { if (ourHandler == null) { originalComponent = cacheManager.getGlobalComponentRegistry().getComponent(componentClass); if (originalComponent == null) { throw new IllegalStateException("Attempting to wrap a non-existing global component: " + componentClass); } ourHandler = new ProxyInvocationHandler(originalComponent, stateSequencer, matcher); T componentProxy = createComponentProxy(componentClass, ourHandler); TestingUtil.replaceComponent(cacheManager, componentClass, componentProxy, true); } }
@CacheStarted public void cacheStarted(CacheStartedEvent event) { if (!event.getCacheManager().getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class).isInternalCache(event.getCacheName())) InfinispanLogger.ROOT_LOGGER.cacheStarted(event.getCacheName(), this.name); }
@BeforeMethod private void configureBeforeMethod() { mockedCacheManager = mock(DefaultCacheManager.class); // We return the real global component registry to avoid to mock all the dependencies in the world when(mockedCacheManager.getGlobalComponentRegistry()).thenReturn(cacheManager.getGlobalComponentRegistry()); internalCacheRegistry.registerInternalCache(INTERNAL_CACHE_NAME, new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_ASYNC).build(), EnumSet.of(InternalCacheRegistry.Flag.EXCLUSIVE)); cacheManager.defineConfiguration(CACHE_NAME, new ConfigurationBuilder().build()); }
private void preStartCaches() { // Start defined caches to avoid issues with lazily started caches. Skip internal caches if authorization is not // enabled InternalCacheRegistry icr = cacheManager.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class); boolean authz = cacheManager.getCacheManagerConfiguration().security().authorization().enabled(); for (String cacheName : cacheManager.getCacheNames()) { getCacheInstance(UNKNOWN_TYPES, null, cacheName, cacheManager, false, (!icr.internalCacheHasFlag(cacheName, InternalCacheRegistry.Flag.PROTECTED) || authz)); } }
public static CountingRequestRepository replaceDispatcher(EmbeddedCacheManager cacheManager) { GlobalComponentRegistry gcr = cacheManager.getGlobalComponentRegistry(); JGroupsTransport transport = (JGroupsTransport) gcr.getComponent(Transport.class); RequestRepository requestRepository = (RequestRepository) TestingUtil.extractField(JGroupsTransport.class, transport, "requests"); CountingRequestRepository instance = new CountingRequestRepository(requestRepository); TestingUtil.replaceField(instance, "requests", transport, JGroupsTransport.class); return instance; }
public void testLoopbackPutOnProtectedCache(Method m) { InternalCacheRegistry internalCacheRegistry = manager(0).getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class); internalCacheRegistry.registerInternalCache("MyInternalCache", new ConfigurationBuilder().build(), EnumSet.of(InternalCacheRegistry.Flag.USER, InternalCacheRegistry.Flag.PROTECTED)); TestResponse resp = hotRodClient.execute(0xA0, (byte) 0x01, "MyInternalCache", k(m), 0, 0, v(m), 0, (byte) 1, 0); assertEquals(Success, resp.status); }
@Override public void call() { GlobalComponentRegistry registry = cm.getGlobalComponentRegistry(); EncoderRegistry encoderRegistry = registry.getComponent(EncoderRegistry.class); encoderRegistry.registerEncoder(new GzipEncoder()); AdvancedCache<String, String> cache = cm.<String, String>getCache().getAdvancedCache(); AdvancedCache<String, String> compressingCache = (AdvancedCache<String, String>) cache.withEncoding(IdentityEncoder.class, GzipEncoder.class); compressingCache.put("297931749", "0412c789a37f5086f743255cfa693dd502b6a2ecb2ceee68380ff58ad15e7b56"); assertEquals(compressingCache.get("297931749"), "0412c789a37f5086f743255cfa693dd502b6a2ecb2ceee68380ff58ad15e7b56"); Object value = compressingCache.withEncoding(IdentityEncoder.class).get("297931749"); assert value instanceof byte[]; } });