Search in sources :

Example 6 with GlobalComponentRegistry

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

the class TestingUtil method replaceComponent.

/**
 * Same as {@link TestingUtil#replaceComponent(CacheContainer, Class, Object, boolean)} except that you can provide
 * an optional name, to replace specifically named components.
 *
 * @param cacheContainer       cache in which to replace component
 * @param componentType        component type of which to replace
 * @param name                 name of the component
 * @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(CacheContainer cacheContainer, Class<T> componentType, String name, T replacementComponent, boolean rewire) {
    GlobalComponentRegistry cr = extractGlobalComponentRegistry(cacheContainer);
    BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
    ComponentRef<T> old = bcr.getComponent(componentType);
    bcr.replaceComponent(name, 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 7 with GlobalComponentRegistry

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

the class DataConversionTest method testObjectEncoder.

@Test
public void testObjectEncoder() {
    GenericJbossMarshallerEncoder encoder = new GenericJbossMarshallerEncoder(org.infinispan.dataconversion.DataConversionTest.class.getClassLoader());
    withCacheManager(new CacheManagerCallable(createCacheManager(new ConfigurationBuilder())) {

        GenericJBossMarshaller marshaller = new GenericJBossMarshaller();

        private byte[] marshall(Object o) {
            try {
                return marshaller.objectToByteBuffer(o);
            } catch (IOException | InterruptedException e) {
                throw new AssertionError("Cannot marshall content", e);
            }
        }

        @Override
        public void call() {
            GlobalComponentRegistry registry = cm.getGlobalComponentRegistry();
            EncoderRegistry encoderRegistry = registry.getComponent(EncoderRegistry.class);
            encoderRegistry.registerEncoder(encoder);
            cm.getClassAllowList().addClasses(Person.class);
            Cache<byte[], byte[]> cache = cm.getCache();
            // Write encoded content to the cache
            Person key1 = new Person("key1");
            Person value1 = new Person("value1");
            byte[] encodedKey1 = marshall(key1);
            byte[] encodedValue1 = marshall(value1);
            cache.put(encodedKey1, encodedValue1);
            // Read encoded content
            assertEquals(cache.get(encodedKey1), encodedValue1);
            // Read with a different valueEncoder
            AdvancedCache<Person, Person> encodingCache = (AdvancedCache<Person, Person>) cache.getAdvancedCache().withEncoding(GenericJbossMarshallerEncoder.class);
            assertEquals(encodingCache.get(key1), value1);
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) AdvancedCache(org.infinispan.AdvancedCache) Person(org.infinispan.test.data.Person) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache) Test(org.testng.annotations.Test)

Example 8 with GlobalComponentRegistry

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

the class DistributedServerTask method apply.

@Override
public T apply(EmbeddedCacheManager embeddedCacheManager) {
    Cache<Object, Object> cache = embeddedCacheManager.getCache(cacheName);
    // todo inject global component registry to be independent of existence of cache.
    GlobalComponentRegistry componentRegistry = SecurityActions.getGlobalComponentRegistry(embeddedCacheManager);
    ServerTaskEngine serverTaskEngine = componentRegistry.getComponent(ServerTaskEngine.class);
    Marshaller marshaller = componentRegistry.getComponent(StreamingMarshaller.class);
    ServerTaskWrapper<T> task = serverTaskEngine.getTask(taskName);
    task.inject(prepareContext(embeddedCacheManager, cache, marshaller));
    try {
        return task.run();
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
Also used : StreamingMarshaller(org.infinispan.commons.marshall.StreamingMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) CacheException(org.infinispan.commons.CacheException) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) CacheException(org.infinispan.commons.CacheException)

Example 9 with GlobalComponentRegistry

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

the class CheckAddressTask method startInternal.

@Override
protected void startInternal() {
    GlobalComponentRegistry gcr = SecurityActions.getGlobalComponentRegistry(cacheManager);
    this.iterationManager = new DefaultIterationManager(gcr.getTimeService());
    this.hasDefaultCache = configuration.defaultCacheName() != null || cacheManager.getCacheManagerConfiguration().defaultCacheName().isPresent();
    // Initialize query-specific stuff
    queryFacade = loadQueryFacade();
    clientListenerRegistry = new ClientListenerRegistry(gcr.getComponent(EncoderRegistry.class), gcr.getComponent(ExecutorService.class, NON_BLOCKING_EXECUTOR));
    clientCounterNotificationManager = new ClientCounterManagerNotificationManager(asCounterManager(cacheManager));
    addKeyValueFilterConverterFactory(ToEmptyBytesKeyValueFilterConverter.class.getName(), new ToEmptyBytesFactory());
    addCacheEventConverterFactory("key-value-with-previous-converter-factory", new KeyValueWithPreviousEventConverterFactory());
    addCacheEventConverterFactory("___eager-key-value-version-converter", KeyValueVersionConverterFactory.SINGLETON);
    loadFilterConverterFactories(ParamKeyValueFilterConverterFactory.class, this::addKeyValueFilterConverterFactory);
    loadFilterConverterFactories(CacheEventFilterConverterFactory.class, this::addCacheEventFilterConverterFactory);
    loadFilterConverterFactories(CacheEventConverterFactory.class, this::addCacheEventConverterFactory);
    loadFilterConverterFactories(KeyValueFilterConverterFactory.class, this::addKeyValueFilterConverterFactory);
    DefaultThreadFactory factory = new DefaultThreadFactory(getQualifiedName() + "-Scheduled");
    scheduledExecutor = Executors.newSingleThreadScheduledExecutor(factory);
    removeCacheListener = new RemoveCacheListener();
    SecurityActions.addListener(cacheManager, removeCacheListener);
    // Start default cache and the endpoint before adding self to
    // topology in order to avoid topology updates being used before
    // endpoint is available.
    super.startInternal();
    // Add self to topology cache last, after everything is initialized
    if (Configurations.isClustered(SecurityActions.getCacheManagerConfiguration(cacheManager))) {
        defineTopologyCacheConfig(cacheManager);
        if (log.isDebugEnabled())
            log.debugf("Externally facing address is %s:%d", configuration.proxyHost(), configuration.proxyPort());
        addSelfToTopologyView(cacheManager);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultIterationManager(org.infinispan.server.hotrod.iteration.DefaultIterationManager) ClientCounterManagerNotificationManager(org.infinispan.server.hotrod.counter.listener.ClientCounterManagerNotificationManager) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) KeyValueWithPreviousEventConverterFactory(org.infinispan.server.hotrod.event.KeyValueWithPreviousEventConverterFactory)

Example 10 with GlobalComponentRegistry

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

the class BackupReader method restoreContainer.

private CompletionStage<Void> restoreContainer(String containerName, BackupManager.Resources params, ZipFile zip) {
    // TODO validate container config
    EmbeddedCacheManager cm = cacheManagers.get(containerName);
    GlobalComponentRegistry gcr = SecurityActions.getGlobalComponentRegistry(cm);
    Path containerRoot = Paths.get(CONTAINER_KEY, containerName);
    Properties properties = readProperties(containerRoot.resolve(CONTAINERS_PROPERTIES_FILE), zip);
    Collection<ContainerResource> resources = ContainerResourceFactory.getResources(params, blockingManager, cm, gcr, parserRegistry, containerRoot);
    resources.forEach(r -> r.prepareAndValidateRestore(properties));
    AggregateCompletionStage<Void> stages = CompletionStages.aggregateCompletionStage();
    for (ContainerResource cr : resources) stages.dependsOn(cr.restore(zip));
    return stages.freeze();
}
Also used : Path(java.nio.file.Path) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Properties(java.util.Properties)

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