use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformLogger method log.
/**
* Logs the message.
*
* @param level Log level.
* @param msg Message.
* @param e Exception.
*/
private void log(int level, String msg, @Nullable Throwable e) {
String errorInfo = null;
if (e != null)
errorInfo = X.getFullStackTrace(e);
PlatformNativeException e0 = X.cause(e, PlatformNativeException.class);
if (ctx != null && e0 != null) {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(e0.cause());
out.synchronize();
gate.loggerLog(level, msg, category, errorInfo, mem.pointer());
}
} else {
gate.loggerLog(level, msg, category, errorInfo, 0);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformTargetProxyImpl method outStream.
/**
* {@inheritDoc}
*/
@Override
public void outStream(int type, long memPtr) throws Exception {
try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = platformCtx.writer(out);
target.processOutStream(type, writer);
out.synchronize();
} catch (Exception e) {
throw target.convertException(e);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformTargetProxyImpl method inObjectStreamOutObjectStream.
/**
* {@inheritDoc}
*/
@Override
public Object inObjectStreamOutObjectStream(int type, Object arg, long inMemPtr, long outMemPtr) throws Exception {
PlatformMemory inMem = null;
PlatformMemory outMem = null;
try {
BinaryRawReaderEx reader = null;
if (inMemPtr != 0) {
inMem = platformCtx.memory().get(inMemPtr);
reader = platformCtx.reader(inMem);
}
PlatformOutputStream out = null;
BinaryRawWriterEx writer = null;
if (outMemPtr != 0) {
outMem = platformCtx.memory().get(outMemPtr);
out = outMem.output();
writer = platformCtx.writer(out);
}
PlatformTarget res = target.processInObjectStreamOutObjectStream(type, unwrapProxy(arg), reader, writer);
if (out != null)
out.synchronize();
return wrapProxy(res);
} catch (Exception e) {
throw target.convertException(e);
} finally {
try {
if (inMem != null)
inMem.close();
} finally {
if (outMem != null)
outMem.close();
}
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformCacheEntryFilterImpl method apply.
/**
* {@inheritDoc}
*/
@Override
public boolean apply(Object k, Object v) {
assert ptr != 0;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(ptr);
writer.writeObject(k);
try {
if (platfromCacheEnabled) {
// Normally, platform cache already has the value.
// Put value to platform thread local so it can be requested when missing.
writer.writeBoolean(false);
ctx.kernalContext().platform().setThreadLocal(v);
} else {
writer.writeBoolean(true);
writer.writeObject(v);
}
out.synchronize();
return ctx.gateway().cacheEntryFilterApply(mem.pointer()) != 0;
} finally {
if (platfromCacheEnabled) {
ctx.kernalContext().platform().setThreadLocal(null);
}
}
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformContextImpl method updatePlatformCache.
/**
* {@inheritDoc}
*/
@Override
public void updatePlatformCache(int cacheId, byte[] keyBytes, byte[] valBytes, int part, AffinityTopologyVersion ver) {
if (!isPlatformCacheSupported())
return;
Boolean useTls = platformCacheUpdateUseThreadLocal.get();
if (useTls != null && useTls) {
long cacheIdAndPartition = ((long) part << 32) | cacheId;
gateway().platformCacheUpdateFromThreadLocal(cacheIdAndPartition, ver.topologyVersion(), ver.minorTopologyVersion());
return;
}
assert keyBytes != null;
assert part >= 0;
try (PlatformMemory mem0 = mem.allocate()) {
PlatformOutputStream out = mem0.output();
out.writeInt(cacheId);
out.writeByteArray(keyBytes);
if (valBytes != null) {
out.writeBoolean(true);
out.writeByteArray(valBytes);
assert ver != null;
out.writeInt(part);
out.writeLong(ver.topologyVersion());
out.writeInt(ver.minorTopologyVersion());
} else {
out.writeBoolean(false);
}
out.synchronize();
gateway().platformCacheUpdate(mem0.pointer());
}
}
Aggregations