use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class LifecycleManager method cacheStarting.
/**
* Registers the interceptor in the ___protobuf_metadata cache before it gets started. Also creates query components
* for user caches.
*/
@Override
public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
BasicComponentRegistry gcr = cr.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class);
LocalQueryStatistics queryStatistics = cr.getComponent(LocalQueryStatistics.class);
if (PROTOBUF_METADATA_CACHE_NAME.equals(cacheName)) {
// a protobuf metadata cache is starting, need to register the interceptor
ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
protobufMetadataManager.addProtobufMetadataManagerInterceptor(cr.getComponent(BasicComponentRegistry.class));
}
InternalCacheRegistry icr = gcr.getComponent(InternalCacheRegistry.class).running();
if (!icr.isInternalCache(cacheName)) {
// a stop dependency must be added for each non-internal cache
ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
protobufMetadataManager.addCacheDependency(cacheName);
// a remote query manager must be added for each non-internal cache
SerializationContext serCtx = protobufMetadataManager.getSerializationContext();
RemoteQueryManager remoteQueryManager = buildQueryManager(cfg, serCtx, cr);
cr.registerComponent(remoteQueryManager, RemoteQueryManager.class);
SearchMappingCommonBuilding commonBuilding = cr.getComponent(SearchMappingCommonBuilding.class);
SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
if (commonBuilding != null && searchMapping == null) {
AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache().withStorageMediaType().withWrapping(ByteArrayWrapper.class, ProtobufWrapper.class);
KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils.getKeyTransformationHandler(cache);
EntityLoader<?> entityLoader = new EntityLoader<>(queryStatistics, cache, keyTransformationHandler);
searchMapping = new LazySearchMapping(commonBuilding, entityLoader, serCtx, cache, protobufMetadataManager);
cr.registerComponent(searchMapping, SearchMapping.class);
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
bcr.replaceComponent(IndexStatistics.class.getName(), new LocalIndexStatistics(), true);
bcr.rewire();
}
}
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class LifecycleManager method cacheManagerStarted.
@Override
public void cacheManagerStarted(GlobalComponentRegistry gcr) {
BasicComponentRegistry bcr = gcr.getComponent(BasicComponentRegistry.class);
ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) bcr.getComponent(ProtobufMetadataManager.class).running();
// if not already running, start it
protobufMetadataManager.getCache();
GlobalConfiguration globalCfg = gcr.getGlobalConfiguration();
if (globalCfg.jmx().enabled()) {
registerProtobufMetadataManagerMBean(protobufMetadataManager, globalCfg, bcr);
}
}
use of org.infinispan.factories.impl.BasicComponentRegistry 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.impl.BasicComponentRegistry in project infinispan by infinispan.
the class InternalCacheFactory method bootstrap.
/**
* Bootstraps this factory with a Configuration and a ComponentRegistry.
*/
private void bootstrap(String cacheName, AdvancedCache<?, ?> cache, Configuration configuration, GlobalComponentRegistry globalComponentRegistry, StreamingMarshaller globalMarshaller) {
// injection bootstrap stuff
componentRegistry = new ComponentRegistry(cacheName, configuration, cache, globalComponentRegistry, globalComponentRegistry.getClassLoader());
/*
--------------------------------------------------------------------------------------------------------------
This is where the bootstrap really happens. Registering the cache in the component registry will cause
the component registry to look at the cache's @Inject methods, and construct various components and their
dependencies, in turn.
--------------------------------------------------------------------------------------------------------------
*/
basicComponentRegistry = componentRegistry.getComponent(BasicComponentRegistry.class);
basicComponentRegistry.registerAlias(Cache.class.getName(), AdvancedCache.class.getName(), AdvancedCache.class);
basicComponentRegistry.registerComponent(AdvancedCache.class.getName(), cache, false);
componentRegistry.registerComponent(new CacheJmxRegistration(), CacheJmxRegistration.class.getName(), true);
componentRegistry.registerComponent(new CacheMetricsRegistration(), CacheMetricsRegistration.class.getName(), true);
if (configuration.transaction().recovery().enabled()) {
componentRegistry.registerComponent(new RecoveryAdminOperations(), RecoveryAdminOperations.class.getName(), true);
}
if (configuration.sites().hasBackups()) {
componentRegistry.registerComponent(new XSiteAdminOperations(), XSiteAdminOperations.class.getName(), true);
}
// The RollingUpgradeManager should always be added so it is registered in JMX.
componentRegistry.registerComponent(new RollingUpgradeManager(), RollingUpgradeManager.class.getName(), true);
}
use of org.infinispan.factories.impl.BasicComponentRegistry in project infinispan by infinispan.
the class TestingUtil method replaceComponent.
/**
* Replaces a component in a running cache
*
* @param cache 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
*/
public static <T> T replaceComponent(Cache<?, ?> cache, Class<? extends T> componentType, T replacementComponent, boolean rewire) {
if (componentType.equals(DataContainer.class)) {
throw new UnsupportedOperationException();
}
ComponentRegistry cr = extractComponentRegistry(cache);
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
ComponentRef<? extends T> old = bcr.getComponent(componentType);
bcr.replaceComponent(componentType.getName(), replacementComponent, true);
cr.cacheComponents();
if (rewire)
cr.rewire();
return old != null ? old.wired() : null;
}
Aggregations