use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.
the class PdxCopyOnReadQueryJUnitTest method testCopyOnReadPdxSerialization.
@Test
public void testCopyOnReadPdxSerialization() throws Exception {
List<String> classes = new ArrayList<String>();
classes.add(PortfolioPdx.class.getCanonicalName());
ReflectionBasedAutoSerializer serializer = new ReflectionBasedAutoSerializer(classes.toArray(new String[0]));
CacheFactory cf = new CacheFactory();
cf.setPdxSerializer(serializer);
cf.setPdxReadSerialized(false);
cf.set(MCAST_PORT, "0");
cache = cf.create();
cache.setCopyOnRead(true);
Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("SimpleObjects");
Region duplicates = cache.createRegionFactory(RegionShortcut.REPLICATE).create("SimpleObjects_Duplicates");
for (int i = 0; i < 10; i++) {
PortfolioPdx t = new PortfolioPdx(i);
region.put(i, t);
duplicates.put(i, t);
}
QueryService qs = cache.getQueryService();
SelectResults rs = (SelectResults) qs.newQuery("select * from /SimpleObjects").execute();
assertEquals(10, rs.size());
Query query = qs.newQuery("select * from /SimpleObjects_Duplicates s where s in ($1)");
SelectResults finalResults = (SelectResults) query.execute(new Object[] { rs });
assertEquals(10, finalResults.size());
}
use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.
the class RestInterfaceJUnitTest method setupGemFire.
@Before
public void setupGemFire() {
AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
if (agentUtil.findWarLocation("geode-web-api") == null) {
fail("unable to locate geode-web-api WAR file");
}
if (gemfireCache == null) {
gemfireProperties = (gemfireProperties != null ? gemfireProperties : new Properties());
gemfireCache = new CacheFactory().setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getName().replaceAll("\\$", "."))).setPdxReadSerialized(true).setPdxIgnoreUnreadFields(false).set("name", getClass().getSimpleName()).set(MCAST_PORT, "0").set(LOG_LEVEL, "config").set(HTTP_SERVICE_BIND_ADDRESS, "localhost").set(HTTP_SERVICE_PORT, String.valueOf(getHttpServicePort())).set(START_DEV_REST_API, "true").create();
RegionFactory<String, Object> peopleRegionFactory = gemfireCache.createRegionFactory();
peopleRegionFactory.setDataPolicy(DataPolicy.PARTITION);
peopleRegionFactory.setKeyConstraint(String.class);
peopleRegionFactory.setValueConstraint(Object.class);
people = peopleRegionFactory.create("People");
}
}
use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.
the class TypeRegistry method setPdxSerializer.
public static void setPdxSerializer(PdxSerializer v) {
if (v == null) {
PdxSerializer oldValue = pdxSerializer.getAndSet(null);
if (oldValue instanceof ReflectionBasedAutoSerializer) {
asm.compareAndSet((AutoSerializableManager) ((ReflectionBasedAutoSerializer) oldValue).getManager(), null);
}
} else {
pdxSerializerWasSet = true;
pdxSerializer.set(v);
if (v instanceof ReflectionBasedAutoSerializer) {
asm.set((AutoSerializableManager) ((ReflectionBasedAutoSerializer) v).getManager());
}
}
}
use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project immutables by immutables.
the class GeodeCqTest method setUp.
@BeforeEach
public void setUp() throws Exception {
this.clientCache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334).setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName())).setPoolSubscriptionEnabled(true).create();
this.region = clientCache.<String, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("persons");
region.clear();
}
use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.
the class PDXCommands method configurePDX.
@CliCommand(value = CliStrings.CONFIGURE_PDX, help = CliStrings.CONFIGURE_PDX__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result configurePDX(@CliOption(key = CliStrings.CONFIGURE_PDX__READ__SERIALIZED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__READ__SERIALIZED__HELP) Boolean readSerialized, @CliOption(key = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS__HELP) Boolean ignoreUnreadFields, @CliOption(key = CliStrings.CONFIGURE_PDX__DISKSTORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", help = CliStrings.CONFIGURE_PDX__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES__HELP) String[] patterns, @CliOption(key = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portablePatterns) {
Result result = null;
try {
InfoResultData ird = ResultBuilder.createInfoResultData();
CacheCreation cache = new CacheCreation(true);
if ((portablePatterns != null && portablePatterns.length > 0) && (patterns != null && patterns.length > 0)) {
return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
}
if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
}
// Set persistent and the disk-store
if (diskStore != null) {
cache.setPdxPersistent(true);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
if (!diskStore.equals("")) {
cache.setPdxDiskStore(diskStore);
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore());
} else {
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT");
}
} else {
cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
}
// Set read-serialized
if (readSerialized != null) {
cache.setPdxReadSerialized(readSerialized);
} else {
cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED);
}
ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized());
// Set ingoreUnreadFields
if (ignoreUnreadFields != null) {
cache.setPdxIgnoreUnreadFields(ignoreUnreadFields);
} else {
cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS);
}
ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields());
if (portablePatterns != null) {
ReflectionBasedAutoSerializer autoSerializer = new ReflectionBasedAutoSerializer(portablePatterns);
cache.setPdxSerializer(autoSerializer);
ird.addLine("PDX Serializer " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Portable classes " + Arrays.toString(portablePatterns));
}
if (patterns != null) {
ReflectionBasedAutoSerializer nonPortableAutoSerializer = new ReflectionBasedAutoSerializer(true, patterns);
cache.setPdxSerializer(nonPortableAutoSerializer);
ird.addLine("PDX Serializer : " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Non portable classes :" + Arrays.toString(patterns));
}
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
CacheXmlGenerator.generate(cache, printWriter, true, false, false);
printWriter.close();
String xmlDefinition = stringWriter.toString();
// TODO jbarrett - shouldn't this use the same loadXmlDefinition that other constructors use?
XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
result = ResultBuilder.buildResult(ird);
persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
} catch (Exception e) {
return ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
Aggregations