Search in sources :

Example 1 with NonPortableClassException

use of org.apache.geode.pdx.NonPortableClassException in project geode by apache.

the class InternalDataSerializer method writePdx.

public static boolean writePdx(DataOutput out, InternalCache internalCache, Object pdx, PdxSerializer pdxSerializer) throws IOException {
    TypeRegistry tr = null;
    if (internalCache != null) {
        tr = internalCache.getPdxRegistry();
    }
    PdxOutputStream os;
    if (out instanceof HeapDataOutputStream) {
        os = new PdxOutputStream((HeapDataOutputStream) out);
    } else {
        os = new PdxOutputStream();
    }
    PdxWriterImpl writer = new PdxWriterImpl(tr, pdx, os);
    try {
        if (pdxSerializer != null) {
            // serializer
            if (isGemfireObject(pdx)) {
                return false;
            }
            if (is662SerializationEnabled()) {
                boolean alreadyInProgress = isPdxSerializationInProgress();
                if (!alreadyInProgress) {
                    setPdxSerializationInProgress(true);
                    try {
                        if (!pdxSerializer.toData(pdx, writer)) {
                            return false;
                        }
                    } finally {
                        setPdxSerializationInProgress(false);
                    }
                } else {
                    if (!pdxSerializer.toData(pdx, writer)) {
                        return false;
                    }
                }
            } else {
                if (!pdxSerializer.toData(pdx, writer)) {
                    return false;
                }
            }
        } else {
            if (is662SerializationEnabled()) {
                boolean alreadyInProgress = isPdxSerializationInProgress();
                if (!alreadyInProgress) {
                    setPdxSerializationInProgress(true);
                    try {
                        ((PdxSerializable) pdx).toData(writer);
                    } finally {
                        setPdxSerializationInProgress(false);
                    }
                } else {
                    ((PdxSerializable) pdx).toData(writer);
                }
            } else {
                ((PdxSerializable) pdx).toData(writer);
            }
        }
    } catch (ToDataException | CancelException | NonPortableClassException | GemFireRethrowable ex) {
        throw ex;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        if (pdxSerializer != null) {
            throw new ToDataException("PdxSerializer failed when calling toData on " + pdx.getClass(), t);
        } else {
            throw new ToDataException("toData failed on PdxSerializable " + pdx.getClass(), t);
        }
    }
    int bytesWritten = writer.completeByteStreamGeneration();
    getDMStats(internalCache).incPdxSerialization(bytesWritten);
    if (!(out instanceof HeapDataOutputStream)) {
        writer.sendTo(out);
    }
    return true;
}
Also used : PdxOutputStream(org.apache.geode.pdx.internal.PdxOutputStream) NonPortableClassException(org.apache.geode.pdx.NonPortableClassException) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) GemFireRethrowable(org.apache.geode.GemFireRethrowable) ToDataException(org.apache.geode.ToDataException) CancelException(org.apache.geode.CancelException) PdxWriterImpl(org.apache.geode.pdx.internal.PdxWriterImpl) PdxSerializable(org.apache.geode.pdx.PdxSerializable)

Example 2 with NonPortableClassException

use of org.apache.geode.pdx.NonPortableClassException in project geode by apache.

the class InternalDataSerializer method autoSerialized.

public static boolean autoSerialized(Object o, DataOutput out) throws IOException {
    AutoSerializableManager asm = TypeRegistry.getAutoSerializableManager();
    if (asm != null) {
        AutoClassInfo aci = asm.getExistingClassInfo(o.getClass());
        if (aci != null) {
            InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
            TypeRegistry tr = internalCache.getPdxRegistry();
            PdxOutputStream os;
            if (out instanceof HeapDataOutputStream) {
                os = new PdxOutputStream((HeapDataOutputStream) out);
            } else {
                os = new PdxOutputStream();
            }
            PdxWriterImpl writer = new PdxWriterImpl(tr, o, aci, os);
            try {
                if (is662SerializationEnabled()) {
                    boolean alreadyInProgress = isPdxSerializationInProgress();
                    if (!alreadyInProgress) {
                        setPdxSerializationInProgress(true);
                        try {
                            asm.writeData(writer, o, aci);
                        } finally {
                            setPdxSerializationInProgress(false);
                        }
                    } else {
                        asm.writeData(writer, o, aci);
                    }
                } else {
                    asm.writeData(writer, o, aci);
                }
            } catch (ToDataException | CancelException | NonPortableClassException | GemFireRethrowable ex) {
                throw ex;
            } catch (VirtualMachineError err) {
                SystemFailure.initiateFailure(err);
                // now, so don't let this thread continue.
                throw err;
            } catch (Throwable t) {
                // Whenever you catch Error or Throwable, you must also
                // catch VirtualMachineError (see above). However, there is
                // _still_ a possibility that you are dealing with a cascading
                // error condition, so you also need to check to see if the JVM
                // is still usable:
                SystemFailure.checkFailure();
                throw new ToDataException("PdxSerializer failed when calling toData on " + o.getClass(), t);
            }
            int bytesWritten = writer.completeByteStreamGeneration();
            getDMStats(internalCache).incPdxSerialization(bytesWritten);
            if (!(out instanceof HeapDataOutputStream)) {
                writer.sendTo(out);
            }
            return true;
        }
    }
    return false;
}
Also used : PdxOutputStream(org.apache.geode.pdx.internal.PdxOutputStream) NonPortableClassException(org.apache.geode.pdx.NonPortableClassException) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) AutoClassInfo(org.apache.geode.pdx.internal.AutoSerializableManager.AutoClassInfo) AutoSerializableManager(org.apache.geode.pdx.internal.AutoSerializableManager) GemFireRethrowable(org.apache.geode.GemFireRethrowable) ToDataException(org.apache.geode.ToDataException) CancelException(org.apache.geode.CancelException) PdxWriterImpl(org.apache.geode.pdx.internal.PdxWriterImpl)

Aggregations

CancelException (org.apache.geode.CancelException)2 GemFireRethrowable (org.apache.geode.GemFireRethrowable)2 ToDataException (org.apache.geode.ToDataException)2 NonPortableClassException (org.apache.geode.pdx.NonPortableClassException)2 PdxOutputStream (org.apache.geode.pdx.internal.PdxOutputStream)2 PdxWriterImpl (org.apache.geode.pdx.internal.PdxWriterImpl)2 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)2 InternalCache (org.apache.geode.internal.cache.InternalCache)1 PdxSerializable (org.apache.geode.pdx.PdxSerializable)1 AutoSerializableManager (org.apache.geode.pdx.internal.AutoSerializableManager)1 AutoClassInfo (org.apache.geode.pdx.internal.AutoSerializableManager.AutoClassInfo)1