Search in sources :

Example 1 with InternalCacheRegistry

use of org.infinispan.registry.InternalCacheRegistry in project infinispan by infinispan.

the class ClusterRoleMapper method setContext.

@Override
public void setContext(PrincipalRoleMapperContext 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 registry = SecurityActions.getGlobalComponentRegistry(cacheManager);
    InternalCacheRegistry internalCacheRegistry = registry.getComponent(InternalCacheRegistry.class);
    internalCacheRegistry.registerInternalCache(CLUSTER_ROLE_MAPPER_CACHE, cfg.build(), EnumSet.of(InternalCacheRegistry.Flag.PERSISTENT));
    registry.registerComponent(this, PrincipalRoleMapper.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)

Example 2 with InternalCacheRegistry

use of org.infinispan.registry.InternalCacheRegistry in project infinispan by infinispan.

the class DefaultCacheManager method getCacheNames.

@Override
public Set<String> getCacheNames() {
    // Get the XML/programmatically defined caches
    Set<String> names = new HashSet<>(configurationManager.getDefinedCaches());
    // Add the caches created dynamically without explicit config
    names.addAll(caches.keySet());
    InternalCacheRegistry internalCacheRegistry = globalComponentRegistry.getComponent(InternalCacheRegistry.class);
    internalCacheRegistry.filterPrivateCaches(names);
    if (names.isEmpty())
        return Collections.emptySet();
    else
        return Immutables.immutableSetWrap(names);
}
Also used : InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with InternalCacheRegistry

use of org.infinispan.registry.InternalCacheRegistry in project infinispan by infinispan.

the class CounterModuleLifecycle method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    final Map<Integer, AdvancedExternalizer<?>> externalizerMap = globalConfiguration.serialization().advancedExternalizers();
    // Only required by GlobalMarshaller
    addAdvancedExternalizer(externalizerMap, ResetFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, ReadFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, InitializeCounterFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, AddFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CompareAndSwapFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CreateAndCASFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CreateAndAddFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, RemoveFunction.EXTERNALIZER);
    BasicComponentRegistry bcr = gcr.getComponent(BasicComponentRegistry.class);
    EmbeddedCacheManager cacheManager = bcr.getComponent(EmbeddedCacheManager.class).wired();
    InternalCacheRegistry internalCacheRegistry = bcr.getComponent(InternalCacheRegistry.class).running();
    SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, new PersistenceContextInitializerImpl());
    CounterManagerConfiguration counterManagerConfiguration = extractConfiguration(globalConfiguration);
    if (gcr.getGlobalConfiguration().isClustered()) {
        // only attempts to create the caches if the cache manager is clustered.
        registerCounterCache(internalCacheRegistry, counterManagerConfiguration);
    } else {
        // local only cache manager.
        registerLocalCounterCache(internalCacheRegistry);
    }
    registerCounterNotificationManager(bcr);
    registerCounterManager(cacheManager, bcr, globalConfiguration);
}
Also used : BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) PersistenceContextInitializerImpl(org.infinispan.counter.impl.persistence.PersistenceContextInitializerImpl) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Example 4 with InternalCacheRegistry

use of org.infinispan.registry.InternalCacheRegistry in project infinispan by infinispan.

the class HotRodSingleClusteredTest method testLoopbackPutOnProtectedCache.

public void testLoopbackPutOnProtectedCache(Method m) {
    InternalCacheRegistry internalCacheRegistry = manager(0).getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class);
    internalCacheRegistry.registerInternalCache("MyInternalCache", hotRodCacheConfiguration().build(), EnumSet.of(InternalCacheRegistry.Flag.USER, InternalCacheRegistry.Flag.PROTECTED));
    TestResponse resp = hotRodClient.execute(0xA0, (byte) 0x01, "MyInternalCache", k(m), 0, 0, v(m), 0, (byte) 1, 0);
    assertEquals(Success, resp.status);
}
Also used : TestResponse(org.infinispan.server.hotrod.test.TestResponse) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry)

Example 5 with InternalCacheRegistry

use of org.infinispan.registry.InternalCacheRegistry in project infinispan by infinispan.

the class CheckAddressTask method checkCacheIsAvailable.

private boolean checkCacheIsAvailable(String cacheName, byte hotRodVersion, long messageId) {
    InternalCacheRegistry icr = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(InternalCacheRegistry.class);
    boolean keep;
    if (icr.isPrivateCache(cacheName)) {
        throw new RequestParsingException(String.format("Remote requests are not allowed to private caches. Do no send remote requests to cache '%s'", cacheName), hotRodVersion, messageId);
    } else if (icr.internalCacheHasFlag(cacheName, InternalCacheRegistry.Flag.PROTECTED)) {
        // We want to make sure the cache access is checked every time, so don't store it as a "known" cache.
        // More expensive, but these caches should not be accessed frequently
        keep = false;
    } else if (!cacheName.isEmpty() && !cacheManager.getCacheNames().contains(cacheName)) {
        throw new CacheNotFoundException(String.format("Cache with name '%s' not found amongst the configured caches", cacheName), hotRodVersion, messageId);
    } else if (cacheName.isEmpty() && !hasDefaultCache) {
        throw new CacheNotFoundException("Default cache requested but not configured", hotRodVersion, messageId);
    } else {
        keep = true;
    }
    return keep;
}
Also used : InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry)

Aggregations

InternalCacheRegistry (org.infinispan.registry.InternalCacheRegistry)20 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)5 AdvancedCache (org.infinispan.AdvancedCache)4 Cache (org.infinispan.Cache)4 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 SerializationContextRegistry (org.infinispan.marshall.protostream.impl.SerializationContextRegistry)3 LocalQueryStatistics (org.infinispan.query.core.stats.impl.LocalQueryStatistics)3 AdvancedExternalizer (org.infinispan.commons.marshall.AdvancedExternalizer)2 AggregatedClassLoader (org.infinispan.commons.util.AggregatedClassLoader)2 CacheMode (org.infinispan.configuration.cache.CacheMode)2 Configuration (org.infinispan.configuration.cache.Configuration)2 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)2 ReflectionEntityNamesResolver (org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver)2 KeyTransformationHandler (org.infinispan.query.backend.KeyTransformationHandler)2 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)2 LocalIndexStatistics (org.infinispan.query.stats.impl.LocalIndexStatistics)2 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)2 TestResponse (org.infinispan.server.hotrod.test.TestResponse)2