use of org.apache.ignite.internal.processors.platform.memory.PlatformMemory in project ignite by apache.
the class PlatformFullJob method execute0.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public Object execute0(PlatformContext ctx) throws IgniteCheckedException {
boolean cancel = false;
synchronized (this) {
// 1. Create job if necessary.
if (task == null) {
assert ptr == 0;
createJob(ctx);
} else
assert ptr != 0;
// 2. Set correct state.
if (state == STATE_INIT)
state = STATE_RUNNING;
else {
assert state == STATE_CANCELLED;
cancel = true;
}
}
try {
if (task != null)
return runLocal(ctx, cancel);
else {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
out.writeLong(ptr);
// cancel
out.writeBoolean(cancel);
out.synchronize();
ctx.gateway().computeJobExecute(mem.pointer());
PlatformInputStream in = mem.input();
in.synchronize();
BinaryRawReaderEx reader = ctx.reader(in);
return PlatformUtils.readInvocationResult(ctx, reader);
}
}
} finally {
synchronized (this) {
if (task == null) {
assert ptr != 0;
ctx.gateway().computeJobDestroy(ptr);
}
if (state == STATE_RUNNING)
state = STATE_COMPLETED;
}
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformMemory in project ignite by apache.
the class PlatformFullTask method map.
/**
* {@inheritDoc}
*/
@Nullable
@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();
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformMemory 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.PlatformMemory in project ignite by apache.
the class PlatformDotNetConfigurationClosure method prepare.
/**
* Prepare .Net size.
*
* @param igniteCfg Ignite configuration.
* @param interopCfg Interop configuration.
*/
@SuppressWarnings("ConstantConditions")
private void prepare(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx interopCfg) {
cfg = igniteCfg;
try (PlatformMemory outMem = memMgr.allocate()) {
try (PlatformMemory inMem = memMgr.allocate()) {
PlatformOutputStream out = outMem.output();
GridBinaryMarshaller marshaller = PlatformUtils.marshaller();
BinaryRawWriterEx writer = marshaller.writer(out);
PlatformConfigurationUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
// Write .NET beans
List<PlatformDotNetLifecycleBean> beans = beans(igniteCfg);
writer.writeInt(beans.size());
for (PlatformDotNetLifecycleBean bean : beans) {
writer.writeString(bean.getTypeName());
writer.writeMap(bean.getProperties());
}
// Write .NET affinity functions
List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(igniteCfg);
writer.writeInt(affFuncs.size());
for (PlatformDotNetAffinityFunction func : affFuncs) {
writer.writeString(func.getTypeName());
writer.writeMap(func.getProperties());
}
out.synchronize();
gate.extensionCallbackInLongLongOutLong(PlatformUtils.OP_PREPARE_DOT_NET, outMem.pointer(), inMem.pointer());
processPrepareResult(marshaller.reader(inMem.input()));
}
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformMemory in project ignite by apache.
the class PlatformEventFilterListenerImpl method apply0.
/**
* Apply impl.
* @param uuid Node if.
* @param evt Event.
* @return Result.
*/
private boolean apply0(final UUID uuid, final Event evt) {
if (!ctx.isEventTypeSupported(evt.type()))
return false;
if (types != null) {
boolean match = false;
for (int type : types) {
if (type == evt.type()) {
match = true;
break;
}
}
if (!match)
return false;
}
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
ctx.writeEvent(writer, evt);
writer.writeUuid(uuid);
out.synchronize();
int res = ctx.gateway().eventFilterApply(hnd, mem.pointer());
return res != 0;
}
}
Aggregations