Search in sources :

Example 11 with GlobalComponentRegistry

use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.

the class TasksResourceTest method defineCaches.

@Override
protected void defineCaches(EmbeddedCacheManager cm) {
    cm.defineConfiguration("default", getDefaultCacheBuilder().build());
    GlobalComponentRegistry gcr = cm.getGlobalComponentRegistry();
    TaskManager taskManager = gcr.getComponent(TaskManager.class);
    TaskEngine taskEngine = new DummyTaskEngine();
    taskManager.registerTaskEngine(taskEngine);
}
Also used : DummyTaskEngine(org.infinispan.tasks.DummyTaskEngine) TaskEngine(org.infinispan.tasks.spi.TaskEngine) TaskManager(org.infinispan.tasks.TaskManager) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) DummyTaskEngine(org.infinispan.tasks.DummyTaskEngine)

Example 12 with GlobalComponentRegistry

use of org.infinispan.factories.GlobalComponentRegistry in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method getCacheCommandFactory.

private CacheCommandFactory getCacheCommandFactory() {
    final GlobalComponentRegistry globalCr = manager.getGlobalComponentRegistry();
    final Map<Byte, ModuleCommandFactory> factories = (Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
    for (ModuleCommandFactory factory : factories.values()) {
        if (factory instanceof CacheCommandFactory) {
            return (CacheCommandFactory) factory;
        }
    }
    throw log.cannotInstallCommandFactory();
}
Also used : ModuleCommandFactory(org.infinispan.commands.module.ModuleCommandFactory) CacheCommandFactory(org.hibernate.cache.infinispan.util.CacheCommandFactory) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with GlobalComponentRegistry

use of org.infinispan.factories.GlobalComponentRegistry in project keycloak by keycloak.

the class InfinispanUtil method replaceComponent.

/**
 * Forked from org.infinispan.test.TestingUtil class
 *
 * Replaces a component in a running cache manager (global component registry).
 *
 * @param cacheMgr       cache in which to replace component
 * @param componentType        component type of which to replace
 * @param replacementComponent new instance
 * @param rewire               if true, ComponentRegistry.rewire() is called after replacing.
 *
 * @return the original component that was replaced
 */
private static <T> T replaceComponent(EmbeddedCacheManager cacheMgr, Class<T> componentType, T replacementComponent, boolean rewire) {
    GlobalComponentRegistry cr = cacheMgr.getGlobalComponentRegistry();
    BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
    ComponentRef<T> old = bcr.getComponent(componentType);
    bcr.replaceComponent(componentType.getName(), 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 14 with GlobalComponentRegistry

use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.

the class DefaultCacheManager method wireAndStartCache.

/**
 * @return a null return value means the cache was created by someone else before we got the lock
 */
private <K, V> Cache<K, V> wireAndStartCache(String cacheName) {
    Configuration c = configurationManager.getConfiguration(cacheName);
    if (c == null) {
        throw CONFIG.noSuchCacheConfiguration(cacheName);
    }
    if (c.security().authorization().enabled()) {
        // Don't even attempt to wire anything if we don't have LIFECYCLE privileges
        authorizer.checkPermission(c.security().authorization(), getSubject(), AuthorizationPermission.LIFECYCLE, null);
    }
    if (c.isTemplate()) {
        throw CONFIG.templateConfigurationStartAttempt(cacheName);
    }
    CompletableFuture<Cache<?, ?>> cacheFuture = new CompletableFuture<>();
    CompletableFuture<Cache<?, ?>> oldFuture = caches.computeIfAbsent(cacheName, name -> {
        assertIsNotTerminated();
        return cacheFuture;
    });
    Cache<K, V> cache = null;
    try {
        if (oldFuture != cacheFuture) {
            cache = (Cache<K, V>) oldFuture.join();
            if (!cache.getStatus().isTerminated()) {
                return cache;
            }
        }
    } catch (CompletionException ce) {
        throw ((CacheException) ce.getCause());
    }
    try {
        log.debugf("Creating cache %s on %s", cacheName, identifierString());
        if (cache == null) {
            cache = new InternalCacheFactory<K, V>().createCache(c, globalComponentRegistry, cacheName);
            if (cache.getAdvancedCache().getAuthorizationManager() != null) {
                cache = new SecureCacheImpl<>(cache.getAdvancedCache());
            }
        }
        ComponentRegistry cr = SecurityActions.getUnwrappedCache(cache).getAdvancedCache().getComponentRegistry();
        boolean notStartedYet = cr.getStatus() != ComponentStatus.RUNNING && cr.getStatus() != ComponentStatus.INITIALIZING;
        // start the cache-level components
        cache.start();
        cacheFuture.complete(cache);
        boolean needToNotifyCacheStarted = notStartedYet && cr.getStatus() == ComponentStatus.RUNNING;
        if (needToNotifyCacheStarted) {
            globalComponentRegistry.notifyCacheStarted(cacheName);
        }
        log.tracef("Cache %s is ready", cacheName);
        return cache;
    } catch (CacheException e) {
        cacheFuture.completeExceptionally(e);
        throw e;
    } catch (Throwable t) {
        cacheFuture.completeExceptionally(new CacheException(t));
        throw t;
    }
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) GlobalAuthorizationConfiguration(org.infinispan.configuration.global.GlobalAuthorizationConfiguration) TransportConfiguration(org.infinispan.configuration.global.TransportConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) CacheException(org.infinispan.commons.CacheException) CompletableFuture(java.util.concurrent.CompletableFuture) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) CompletionException(java.util.concurrent.CompletionException) InternalCacheFactory(org.infinispan.factories.InternalCacheFactory) Cache(org.infinispan.Cache)

Example 15 with GlobalComponentRegistry

use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.

the class ClusterPermissionMapper method setContext.

@Override
public void setContext(AuthorizationMapperContext context) {
    this.cacheManager = context.getCacheManager();
    GlobalConfiguration globalConfiguration = SecurityActions.getCacheManagerConfiguration(cacheManager);
    CacheMode cacheMode = globalConfiguration.isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL;
    ConfigurationBuilder cfg = new ConfigurationBuilder();
    cfg.clustering().cacheMode(cacheMode).stateTransfer().fetchInMemoryState(true).awaitInitialTransfer(false).security().authorization().disable();
    GlobalComponentRegistry gcr = SecurityActions.getGlobalComponentRegistry(cacheManager);
    InternalCacheRegistry internalCacheRegistry = gcr.getComponent(InternalCacheRegistry.class);
    internalCacheRegistry.registerInternalCache(CLUSTER_PERMISSION_MAPPER_CACHE, cfg.build(), EnumSet.of(InternalCacheRegistry.Flag.PERSISTENT));
    gcr.registerComponent(this, RolePermissionMapper.class);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) CacheMode(org.infinispan.configuration.cache.CacheMode) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry)

Aggregations

GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)26 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)7 ComponentRegistry (org.infinispan.factories.ComponentRegistry)7 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)7 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)7 ConfigurationManager (org.infinispan.configuration.ConfigurationManager)5 Cache (org.infinispan.Cache)4 CacheException (org.infinispan.commons.CacheException)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 Transport (org.infinispan.remoting.transport.Transport)4 CacheMode (org.infinispan.configuration.cache.CacheMode)3 Configuration (org.infinispan.configuration.cache.Configuration)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 ModuleLifecycle (org.infinispan.lifecycle.ModuleLifecycle)3 JGroupsTransport (org.infinispan.remoting.transport.jgroups.JGroupsTransport)3 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 AdvancedCache (org.infinispan.AdvancedCache)2