Search in sources :

Example 1 with GenericJBossMarshaller

use of org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller in project infinispan by infinispan.

the class JBMARRemoteQueryDslConditionsTest method createCacheManagers.

@Override
protected void createCacheManagers() {
    GlobalConfigurationBuilder globalCfg = GlobalConfigurationBuilder.defaultClusteredBuilder();
    globalCfg.serialization().marshaller(new GenericJBossMarshaller());
    ConfigurationBuilder cfg = getConfigurationBuilder();
    createClusteredCaches(1, globalCfg, cfg, true);
    cache = manager(0).getCache();
    hotRodServer = HotRodClientTestingUtil.startHotRodServer(manager(0));
    org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = HotRodClientTestingUtil.newRemoteConfigurationBuilder();
    clientBuilder.addServer().host("127.0.0.1").port(hotRodServer.getPort());
    clientBuilder.version(getProtocolVersion());
    clientBuilder.marshaller(new GenericJBossMarshaller());
    remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
    remoteCache = remoteCacheManager.getCache();
    cacheManagers.forEach(c -> c.getClassAllowList().addRegexps(".*"));
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) HotRodClientTestingUtil.killRemoteCacheManager(org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager)

Example 2 with GenericJBossMarshaller

use of org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller in project infinispan by infinispan.

the class JbossMarshallingModule method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    PERSISTENCE.jbossMarshallingDetected();
    Marshaller userMarshaller = globalConfiguration.serialization().marshaller();
    if (userMarshaller instanceof JBossUserMarshaller) {
        // Core automatically registers a transcoder for the user marshaller
        // Initialize the externalizers from the serialization configuration
        ((JBossUserMarshaller) userMarshaller).initialize(gcr);
    } else {
        // Register a JBoss Marshalling transcoder, ignoring any configured externalizers
        ClassAllowList classAllowList = gcr.getComponent(EmbeddedCacheManager.class).getClassAllowList();
        ClassLoader classLoader = globalConfiguration.classLoader();
        GenericJBossMarshaller jbossMarshaller = new GenericJBossMarshaller(classLoader, classAllowList);
        EncoderRegistry encoderRegistry = gcr.getComponent(EncoderRegistry.class);
        encoderRegistry.registerTranscoder(new JBossMarshallingTranscoder(jbossMarshaller));
    }
}
Also used : GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) JBossUserMarshaller(org.infinispan.jboss.marshalling.core.JBossUserMarshaller) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) JBossMarshallingTranscoder(org.infinispan.jboss.marshalling.dataconversion.JBossMarshallingTranscoder) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) JBossUserMarshaller(org.infinispan.jboss.marshalling.core.JBossUserMarshaller)

Example 3 with GenericJBossMarshaller

use of org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller 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 4 with GenericJBossMarshaller

use of org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller in project infinispan by infinispan.

the class HotRodUpgradeSynchronizerTest method doWhenSourceIterationReaches.

private void doWhenSourceIterationReaches(String key, TestCluster cluster, String cacheName, IterationCallBack callback) {
    cluster.getEmbeddedCaches(cacheName).forEach(c -> {
        PersistenceManager pm = extractComponent(c, PersistenceManager.class);
        RemoteStore remoteStore = pm.getStores(RemoteStore.class).iterator().next();
        RemoteCacheImpl remoteCache = TestingUtil.extractField(remoteStore, "remoteCache");
        RemoteCacheImpl spy = spy(remoteCache);
        doAnswer(invocation -> {
            Object[] params = invocation.getArguments();
            CloseableIterator<Map.Entry<Object, Object>> iterator = remoteCache.retrieveEntriesWithMetadata((Set<Integer>) params[0], (int) params[1]);
            Marshaller marshaller = new GenericJBossMarshaller();
            return new IteratorMapper<>(iterator, entry -> {
                try {
                    if (key.equals(marshaller.objectFromByteBuffer((byte[]) entry.getKey()))) {
                        callback.iterationReached(key);
                    }
                } catch (IOException | ClassNotFoundException ex) {
                    throw new RuntimeException(ex);
                }
                return entry;
            });
        }).when(spy).retrieveEntriesWithMetadata(anySet(), anyInt());
        TestingUtil.replaceField(spy, "remoteCache", remoteStore, RemoteStore.class);
    });
}
Also used : GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) IOException(java.io.IOException) RemoteStore(org.infinispan.persistence.remote.RemoteStore) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) IteratorMapper(org.infinispan.commons.util.IteratorMapper) RemoteCacheImpl(org.infinispan.client.hotrod.impl.RemoteCacheImpl)

