use of org.apache.geode.pdx.internal.EnumInfo 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.EnumInfo in project geode by apache.
the class GetPDXEnumById 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 enum by id request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
int enumId = clientMessage.getPart(0).getInt();
EnumInfo result;
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
result = registry.getEnumInfoById(enumId);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setMessageType(MessageType.RESPONSE);
responseMsg.setNumberOfParts(1);
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.addObjPart(result);
responseMsg.send(serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class GetPDXIdForEnum 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 enum request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
EnumInfo enumInfo = (EnumInfo) clientMessage.getPart(0).getObject();
int enumId;
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
enumId = registry.defineEnum(enumInfo);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setMessageType(MessageType.RESPONSE);
responseMsg.setNumberOfParts(1);
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.addIntPart(enumId);
responseMsg.send(serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.pdx.internal.EnumInfo 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);
}
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class GFSnapshot method main.
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Usage: GFSnapshot <file>");
System.exit(1);
}
GFSnapshotImporter imp = new GFSnapshotImporter(new File(args[0]));
try {
System.out.println("Snapshot format is version " + imp.getVersion());
System.out.println("Snapshot region is " + imp.getRegionName());
ExportedRegistry reg = imp.getPdxTypes();
Map<Integer, PdxType> types = reg.types();
System.out.println("Found " + types.size() + " PDX types:");
for (Entry<Integer, PdxType> entry : types.entrySet()) {
System.out.println("\t" + entry.getKey() + " = " + entry.getValue());
}
Map<Integer, EnumInfo> enums = reg.enums();
System.out.println("Found " + enums.size() + " PDX enums: ");
for (Entry<Integer, EnumInfo> entry : enums.entrySet()) {
System.out.println("\t" + entry.getKey() + " = " + entry.getValue());
}
System.out.println();
SnapshotRecord record;
while ((record = imp.readSnapshotRecord()) != null) {
System.out.println(record.getKeyObject() + " = " + record.getValueObject());
}
} finally {
imp.close();
}
}
Aggregations