Search in sources :

Example 1 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridCacheQueryResponse method unmarshalCollection0.

/**
     * @param byteCol Collection to unmarshal.
     * @param ctx Context.
     * @param ldr Loader.
     * @return Unmarshalled collection.
     * @throws IgniteCheckedException If failed.
     */
@Nullable
protected <T> List<T> unmarshalCollection0(@Nullable Collection<byte[]> byteCol, GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    assert ldr != null;
    assert ctx != null;
    if (byteCol == null)
        return null;
    List<T> col = new ArrayList<>(byteCol.size());
    Marshaller marsh = ctx.marshaller();
    ClassLoader ldr0 = U.resolveClassLoader(ldr, ctx.gridConfig());
    CacheObjectContext cacheObjCtx = null;
    for (byte[] bytes : byteCol) {
        Object obj = bytes == null ? null : marsh.<T>unmarshal(bytes, ldr0);
        if (obj instanceof Map.Entry) {
            Object key = ((Map.Entry) obj).getKey();
            if (key instanceof KeyCacheObject) {
                if (cacheObjCtx == null)
                    cacheObjCtx = ctx.cacheContext(cacheId).cacheObjectContext();
                ((KeyCacheObject) key).finishUnmarshal(cacheObjCtx, ldr0);
            }
        }
        col.add((T) obj);
    }
    return col;
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) ArrayList(java.util.ArrayList) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridServiceProcessor method copyAndInject.

/**
     * @param cfg Service configuration.
     * @return Copy of service.
     * @throws IgniteCheckedException If failed.
     */
private Service copyAndInject(ServiceConfiguration cfg) throws IgniteCheckedException {
    Marshaller m = ctx.config().getMarshaller();
    if (cfg instanceof LazyServiceConfiguration) {
        byte[] bytes = ((LazyServiceConfiguration) cfg).serviceBytes();
        Service srvc = U.unmarshal(m, bytes, U.resolveClassLoader(null, ctx.config()));
        ctx.resource().inject(srvc);
        return srvc;
    } else {
        Service svc = cfg.getService();
        try {
            byte[] bytes = U.marshal(m, svc);
            Service cp = U.unmarshal(m, bytes, U.resolveClassLoader(svc.getClass().getClassLoader(), ctx.config()));
            ctx.resource().inject(cp);
            return cp;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to copy service (will reuse same instance): " + svc.getClass(), e);
            return svc;
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.ignite.services.Service)

Example 3 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class ClusterGroupSelfTest method testAgeClusterGroupSerialization.

/**
     * @throws Exception If failed.
     */
public void testAgeClusterGroupSerialization() throws Exception {
    Marshaller marshaller = ignite.configuration().getMarshaller();
    ClusterGroup grp = ignite.cluster().forYoungest();
    ClusterNode node = grp.node();
    byte[] arr = marshaller.marshal(grp);
    ClusterGroup obj = marshaller.unmarshal(arr, null);
    assertEquals(node.id(), obj.node().id());
    try (Ignite ignore = startGrid()) {
        obj = marshaller.unmarshal(arr, null);
        assertEquals(grp.node().id(), obj.node().id());
        assertFalse(node.id().equals(obj.node().id()));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Marshaller(org.apache.ignite.marshaller.Marshaller) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 4 with Marshaller

use of org.apache.ignite.marshaller.Marshaller 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 5 with Marshaller

use of org.apache.ignite.marshaller.Marshaller 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)

Aggregations

Marshaller (org.apache.ignite.marshaller.Marshaller)42 Externalizable (java.io.Externalizable)8 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)6 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 URLConnection (java.net.URLConnection)5 HttpSession (javax.servlet.http.HttpSession)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 Server (org.eclipse.jetty.server.Server)4 ArrayList (java.util.ArrayList)3 Ignite (org.apache.ignite.Ignite)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 OptimizedMarshaller (org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller)3 Nullable (org.jetbrains.annotations.Nullable)3 File (java.io.File)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)2 XStream (com.thoughtworks.xstream.XStream)1