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);
}
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();
}
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;
}
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;
}
}
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);
}
Aggregations