use of org.apache.geode.pdx.internal.PdxType in project geode by apache.
the class PdxSerializableJUnitTest method testFieldRemove.
@Test
public void testFieldRemove() throws Exception {
// this test pretends that version 1 is newer than version2
// so it look like a field was removed.
MyEvolvablePdx.setVersion(1);
MyEvolvablePdx pdx = new MyEvolvablePdx(7);
assertEquals(7, pdx.f1);
assertEquals(0, pdx.f2);
byte[] v1actual = createBlob(pdx);
int v1typeId = getBlobPdxTypeId(v1actual);
c.getPdxRegistry().removeLocal(pdx);
MyEvolvablePdx.setVersion(2);
MyEvolvablePdx pdxv2 = deblob(v1actual);
assertEquals(7, pdxv2.f1);
assertEquals(0, pdxv2.f2);
pdxv2.f2 = 23;
int numPdxTypes = getNumPdxTypes();
// now reserialize and make sure it is version2 and not version1
byte[] v2actual = createBlob(pdxv2);
int v2typeId = getBlobPdxTypeId(v2actual);
assertEquals(numPdxTypes + 1, getNumPdxTypes());
TypeRegistry tr = c.getPdxRegistry();
PdxType v2Type = tr.getType(v2typeId);
PdxType v1Type = tr.getType(v1typeId);
assertFalse(v1Type.equals(v2Type));
assertFalse(v1Type.compatible(v2Type));
assertNotNull(v1Type.getPdxField("f1"));
assertNull(v1Type.getPdxField("f2"));
assertNotNull(v2Type.getPdxField("f1"));
assertNotNull(v2Type.getPdxField("f2"));
MyEvolvablePdx.setVersion(1);
c.getPdxRegistry().removeLocal(pdx);
MyEvolvablePdx pdxv3 = deblob(v2actual);
assertEquals(7, pdxv3.f1);
assertEquals(0, pdxv3.f2);
}
use of org.apache.geode.pdx.internal.PdxType in project geode by apache.
the class DiskStoreImpl method pdxDeleteField.
private Collection<PdxType> pdxDeleteField(String className, String fieldName) throws IOException {
// Since we are recovering a disk store, the cast from DiskRegionView -->
// PlaceHolderDiskRegion
// and from RegionEntry --> DiskEntry should be ok.
// In offline mode, we need to schedule the regions to be recovered
// explicitly.
DiskRegionView foundPdx = null;
for (DiskRegionView drv : getKnown()) {
if (drv.getName().equals(PeerTypeRegistration.REGION_FULL_PATH)) {
foundPdx = drv;
scheduleForRecovery((PlaceHolderDiskRegion) drv);
}
}
if (foundPdx == null) {
throw new IllegalStateException("The disk store does not contain any PDX types.");
}
recoverRegionsThatAreReady();
PersistentOplogSet oplogSet = (PersistentOplogSet) getOplogSet(foundPdx);
ArrayList<PdxType> result = new ArrayList<PdxType>();
for (RegionEntry re : foundPdx.getRecoveredEntryMap().regionEntries()) {
Object value = re._getValueRetain(foundPdx, true);
if (Token.isRemoved(value)) {
continue;
}
if (value instanceof CachedDeserializable) {
value = ((CachedDeserializable) value).getDeserializedForReading();
}
if (value instanceof EnumInfo) {
// nothing to delete in an enum
continue;
}
PdxType type = (PdxType) value;
if (type.getClassName().equals(className)) {
PdxField field = type.getPdxField(fieldName);
if (field != null) {
field.setDeleted(true);
type.setHasDeletedField(true);
result.add(type);
oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(type), true);
}
}
}
return result;
}
use of org.apache.geode.pdx.internal.PdxType in project geode by apache.
the class DiskStoreImpl method pdxRename.
private Collection<Object> pdxRename(String oldBase, String newBase) throws IOException {
// Since we are recovering a disk store, the cast from DiskRegionView -->
// PlaceHolderDiskRegion
// and from RegionEntry --> DiskEntry should be ok.
// In offline mode, we need to schedule the regions to be recovered
// explicitly.
DiskRegionView foundPdx = null;
for (DiskRegionView drv : getKnown()) {
if (drv.getName().equals(PeerTypeRegistration.REGION_FULL_PATH)) {
foundPdx = drv;
scheduleForRecovery((PlaceHolderDiskRegion) drv);
}
}
if (foundPdx == null) {
throw new IllegalStateException("The disk store does not contain any PDX types.");
}
recoverRegionsThatAreReady();
PersistentOplogSet oplogSet = (PersistentOplogSet) getOplogSet(foundPdx);
ArrayList<Object> result = new ArrayList<>();
Pattern pattern = createPdxRenamePattern(oldBase);
for (RegionEntry re : foundPdx.getRecoveredEntryMap().regionEntries()) {
Object value = re._getValueRetain(foundPdx, true);
if (Token.isRemoved(value)) {
continue;
}
if (value instanceof CachedDeserializable) {
value = ((CachedDeserializable) value).getDeserializedForReading();
}
if (value instanceof EnumInfo) {
EnumInfo ei = (EnumInfo) value;
String newName = replacePdxRenamePattern(pattern, ei.getClassName(), newBase);
if (newName != null) {
ei.setClassName(newName);
result.add(ei);
oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(ei), true);
}
} else {
PdxType type = (PdxType) value;
String newName = replacePdxRenamePattern(pattern, type.getClassName(), newBase);
if (newName != null) {
type.setClassName(newName);
result.add(type);
oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(type), true);
}
}
}
return result;
}
use of org.apache.geode.pdx.internal.PdxType in project geode by apache.
the class AddPdxType method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received get pdx id for type request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
int noOfParts = clientMessage.getNumberOfParts();
PdxType type = (PdxType) clientMessage.getPart(0).getObject();
int typeId = clientMessage.getPart(1).getInt();
// The native client needs this line
// because it doesn't set the type id on the
// client side.
type.setTypeId(typeId);
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
registry.addRemoteType(typeId, type);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.pdx.internal.PdxType in project geode by apache.
the class ExportedRegistry method fromData.
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
int typeCount = in.readInt();
for (int i = 0; i < typeCount; i++) {
PdxType type = DataSerializer.readObject(in);
types.put(type.getTypeId(), type);
}
int enumCount = in.readInt();
for (int i = 0; i < enumCount; i++) {
int id = in.readInt();
EnumInfo ei = DataSerializer.readObject(in);
enums.put(id, ei);
}
}
Aggregations