Example 5 with GenericJBossMarshaller

use of org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller in project keycloak by keycloak.

the class HotRodServerRule method createEmbeddedHotRodServer.

public void createEmbeddedHotRodServer(Config.Scope config) {
    try {
        hotRodCacheManager = new DefaultCacheManager("hotrod/hotrod1.xml");
        hotRodCacheManager2 = new DefaultCacheManager("hotrod/hotrod2.xml");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    HotRodServerConfiguration build = new HotRodServerConfigurationBuilder().build();
    hotRodServer = new HotRodServer();
    hotRodServer.start(build, hotRodCacheManager);
    HotRodServerConfiguration build2 = new HotRodServerConfigurationBuilder().port(11333).build();
    hotRodServer2 = new HotRodServer();
    hotRodServer2.start(build2, hotRodCacheManager2);
    // Create a Hot Rod client
    org.infinispan.client.hotrod.configuration.ConfigurationBuilder remoteBuilder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
    remoteBuilder.marshaller(new GenericJBossMarshaller());
    org.infinispan.client.hotrod.configuration.Configuration cfg = remoteBuilder.addServers(hotRodServer.getHost() + ":" + hotRodServer.getPort() + ";" + hotRodServer2.getHost() + ":" + hotRodServer2.getPort()).build();
    remoteCacheManager = new RemoteCacheManager(cfg);
    boolean async = config.getBoolean("async", false);
    // create remote keycloak caches
    createKeycloakCaches(async, USER_SESSION_CACHE_NAME, OFFLINE_USER_SESSION_CACHE_NAME, CLIENT_SESSION_CACHE_NAME, OFFLINE_CLIENT_SESSION_CACHE_NAME, LOGIN_FAILURE_CACHE_NAME, WORK_CACHE_NAME, ACTION_TOKEN_CACHE);
    getCaches(USER_SESSION_CACHE_NAME, OFFLINE_USER_SESSION_CACHE_NAME, CLIENT_SESSION_CACHE_NAME, OFFLINE_CLIENT_SESSION_CACHE_NAME, LOGIN_FAILURE_CACHE_NAME, WORK_CACHE_NAME, ACTION_TOKEN_CACHE);
    // Use Keycloak time service in remote caches
    InfinispanUtil.setTimeServiceToKeycloakTime(hotRodCacheManager);
    InfinispanUtil.setTimeServiceToKeycloakTime(hotRodCacheManager2);
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) HotRodServerConfiguration(org.infinispan.server.hotrod.configuration.HotRodServerConfiguration) IOException(java.io.IOException) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) HotRodServer(org.infinispan.server.hotrod.HotRodServer) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)

Aggregations

GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)7 Marshaller (org.infinispan.commons.marshall.Marshaller)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)2 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)2 DelegatingUserMarshaller (org.infinispan.marshall.core.impl.DelegatingUserMarshaller)2 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)2 Infinispan8Marshaller (org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller)2 Infinispan9Marshaller (org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller)2 AdvancedCache (org.infinispan.AdvancedCache)1 Cache (org.infinispan.Cache)1 RemoteCacheImpl (org.infinispan.client.hotrod.impl.RemoteCacheImpl)1 HotRodClientTestingUtil.killRemoteCacheManager (org.infinispan.client.hotrod.test.HotRodClientTestingUtil.killRemoteCacheManager)1 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)1 IteratorMapper (org.infinispan.commons.util.IteratorMapper)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)1 JBossUserMarshaller (org.infinispan.jboss.marshalling.core.JBossUserMarshaller)1