Search in sources :

Example 1 with BasicComponentRegistry

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;
}
Also used : BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) RpcManager(org.infinispan.remoting.rpc.RpcManager) AdvancedCache(org.infinispan.AdvancedCache)

Example 2 with BasicComponentRegistry

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();
}
Also used : InvalidationInterceptor(org.infinispan.interceptors.impl.InvalidationInterceptor) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor)

Example 3 with BasicComponentRegistry

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();
    }
}
Also used : ClusterExpirationManager(org.infinispan.expiration.impl.ClusterExpirationManager) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) LockingInterceptor(org.infinispan.hibernate.cache.commons.access.LockingInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) UnorderedDistributionInterceptor(org.infinispan.hibernate.cache.commons.access.UnorderedDistributionInterceptor) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) UnorderedReplicationLogic(org.infinispan.hibernate.cache.commons.access.UnorderedReplicationLogic) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) ExpirationManagerImpl(org.infinispan.expiration.impl.ExpirationManagerImpl)

Example 4 with BasicComponentRegistry

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;
}
Also used : BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry)

Example 5 with BasicComponentRegistry

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);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Aggregations

BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)30 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)11 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)7 AdvancedCache (org.infinispan.AdvancedCache)6 Cache (org.infinispan.Cache)5 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)5 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)5 InternalCacheRegistry (org.infinispan.registry.InternalCacheRegistry)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 ConfigurationManager (org.infinispan.configuration.ConfigurationManager)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 Collections (java.util.Collections)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Executors (java.util.concurrent.Executors)2 CacheStatusRequestCommand (org.infinispan.commands.topology.CacheStatusRequestCommand)2 TimeService (org.infinispan.commons.time.TimeService)2