Search in sources :

Example 1 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class InternalDataSerializer method readPdxSerializable.

private static Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException {
    int len = in.readInt();
    int typeId = in.readInt();
    InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
    PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "readPdxSerializable pdxType={}", pdxType);
    }
    if (pdxType == null) {
        throw new IllegalStateException("Unknown pdx type=" + typeId);
    }
    DMStats dmStats = getDMStats(internalCache);
    dmStats.incPdxDeserialization(len + 9);
    // check if PdxInstance needs to be returned.
    if (pdxType.getNoDomainClass() || internalCache.getPdxReadSerializedByAnyGemFireServices()) {
        dmStats.incPdxInstanceCreations();
        return new PdxInstanceImpl(pdxType, in, len);
    } else {
        PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len);
        return pdxReader.getObject();
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) PdxReaderImpl(org.apache.geode.pdx.internal.PdxReaderImpl) PdxType(org.apache.geode.pdx.internal.PdxType) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 2 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class InternalDataSerializer method readPdxInstance.

/**
   * Reads a PdxInstance from dataBytes and returns it. If the first object read is not pdx encoded
   * returns null.
   */
public static PdxInstance readPdxInstance(final byte[] dataBytes, InternalCache internalCache) {
    try {
        byte type = dataBytes[0];
        if (type == PDX) {
            PdxInputStream in = new PdxInputStream(dataBytes);
            // throw away the type byte
            in.readByte();
            int len = in.readInt();
            int typeId = in.readInt();
            PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
            if (pdxType == null) {
                throw new IllegalStateException("Unknown pdx type=" + typeId);
            }
            return new PdxInstanceImpl(pdxType, in, len);
        } else if (type == DSCODE.PDX_ENUM) {
            PdxInputStream in = new PdxInputStream(dataBytes);
            // throw away the type byte
            in.readByte();
            int dsId = in.readByte();
            int tmp = readArrayLength(in);
            int enumId = dsId << 24 | tmp & 0xFFFFFF;
            TypeRegistry tr = internalCache.getPdxRegistry();
            EnumInfo ei = tr.getEnumInfoById(enumId);
            if (ei == null) {
                throw new IllegalStateException("Unknown pdx enum id=" + enumId);
            }
            return ei.getPdxInstance(enumId);
        } else if (type == DSCODE.PDX_INLINE_ENUM) {
            PdxInputStream in = new PdxInputStream(dataBytes);
            // throw away the type byte
            in.readByte();
            String className = DataSerializer.readString(in);
            String enumName = DataSerializer.readString(in);
            int enumOrdinal = InternalDataSerializer.readArrayLength(in);
            return new PdxInstanceEnum(className, enumName, enumOrdinal);
        }
    } catch (IOException ignore) {
    }
    return null;
}
Also used : PdxInstanceEnum(org.apache.geode.pdx.internal.PdxInstanceEnum) PdxType(org.apache.geode.pdx.internal.PdxType) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) PdxInputStream(org.apache.geode.pdx.internal.PdxInputStream) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry)

Example 3 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class GetPdxTypes70 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 types from {}", serverConnection.getName(), serverConnection.getSocketString());
    }
    Map<Integer, PdxType> types;
    try {
        InternalCache cache = serverConnection.getCache();
        types = cache.getPdxRegistry().typeMap();
    } 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(types);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Message(org.apache.geode.internal.cache.tier.sockets.Message) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException)

Example 4 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class GetPDXIdForType 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 pdxId;
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        pdxId = registry.defineType(type);
    } 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(pdxId);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Message(org.apache.geode.internal.cache.tier.sockets.Message) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 5 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class GetPDXTypeById 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 type by id request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int pdxId = clientMessage.getPart(0).getInt();
    PdxType type;
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        type = registry.getType(pdxId);
    } 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(type);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Message(org.apache.geode.internal.cache.tier.sockets.Message) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Aggregations

PdxType (org.apache.geode.pdx.internal.PdxType)32 Test (org.junit.Test)18 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)14 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)10 IOException (java.io.IOException)9 Cache (org.apache.geode.cache.Cache)9 CacheFactory (org.apache.geode.cache.CacheFactory)9 Region (org.apache.geode.cache.Region)8 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)8 File (java.io.File)7 Properties (java.util.Properties)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 Map (java.util.Map)5 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)5 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)5 PdxInstance (org.apache.geode.pdx.PdxInstance)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 ArrayList (java.util.ArrayList)4 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)4