Search in sources :

Example 21 with BasicComponentRegistry

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;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) TimeService(org.infinispan.commons.time.TimeService) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 22 with BasicComponentRegistry

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

Example 23 with BasicComponentRegistry

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());
}
Also used : PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyServerStateManager(org.infinispan.server.core.DummyServerStateManager) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) BasicAuthenticator(org.infinispan.rest.authentication.impl.BasicAuthenticator) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) SimpleSecurityDomain(org.infinispan.rest.resources.security.SimpleSecurityDomain) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 24 with BasicComponentRegistry

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));
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry)

Example 25 with BasicComponentRegistry

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

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