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;
}
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;
}
}
}
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()));
}
}
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));
}
}
}
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));
}
}
}
Aggregations