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(".*"));
}
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));
}
}
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);
}
});
}
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);
});
}
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);
}
Aggregations