Search in sources :

Example 11 with BasicComponentRegistry

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();
        }
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) EntityLoader(org.infinispan.query.impl.EntityLoader) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) KeyTransformationHandler(org.infinispan.query.backend.KeyTransformationHandler) LocalQueryStatistics(org.infinispan.query.core.stats.impl.LocalQueryStatistics) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache)

Example 12 with BasicComponentRegistry

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

Example 13 with BasicComponentRegistry

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

Example 14 with BasicComponentRegistry

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);
}
Also used : RollingUpgradeManager(org.infinispan.upgrade.RollingUpgradeManager) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) CacheJmxRegistration(org.infinispan.jmx.CacheJmxRegistration) RecoveryAdminOperations(org.infinispan.transaction.xa.recovery.RecoveryAdminOperations) AbstractDelegatingAdvancedCache(org.infinispan.cache.impl.AbstractDelegatingAdvancedCache) AdvancedCache(org.infinispan.AdvancedCache) CacheMetricsRegistration(org.infinispan.metrics.impl.CacheMetricsRegistration) XSiteAdminOperations(org.infinispan.xsite.XSiteAdminOperations) Cache(org.infinispan.Cache) StatsCollectingCache(org.infinispan.cache.impl.StatsCollectingCache) AbstractDelegatingAdvancedCache(org.infinispan.cache.impl.AbstractDelegatingAdvancedCache) AdvancedCache(org.infinispan.AdvancedCache) EncoderCache(org.infinispan.cache.impl.EncoderCache)

Example 15 with BasicComponentRegistry

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

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