Search in sources :

Example 1 with Externalizable

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

the class OptimizedObjectInputStream method readExternalizable.

/**
     * Reads {@link Externalizable} object.
     *
     * @param constructor Constructor.
     * @param readResolveMtd {@code readResolve} method.
     * @return Object.
     * @throws ClassNotFoundException If class not found.
     * @throws IOException In case of error.
     */
Object readExternalizable(Constructor<?> constructor, Method readResolveMtd) throws ClassNotFoundException, IOException {
    Object obj;
    try {
        obj = constructor.newInstance();
    } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
        throw new IOException(e);
    }
    int handle = handles.assign(obj);
    Externalizable extObj = ((Externalizable) obj);
    extObj.readExternal(this);
    if (readResolveMtd != null) {
        try {
            obj = readResolveMtd.invoke(obj);
            handles.set(handle, obj);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new IOException(e);
        }
    }
    return obj;
}
Also used : OptimizedMarshallerUtils.setObject(org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setObject) Externalizable(java.io.Externalizable) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Externalizable

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

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByStringAndUUIDAndLong.

/**
     * @throws Exception If failed.
     */
public void testSerializationTopicCreatedByStringAndUUIDAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING, AN_UUID, A_LONG);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 3 with Externalizable

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

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByStrinAndLong.

/**
     * @throws Exception If failed.
     */
public void testSerializationTopicCreatedByStrinAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING, A_LONG);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 4 with Externalizable

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

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByStringAndIntAndLong.

/**
     * @throws Exception If failed.
     */
public void testSerializationTopicCreatedByStringAndIntAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING, AN_INT, A_LONG);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 5 with Externalizable

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

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByGridUuidAndUUID.

/**
     * @throws Exception If failed.
     */
public void testSerializationTopicCreatedByGridUuidAndUUID() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_GRID_UUID, AN_UUID);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

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