use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class CountingRpcManager method replaceRpcManager.
public static CountingRpcManager replaceRpcManager(Cache c) {
AdvancedCache advancedCache = c.getAdvancedCache();
CountingRpcManager crm = new CountingRpcManager(advancedCache.getRpcManager());
BasicComponentRegistry bcr = advancedCache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
bcr.replaceComponent(RpcManager.class.getName(), crm, false);
bcr.rewire();
assert advancedCache.getRpcManager().equals(crm);
return crm;
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class PutFromLoadValidator method removeFromCache.
/**
* This methods should be called only from tests; it removes existing validator from the cache structures
* in order to replace it with new one.
*
* @param cache
*/
public static PutFromLoadValidator removeFromCache(AdvancedCache cache) {
AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
BasicComponentRegistry cr = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
chain.removeInterceptor(TxPutFromLoadInterceptor.class);
chain.removeInterceptor(NonTxPutFromLoadInterceptor.class);
chain.getInterceptors().stream().filter(BaseInvalidationInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass).ifPresent(invalidationClass -> {
InvalidationInterceptor invalidationInterceptor = new InvalidationInterceptor();
cr.replaceComponent(InvalidationInterceptor.class.getName(), invalidationInterceptor, true);
cr.getComponent(InvalidationInterceptor.class).running();
chain.replaceInterceptor(invalidationInterceptor, invalidationClass);
});
chain.getInterceptors().stream().filter(LockingInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass).ifPresent(invalidationClass -> {
NonTransactionalLockingInterceptor lockingInterceptor = new NonTransactionalLockingInterceptor();
cr.replaceComponent(NonTransactionalLockingInterceptor.class.getName(), lockingInterceptor, true);
cr.getComponent(NonTransactionalLockingInterceptor.class).running();
chain.replaceInterceptor(lockingInterceptor, LockingInterceptor.class);
});
return cr.getComponent(PutFromLoadValidator.class).running();
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class DomainDataRegionImpl method prepareCommon.
private void prepareCommon(CacheMode cacheMode) {
BasicComponentRegistry registry = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
if (cacheMode.isReplicated() || cacheMode.isDistributed()) {
AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
LockingInterceptor lockingInterceptor = new LockingInterceptor();
registry.registerComponent(LockingInterceptor.class, lockingInterceptor, true);
registry.getComponent(LockingInterceptor.class).running();
if (!chain.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) {
throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
}
chain.removeInterceptor(NonTransactionalLockingInterceptor.class);
UnorderedDistributionInterceptor distributionInterceptor = new UnorderedDistributionInterceptor();
registry.registerComponent(UnorderedDistributionInterceptor.class, distributionInterceptor, true);
registry.getComponent(UnorderedDistributionInterceptor.class).running();
if (!chain.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class) && !chain.addInterceptorBefore(distributionInterceptor, TriangleDistributionInterceptor.class)) {
throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
}
chain.removeInterceptor(NonTxDistributionInterceptor.class);
chain.removeInterceptor(TriangleDistributionInterceptor.class);
}
// ClusteredExpirationManager sends RemoteExpirationCommands to remote nodes which causes
// undesired overhead. When get() triggers a RemoteExpirationCommand executed in async executor
// this locks the entry for the duration of RPC, and putFromLoad with ZERO_LOCK_ACQUISITION_TIMEOUT
// fails as it finds the entry being blocked.
ComponentRef<InternalExpirationManager> ref = registry.getComponent(InternalExpirationManager.class);
InternalExpirationManager expirationManager = ref.running();
if (expirationManager instanceof ClusterExpirationManager) {
registry.replaceComponent(InternalExpirationManager.class.getName(), new ExpirationManagerImpl<>(), true);
registry.getComponent(InternalExpirationManager.class).running();
registry.rewire();
// re-registering component does not stop the old one
((ClusterExpirationManager) expirationManager).stop();
} else if (expirationManager instanceof ExpirationManagerImpl) {
// do nothing
} else {
throw new IllegalStateException("Expected clustered expiration manager, found " + expirationManager);
}
registry.registerComponent(InfinispanDataRegion.class, this, true);
if (cacheMode.isClustered()) {
UnorderedReplicationLogic replLogic = new UnorderedReplicationLogic();
registry.replaceComponent(ClusteringDependentLogic.class.getName(), replLogic, true);
registry.getComponent(ClusteringDependentLogic.class).running();
registry.rewire();
}
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class TestingUtil method replaceComponent.
/**
* Same as {@link TestingUtil#replaceComponent(CacheContainer, Class, Object, boolean)} except that you can provide
* an optional name, to replace specifically named components.
*
* @param cacheContainer cache in which to replace component
* @param componentType component type of which to replace
* @param name name of the component
* @param replacementComponent new instance
* @param rewire if true, ComponentRegistry.rewire() is called after replacing.
*
* @return the original component that was replaced
*/
public static <T> T replaceComponent(CacheContainer cacheContainer, Class<T> componentType, String name, T replacementComponent, boolean rewire) {
GlobalComponentRegistry cr = extractGlobalComponentRegistry(cacheContainer);
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
ComponentRef<T> old = bcr.getComponent(componentType);
bcr.replaceComponent(name, replacementComponent, true);
if (rewire) {
cr.rewire();
cr.rewireNamedRegistries();
}
return old != null ? old.wired() : null;
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class BaseScatteredTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
ConfigurationBuilder cfg = getDefaultClusteredCacheConfig(CacheMode.SCATTERED_SYNC, false);
if (biasAcquisition != null) {
cfg.clustering().biasAcquisition(biasAcquisition);
}
cfg.clustering().hash().numSegments(16);
// for debugging
cfg.clustering().remoteTimeout(4, TimeUnit.MINUTES);
createCluster(TestDataSCI.INSTANCE, cfg, 3);
cm1 = manager(0);
cm2 = manager(1);
cm3 = manager(2);
// them and then rewire
for (EmbeddedCacheManager cm : cacheManagers) cm.getCache();
TestingUtil.waitForNoRebalance(caches());
svms = caches().stream().map(c -> {
ControlledScatteredVersionManager csvm = new ControlledScatteredVersionManager();
BasicComponentRegistry bcr = c.getAdvancedCache().getComponentRegistry().getComponent(BasicComponentRegistry.class);
bcr.replaceComponent(ScatteredVersionManager.class.getName(), csvm, true);
bcr.rewire();
return csvm;
}).toArray(ControlledScatteredVersionManager[]::new);
}
Aggregations