public CodecRegistry(EmbeddedCacheManager cacheManager) { GlobalConfiguration globalConfiguration = cacheManager.getCacheManagerConfiguration(); ClassLoader cl = globalConfiguration.classLoader(); ClassWhiteList classWhiteList = cacheManager.getClassWhiteList(); codecs = new HashMap<>(); Iterator<Codec> it = ServiceFinder.load(Codec.class, cl).iterator(); for (; ; ) { try { Codec codec = it.next(); codec.setWhiteList(classWhiteList); String name = codec.getName(); if (codecs.containsKey(name)) { log.duplicateCodec(codec.getClass().getName(), codecs.get(name).getClass().getName()); } else { codecs.put(name, codec); } } catch (ServiceConfigurationError e) { log.loadingCodecFailed(e); } catch (NoSuchElementException e) { break; } } }
void addRegexWhiteList(String regex) { cacheManager.getClassWhiteList().addRegexps(regex); }
@Override protected void createCacheManagers() { super.createCacheManagers(); cacheManagers.forEach(cm -> { cm.getClassWhiteList().addRegexps("org.infinispan.rest.search.entity.*"); }); }
@Override public void call() { Cache<String, Person> cache = cm.getCache(); cm.getClassWhiteList().addClasses(Person.class); // Obtain cache with custom valueEncoder Cache storeMarshalled = cache.getAdvancedCache().withEncoding(JavaSerializationEncoder.class); // Add a listener SimpleListener simpleListener = new SimpleListener(); storeMarshalled.addListener(simpleListener); Person value = new Person(); storeMarshalled.put("1", value); // Assert values returned are passed through the valueEncoder assertEquals(simpleListener.events.size(), 1); assertEquals(simpleListener.events.get(0).getKey(), "1"); assertEquals(simpleListener.events.get(0).getValue(), value); } });
@Override public void call() { cm.getClassWhiteList().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); } });
@Override public void call() throws IOException, InterruptedException { cm.getClassWhiteList().addClasses(Person.class); Cache<String, Person> cache = cm.getCache(); Marshaller marshaller = cache.getAdvancedCache().getComponentRegistry().getCacheMarshaller(); Person value = new Person(); cache.put("1", value); // Read using default valueEncoder assertEquals(cache.get("1"), value); // Read unencoded Cache<?, ?> unencodedCache = cache.getAdvancedCache().withEncoding(IdentityEncoder.class); assertEquals(unencodedCache.get(marshaller.objectToByteBuffer("1")), marshaller.objectToByteBuffer(value)); } });
@BeforeClass protected void setup() throws Exception { cacheManager = TestCacheManagerFactory.createServerModeCacheManager(); ClassWhiteList classWhiteList = cacheManager.getClassWhiteList(); classWhiteList.addRegexps(".*"); cacheManager.defineConfiguration(CACHE_NAME, getIndexCacheConfiguration().build()); RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder(); int restPort = findFreePort(); builder.port(restPort); restServer = new RestServer(); restServer.start(builder.build(), cacheManager); restClient = new HttpClient(); hotRodServer = startHotRodServer(cacheManager); remoteCacheManager = createRemoteCacheManager(); remoteCache = remoteCacheManager.getCache(CACHE_NAME); restEndpoint = String.format("http://localhost:%s/rest/%s", restServer.getPort(), CACHE_NAME); }
@Override protected void createCacheManagers() throws Exception { GlobalConfigurationBuilder globalBuilder = new GlobalConfigurationBuilder(); globalBuilder.addModule(PrivateGlobalConfigurationBuilder.class).serverMode(true); GlobalConfigurationBuilder globalConfiguration = globalBuilder.clusteredDefault(); createCluster(globalConfiguration, getDefaultCacheBuilder(), NUM_SERVERS); for (EmbeddedCacheManager cm : cacheManagers) { this.defineCaches(cm); String[] cacheNames = cm.getCacheNames().toArray(new String[0]); cm.startCaches(cacheNames); cm.getClassWhiteList().addClasses(TestClass.class); waitForClusterToForm(cacheNames); RestServerHelper restServerHelper = new RestServerHelper(cm); restServerHelper.start(TestResourceTracker.getCurrentTestShortName()); restServers.add(restServerHelper); } client = new HttpClient(); client.start(); }