use of org.apache.ignite.internal.binary.BinaryRawReaderEx 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.binary.BinaryRawReaderEx 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.binary.BinaryRawReaderEx in project ignite by apache.
the class PlatformDotNetCacheStore method loadAll.
/**
* {@inheritDoc}
*/
@Override
public Map<K, V> loadAll(final Iterable<? extends K> keys) {
try {
final Map<K, V> loaded = new HashMap<>();
final Collection keys0 = (Collection) keys;
doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
@Override
public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD_ALL);
writer.writeLong(session());
writer.writeString(ses.cacheName());
writer.writeInt(keys0.size());
for (Object o : keys0) writer.writeObject(o);
}
}, new IgniteInClosureX<BinaryRawReaderEx>() {
@Override
public void applyx(BinaryRawReaderEx reader) {
int cnt = reader.readInt();
for (int i = 0; i < cnt; i++) loaded.put((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
}
});
return loaded;
} catch (IgniteCheckedException e) {
throw new CacheLoaderException(e);
}
}
use of org.apache.ignite.internal.binary.BinaryRawReaderEx in project ignite by apache.
the class PlatformDotNetCacheStore method load.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public V load(final K key) {
try {
final GridTuple<V> val = new GridTuple<>();
doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
@Override
public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD);
writer.writeLong(session());
writer.writeString(ses.cacheName());
writer.writeObject(key);
}
}, new IgniteInClosureX<BinaryRawReaderEx>() {
@Override
public void applyx(BinaryRawReaderEx reader) {
val.set((V) reader.readObjectDetached());
}
});
return val.get();
} catch (IgniteCheckedException e) {
throw new CacheLoaderException(e);
}
}
use of org.apache.ignite.internal.binary.BinaryRawReaderEx 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;
}
}
Aggregations