builder.serialization().classResolver(ModularClassResolver.getInstance(this.loader.get())); builder.classLoader(module.getClassLoader()); int id = Ids.MAX_ID; SerializationConfigurationBuilder serialization = builder.serialization(); for (Externalizer<?> externalizer : EnumSet.allOf(DefaultExternalizer.class)) { serialization.addAdvancedExternalizer(new AdvancedExternalizerAdapter<>(id++, externalizer));
/** * Do not rely on automatic discovery but enforce the registration of the required Externalizers. */ private void forceExternalizerRegistration(ConfigurationBuilderHolder configurationBuilderHolder) { SerializationConfigurationBuilder serialization = configurationBuilderHolder .getGlobalConfigurationBuilder() .serialization(); LifecycleCallbacks.moduleExternalizers().forEach( (i, e) -> serialization.addAdvancedExternalizer( i, e ) ); }
public static void amendMarshaller(GlobalConfigurationBuilder builder) { if (MARSHALLER != null) { try { Marshaller marshaller = Util.getInstanceStrict(MARSHALLER, Thread.currentThread().getContextClassLoader()); builder.serialization().marshaller(marshaller); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // No-op, stick to GlobalConfiguration default. } } }
ConfigurationBuilderHolder holder = parser.parseFile(infinispanConfigFile); GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder(); globalBuilder.serialization() .classResolver(new ClassResolver()) .build();
private GlobalConfigurationBuilder createMultiForeignExternalizerGlobalConfig(int id, boolean doSetId) { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); if (doSetId) builder.serialization().addAdvancedExternalizer(id, new IdViaConfigObj.Externalizer()); else builder.serialization().addAdvancedExternalizer(new IdViaConfigObj.Externalizer()); builder.serialization().addAdvancedExternalizer(new IdViaAnnotationObj.Externalizer()); builder.serialization().addAdvancedExternalizer(3456, new IdViaBothObj.Externalizer()); return builder; }
private GlobalConfigurationBuilder createForeignExternalizerGlobalConfig(int id) { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); builder.serialization().addAdvancedExternalizer(id, new IdViaBothObj.Externalizer()); return builder; }
@BeforeClass public void setUp() { // Use a clustered cache manager to be able to test global marshaller interaction too GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithExternalAndInternal.Externalizer()); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithExternalizer.Externalizer()); globalBuilder.serialization().addAdvancedExternalizer(new PojoWithMultiExternalizer.Externalizer()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.DIST_SYNC); cm = TestCacheManagerFactory.createClusteredCacheManager(globalBuilder, builder); marshaller = extractGlobalMarshaller(cm); }
static EmbeddedCacheManager getCacheManager(Properties properties) { StoreProperties props = new StoreProperties(TARGET, properties); GlobalConfigurationBuilder globalBuilder = new GlobalConfigurationBuilder(); globalBuilder.defaultCacheName(DEFAULT_CACHE_NAME); SerializationConfigUtil.configureSerialization(props, globalBuilder.serialization()); GlobalConfiguration globalConfig = globalBuilder.build(); return new DefaultCacheManager(globalConfig, new ConfigurationBuilder().build()); }
public InfinispanEventsDeliveredCache(String subscribeProxyIdentifier) { super(EventCloudProperties.getDefaultTemporaryPath() + "infinispan" + File.separatorChar + subscribeProxyIdentifier); GlobalConfigurationBuilder config = new GlobalConfigurationBuilder(); config.globalJmxStatistics().disable().allowDuplicateDomains(true); config.serialization().addAdvancedExternalizer( NotificationId.SERIALIZER).addAdvancedExternalizer( SubscriptionId.SERIALIZER); this.cacheManager = new DefaultCacheManager(config.build()); this.cache = this.createCache(); }
public static StreamingMarshaller getMarshaller(StoreProperties props) { switch (getMarshallerType(props)) { case CURRENT: if (props.isTargetStore()) return null; GlobalConfigurationBuilder globalConfig = new GlobalConfigurationBuilder() .defaultCacheName(props.cacheName()); configureExternalizers(props, globalConfig.serialization()); EmbeddedCacheManager manager = new DefaultCacheManager(globalConfig.build(), new ConfigurationBuilder().build()); return manager.getCache().getAdvancedCache().getComponentRegistry().getComponent(StreamingMarshaller.class); case CUSTOM: String marshallerClass = props.get(MARSHALLER, CLASS); if (marshallerClass == null) throw new CacheConfigurationException( String.format("The property %s.%s must be set if a custom marshaller type is specified", MARSHALLER, CLASS)); try { return (StreamingMarshaller) Util.loadClass(marshallerClass, SerializationConfigUtil.class.getClassLoader()).newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new CacheConfigurationException(String.format("Unable to load StreamingMarshaller '%s' for %s store", marshallerClass, SOURCE), e); } case LEGACY: if (props.isTargetStore()) throw new CacheConfigurationException("The legacy marshaller can only be specified for source stores."); return new LegacyVersionAwareMarshaller(getExternalizersFromProps(props)); default: throw new IllegalStateException("Unexpected marshaller type"); } }
private void withExpectedInternalFailure(final AdvancedExternalizer<?> ext, String message) { try { GlobalConfigurationBuilder globalBuilder = new GlobalConfigurationBuilder(); globalBuilder.serialization().addAdvancedExternalizer(ext).addAdvancedExternalizer(ext); assert false : message; } catch (CacheConfigurationException ce) { log.trace("Expected exception", ce); } finally { cm.stop(); } }
protected EmbeddedCacheManager addClusterEnabledCacheManager(TransportFlags flags, GlobalConfigurationBuilder gcb, ConfigurationBuilder builder) { GlobalConfigurationBuilder clone = GlobalConfigurationBuilder.defaultClusteredBuilder(); //get the transport here as clone.read below would inject the same transport reference into the clone // which we don't want Transport transport = clone.transport().getTransport(); Marshaller marshaller = clone.serialization().getMarshaller(); clone.read(gcb.build()); clone.transport().transport(transport); clone.serialization().marshaller(marshaller); clone.transport().clusterName("ISPN(SITE " + siteName + ")"); EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(clone, builder, flags); cacheManagers.add(cm); return cm; }
builder.serialization().marshaller(Util.<Marshaller>getInstance(value, holder.getClassLoader())); break; builder.serialization().version(value); break;
@Override protected GlobalConfigurationBuilder createForeignExternalizerGlobalConfig() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder().clusteredDefault(); builder.serialization() .addAdvancedExternalizer(1234, new IdViaConfigObj.Externalizer()) .addAdvancedExternalizer(new IdViaAnnotationObj.Externalizer()) .addAdvancedExternalizer(3456, new IdViaBothObj.Externalizer()); return builder; }
protected GlobalConfigurationBuilder createForeignExternalizerGlobalConfig() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder().clusteredDefault(); builder.serialization() .addAdvancedExternalizer(1234, new IdViaConfigObj.Externalizer()) .addAdvancedExternalizer(new IdViaAnnotationObj.Externalizer()) .addAdvancedExternalizer(3456, new IdViaBothObj.Externalizer()); return builder; }
public void testConfigureMarshaller() { GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder(); TestObjectStreamMarshaller marshaller = new TestObjectStreamMarshaller(); gc.serialization().marshaller(marshaller); withCacheManager(new CacheManagerCallable( createCacheManager(gc, new ConfigurationBuilder())) { @Override public void call() { cm.getCache(); } }); marshaller.stop(); }
public void testForeignExternalizerMultiClassTypesViaSameExternalizer() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); builder.serialization().addAdvancedExternalizer(new MultiIdViaClassExternalizer()); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builder, new ConfigurationBuilder()); try { cm.getCache(); assert 767 == findExternalizerId(new IdViaConfigObj(), cm); assert 767 == findExternalizerId(new IdViaAnnotationObj(), cm); assert 767 == findExternalizerId(new IdViaBothObj(), cm); } finally { cm.stop(); } }
public void testForeignExternalizerMultiClassNameTypesViaSameExternalizer() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); builder.serialization().addAdvancedExternalizer(868, new MultiIdViaClassNameExternalizer()); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builder, new ConfigurationBuilder()); try { cm.getCache(); assert 868 == findExternalizerId(new IdViaConfigObj(), cm); assert 868 == findExternalizerId(new IdViaAnnotationObj(), cm); assert 868 == findExternalizerId(new IdViaBothObj(), cm); } finally { cm.stop(); } }