Search in sources :

Example 16 with EnumInfo

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;
}
Also used : Pattern(java.util.regex.Pattern) PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) ArrayList(java.util.ArrayList) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView)

Example 17 with EnumInfo

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);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 18 with EnumInfo

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);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 19 with EnumInfo

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);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo)

Example 20 with EnumInfo

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();
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord) File(java.io.File)

Aggregations

EnumInfo (org.apache.geode.pdx.internal.EnumInfo)21 PdxType (org.apache.geode.pdx.internal.PdxType)14 IOException (java.io.IOException)8 Test (org.junit.Test)8 Cache (org.apache.geode.cache.Cache)6 Region (org.apache.geode.cache.Region)6 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)6 CacheFactory (org.apache.geode.cache.CacheFactory)5 InternalCache (org.apache.geode.internal.cache.InternalCache)5 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)5 File (java.io.File)4 Map (java.util.Map)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Properties (java.util.Properties)3 Message (org.apache.geode.internal.cache.tier.sockets.Message)3 EnumId (org.apache.geode.pdx.internal.EnumId)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2