Search in sources :

Example 11 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class OptimizedObjectOutputStream method writeExternalizable.

/**
 * Writes externalizable object.
 *
 * @param obj Object.
 * @throws IOException In case of error.
 */
void writeExternalizable(Object obj) throws IOException {
    Externalizable extObj = (Externalizable) obj;
    extObj.writeExternal(this);
}
Also used : Externalizable(java.io.Externalizable)

Example 12 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class OptimizedObjectOutputStream method writeObject0.

/**
 * Writes object to stream.
 *
 * @param obj Object.
 * @throws IOException In case of error.
 */
private void writeObject0(Object obj) throws IOException {
    curObj = null;
    curFields = null;
    curPut = null;
    if (obj == null)
        writeByte(NULL);
    else {
        if (obj instanceof Throwable && !(obj instanceof Externalizable)) {
            writeByte(JDK);
            try {
                ctx.jdkMarshaller().marshal(obj, this);
            } catch (IgniteCheckedException e) {
                IOException ioEx = e.getCause(IOException.class);
                if (ioEx != null)
                    throw ioEx;
                else
                    throw new IOException("Failed to serialize object with JDK marshaller: " + obj, e);
            }
        } else {
            OptimizedClassDescriptor desc = classDescriptor(clsMap, obj instanceof Object[] ? Object[].class : obj.getClass(), ctx, mapper);
            if (desc.excluded()) {
                writeByte(NULL);
                return;
            }
            Object obj0 = desc.replace(obj);
            if (obj0 == null) {
                writeByte(NULL);
                return;
            }
            int handle = -1;
            if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass() && !desc.isProxy())
                handle = handles.lookup(obj);
            if (obj0 != obj) {
                obj = obj0;
                desc = classDescriptor(clsMap, obj instanceof Object[] ? Object[].class : obj.getClass(), ctx, mapper);
            }
            try {
                if (handle >= 0) {
                    writeByte(HANDLE);
                    writeInt(handle);
                } else
                    desc.write(this, obj);
            } catch (IOException e) {
                throw new IOException("Failed to serialize object [typeName=" + desc.describedClass().getName() + ']', e);
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Externalizable(java.io.Externalizable) OptimizedMarshallerUtils.getObject(org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getObject) IOException(java.io.IOException)

Aggregations

Externalizable (java.io.Externalizable)12 Marshaller (org.apache.ignite.marshaller.Marshaller)8 IOException (java.io.IOException)2 ObjectStreamField (java.io.ObjectStreamField)1 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 OptimizedMarshallerUtils.getObject (org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getObject)1 OptimizedMarshallerUtils.setObject (org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setObject)1