Search in sources :

Example 6 with BinaryRawReaderEx

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);
    }
}
Also used : PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 7 with BinaryRawReaderEx

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 8 with BinaryRawReaderEx

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);
    }
}
Also used : HashMap(java.util.HashMap) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheLoaderException(javax.cache.integration.CacheLoaderException) Collection(java.util.Collection) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Example 9 with BinaryRawReaderEx

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheLoaderException(javax.cache.integration.CacheLoaderException) GridTuple(org.apache.ignite.internal.util.lang.GridTuple) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with BinaryRawReaderEx

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;
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Aggregations

BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)21 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)14 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)13 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 Nullable (org.jetbrains.annotations.Nullable)3 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)2 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)1 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)1