use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class TestInfinispanRegionFactory method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, ServiceRegistry serviceRegistry) {
// If the cache manager has been provided by calling setCacheManager, don't create a new one
EmbeddedCacheManager cacheManager = getCacheManager();
if (cacheManager != null) {
return cacheManager;
} else if (providedManager != null) {
cacheManager = providedManager;
} else {
ConfigurationBuilderHolder holder = DefaultCacheManagerProvider.loadConfiguration(serviceRegistry, properties);
configurationHook.amendConfiguration(holder);
cacheManager = new DefaultCacheManager(holder, true);
}
if (afterManagerCreated != null) {
afterManagerCreated.accept(cacheManager);
}
if (timeService != null) {
BasicComponentRegistry basicComponentRegistry = cacheManager.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class);
basicComponentRegistry.replaceComponent(TimeService.class.getName(), timeService, false);
basicComponentRegistry.rewire();
}
return cacheManager;
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class PutFromLoadValidator method addToCache.
/**
* Besides the call from constructor, this should be called only from tests when mocking the validator.
*/
public static void addToCache(AdvancedCache cache, PutFromLoadValidator validator) {
AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
List<AsyncInterceptor> interceptors = chain.getInterceptors();
log.debugf("Interceptor chain was: ", interceptors);
int position = 0;
// add interceptor before uses exact match, not instanceof match
int entryWrappingPosition = 0;
for (AsyncInterceptor ci : interceptors) {
if (ci instanceof EntryWrappingInterceptor) {
entryWrappingPosition = position;
}
position++;
}
boolean transactional = cache.getCacheConfiguration().transaction().transactionMode().isTransactional();
BasicComponentRegistry componentRegistry = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
if (transactional) {
TxInvalidationInterceptor txInvalidationInterceptor = new TxInvalidationInterceptor();
// We have to use replaceComponent because tests call addToCache more than once
componentRegistry.replaceComponent(TxInvalidationInterceptor.class.getName(), txInvalidationInterceptor, true);
componentRegistry.getComponent(TxInvalidationInterceptor.class).running();
chain.replaceInterceptor(txInvalidationInterceptor, InvalidationInterceptor.class);
// Note that invalidation does *NOT* acquire locks; therefore, we have to start invalidating before
// wrapping the entry, since if putFromLoad was invoked between wrap and beginInvalidatingKey, the invalidation
// would not commit the entry removal (as during wrap the entry was not in cache)
TxPutFromLoadInterceptor txPutFromLoadInterceptor = new TxPutFromLoadInterceptor(validator, ByteString.fromString(cache.getName()));
componentRegistry.replaceComponent(TxPutFromLoadInterceptor.class.getName(), txPutFromLoadInterceptor, true);
componentRegistry.getComponent(TxPutFromLoadInterceptor.class).running();
chain.addInterceptor(txPutFromLoadInterceptor, entryWrappingPosition);
} else {
NonTxPutFromLoadInterceptor nonTxPutFromLoadInterceptor = new NonTxPutFromLoadInterceptor(validator, ByteString.fromString(cache.getName()));
componentRegistry.replaceComponent(NonTxPutFromLoadInterceptor.class.getName(), nonTxPutFromLoadInterceptor, true);
componentRegistry.getComponent(NonTxPutFromLoadInterceptor.class).running();
chain.addInterceptor(nonTxPutFromLoadInterceptor, entryWrappingPosition);
NonTxInvalidationInterceptor nonTxInvalidationInterceptor = new NonTxInvalidationInterceptor();
componentRegistry.replaceComponent(NonTxInvalidationInterceptor.class.getName(), nonTxInvalidationInterceptor, true);
componentRegistry.getComponent(NonTxInvalidationInterceptor.class).running();
chain.replaceInterceptor(nonTxInvalidationInterceptor, InvalidationInterceptor.class);
LockingInterceptor lockingInterceptor = new LockingInterceptor();
componentRegistry.replaceComponent(LockingInterceptor.class.getName(), lockingInterceptor, true);
componentRegistry.getComponent(LockingInterceptor.class).running();
chain.replaceInterceptor(lockingInterceptor, NonTransactionalLockingInterceptor.class);
}
log.debugf("New interceptor chain is: ", cache.getAsyncInterceptorChain());
if (componentRegistry.getComponent(PutFromLoadValidator.class) == null) {
componentRegistry.registerComponent(PutFromLoadValidator.class, validator, false);
} else {
componentRegistry.replaceComponent(PutFromLoadValidator.class.getName(), validator, false);
}
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class AbstractRestResourceTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Exception {
Security.doAs(ADMIN, () -> {
for (int i = 0; i < NUM_SERVERS; i++) {
GlobalConfigurationBuilder configForNode = getGlobalConfigForNode(i);
addClusterEnabledCacheManager(new GlobalConfigurationBuilder().read(configForNode.build()), getDefaultCacheBuilder(), TransportFlags.minimalXsiteFlags());
}
cacheManagers.forEach(this::defineCaches);
cacheManagers.forEach(cm -> cm.defineConfiguration("invalid", getDefaultCacheBuilder().encoding().mediaType(APPLICATION_OBJECT_TYPE).indexing().enabled(true).addIndexedEntities("invalid").build()));
serverStateManager = new DummyServerStateManager();
for (EmbeddedCacheManager cm : cacheManagers) {
BasicComponentRegistry bcr = SecurityActions.getGlobalComponentRegistry(cm).getComponent(BasicComponentRegistry.class.getName());
bcr.registerComponent(ServerStateManager.class, serverStateManager, false);
cm.getClassAllowList().addClasses(TestClass.class);
waitForClusterToForm(cm.getCacheNames().stream().filter(name -> {
try {
cm.getCache(name);
return true;
} catch (CacheConfigurationException ignored) {
return false;
}
}).toArray(String[]::new));
RestServerHelper restServerHelper = new RestServerHelper(cm);
if (isSecurityEnabled()) {
BasicAuthenticator basicAuthenticator = new BasicAuthenticator(new SimpleSecurityDomain(ADMIN, USER), REALM);
restServerHelper.withAuthenticator(basicAuthenticator);
}
if (ssl) {
restServerHelper.withKeyStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE).withTrustStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE);
}
restServerHelper.start(TestResourceTracker.getCurrentTestShortName());
restServers.add(restServerHelper);
}
});
adminClient = RestClient.forConfiguration(getClientConfig("admin", "admin").build());
client = RestClient.forConfiguration(getClientConfig("user", "user").build());
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class LifecycleCallbacks method cacheManagerStarting.
@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration gc) {
ScriptingManagerImpl scriptingManager = new ScriptingManagerImpl();
gcr.registerComponent(scriptingManager, ScriptingManager.class);
SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, new PersistenceContextInitializerImpl());
BasicComponentRegistry bcr = gcr.getComponent(BasicComponentRegistry.class);
InternalCacheRegistry internalCacheRegistry = bcr.getComponent(InternalCacheRegistry.class).wired();
internalCacheRegistry.registerInternalCache(SCRIPT_CACHE, getScriptCacheConfiguration(gc).build(), EnumSet.of(InternalCacheRegistry.Flag.USER, InternalCacheRegistry.Flag.PROTECTED, InternalCacheRegistry.Flag.PERSISTENT, InternalCacheRegistry.Flag.GLOBAL));
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class LifecycleCallbacks method cacheStarting.
@Override
public void cacheStarting(ComponentRegistry cr, Configuration configuration, String cacheName) {
if (SCRIPT_CACHE.equals(cacheName)) {
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
ScriptingInterceptor scriptingInterceptor = new ScriptingInterceptor();
bcr.registerComponent(ScriptingInterceptor.class, scriptingInterceptor, true);
bcr.addDynamicDependency(AsyncInterceptorChain.class.getName(), ScriptingInterceptor.class.getName());
bcr.getComponent(AsyncInterceptorChain.class).wired().addInterceptorAfter(scriptingInterceptor, CacheMgmtInterceptor.class);
}
}
Aggregations