use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformContinuousQueryRemoteFilter method deploy.
/**
* Deploy filter to native platform.
*/
private void deploy() {
lock.writeLock().lock();
try {
// 1. Do not deploy if the filter has been closed concurrently.
if (closed)
throw new CacheEntryListenerException("Failed to deploy the filter because it has been closed.");
// 2. Deploy.
PlatformContext ctx = PlatformUtils.platformContext(grid);
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(filter);
out.synchronize();
ptr = ctx.gateway().continuousQueryFilterCreate(mem.pointer());
} catch (Exception e) {
// 3. Close in case of failure.
close();
throw new CacheEntryListenerException("Failed to deploy the filter.", e);
}
} finally {
lock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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.PlatformOutputStream in project ignite by apache.
the class PlatformDotNetCacheStore method doInvoke.
/**
* Perform actual invoke.
*
* @param task Task.
* @param readClo Reader.
* @return Result.
* @throws org.apache.ignite.IgniteCheckedException If failed.
*/
protected int doInvoke(IgniteInClosure<BinaryRawWriterEx> task, IgniteInClosure<BinaryRawReaderEx> readClo) throws IgniteCheckedException {
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeLong(ptr);
task.apply(writer);
out.synchronize();
int res = platformCtx.gateway().cacheStoreInvoke(mem.pointer());
if (res != 0) {
// Read error
Object nativeErr = platformCtx.reader(mem.input()).readObjectDetached();
throw platformCtx.createNativeException(nativeErr);
}
if (readClo != null) {
BinaryRawReaderEx reader = platformCtx.reader(mem);
readClo.apply(reader);
}
return res;
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformClusterNodeFilterImpl method apply.
/**
* {@inheritDoc}
*/
@Override
public boolean apply(ClusterNode clusterNode) {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
ctx.writeNode(writer, clusterNode);
out.synchronize();
return ctx.gateway().clusterNodeFilterApply(mem.pointer()) != 0;
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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