use of org.apache.ignite.internal.processors.platform.memory.PlatformInputStream in project ignite by apache.
the class PlatformAbstractService method invokeMethod.
/**
* {@inheritDoc}
*/
@Override
public Object invokeMethod(String mthdName, boolean srvKeepBinary, Object[] args) throws IgniteCheckedException {
assert ptr != 0;
assert platformCtx != null;
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeLong(ptr);
writer.writeBoolean(srvKeepBinary);
writer.writeString(mthdName);
if (args == null)
writer.writeBoolean(false);
else {
writer.writeBoolean(true);
writer.writeInt(args.length);
for (Object arg : args) writer.writeObjectDetached(arg);
}
out.synchronize();
platformCtx.gateway().serviceInvokeMethod(mem.pointer());
PlatformInputStream in = mem.input();
in.synchronize();
BinaryRawReaderEx reader = platformCtx.reader(in);
return PlatformUtils.readInvocationResult(platformCtx, reader);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformInputStream in project ignite by apache.
the class PlatformUtils method errorData.
/**
* Get error data.
*
* @param err Error.
* @return Error data.
*/
public static byte[] errorData(Throwable err) {
if (err instanceof PlatformExtendedException) {
PlatformContext ctx = ((PlatformExtendedException) err).context();
try (PlatformMemory mem = ctx.memory().allocate()) {
// Write error data.
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
try {
PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class));
} finally {
out.synchronize();
}
// Read error data into separate array.
PlatformInputStream in = mem.input();
in.synchronize();
int len = in.remaining();
assert len > 0;
byte[] arr = in.array();
byte[] res = new byte[len];
System.arraycopy(arr, 0, res, 0, len);
return res;
}
} else
return null;
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformInputStream in project ignite by apache.
the class PlatformAbstractService method invokeMethod.
/**
* {@inheritDoc}
*/
@Override
public Object invokeMethod(String mthdName, boolean srvKeepBinary, boolean deserializeResult, @Nullable Object[] args, @Nullable Map<String, Object> callAttrs) throws IgniteCheckedException {
assert ptr != 0;
assert platformCtx != null;
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeLong(ptr);
writer.writeBoolean(srvKeepBinary);
writer.writeString(mthdName);
if (args == null)
writer.writeBoolean(false);
else {
writer.writeBoolean(true);
writer.writeInt(args.length);
for (Object arg : args) writer.writeObjectDetached(arg);
}
writer.writeMap(callAttrs);
out.synchronize();
platformCtx.gateway().serviceInvokeMethod(mem.pointer());
PlatformInputStream in = mem.input();
in.synchronize();
BinaryRawReaderEx reader = platformCtx.reader(in);
return PlatformUtils.readInvocationResult(platformCtx, reader, deserializeResult);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformInputStream in project ignite by apache.
the class PlatformAbstractService method init.
/**
* {@inheritDoc}
*/
@Override
public void init(ServiceContext ctx) throws Exception {
assert ptr == 0;
assert platformCtx != null;
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeBoolean(srvKeepBinary);
writer.writeObject(svc);
writeServiceContext(ctx, writer);
out.synchronize();
ptr = platformCtx.gateway().serviceInit(mem.pointer());
PlatformInputStream in = mem.input();
in.synchronize();
BinaryRawReaderEx reader = platformCtx.reader(in);
PlatformUtils.readInvocationResult(platformCtx, reader);
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformInputStream in project ignite by apache.
the class PlatformFullTask method map.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) {
assert arg == null;
lock.readLock().lock();
try {
assert !done;
Collection<ClusterNode> nodes = compute.clusterGroup().nodes();
PlatformMemoryManager memMgr = ctx.memory();
try (PlatformMemory mem = memMgr.allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(taskPtr);
write(writer, nodes, subgrid);
out.synchronize();
ctx.gateway().computeTaskMap(mem.pointer());
PlatformInputStream in = mem.input();
in.synchronize();
BinaryRawReaderEx reader = ctx.reader(in);
return read(reader, nodes);
}
} finally {
lock.readLock().unlock();
}
}
Aggregations