Search in sources :

Example 41 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx in project ignite by apache.

the class PlatformTargetProxyImpl method inStreamOutStream.

/**
 * {@inheritDoc}
 */
@Override
public void inStreamOutStream(int type, long inMemPtr, long outMemPtr) throws Exception {
    try (PlatformMemory inMem = platformCtx.memory().get(inMemPtr)) {
        BinaryRawReaderEx reader = platformCtx.reader(inMem);
        try (PlatformMemory outMem = platformCtx.memory().get(outMemPtr)) {
            PlatformOutputStream out = outMem.output();
            BinaryRawWriterEx writer = platformCtx.writer(out);
            target.processInStreamOutStream(type, reader, writer);
            out.synchronize();
        }
    } catch (Exception e) {
        throw target.convertException(e);
    }
}
Also used : BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) IgniteException(org.apache.ignite.IgniteException)

Example 42 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx in project ignite by apache.

the class PlatformTargetProxyImpl method inStreamOutListenableAsync.

/**
 * Performs asyncronous operation.
 *
 * @param type Type.
 * @param memPtr Stream pointer.
 * @return Listenable.
 * @throws Exception On error.
 */
private PlatformListenable inStreamOutListenableAsync(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
        BinaryRawReaderEx reader = platformCtx.reader(mem);
        long futId = reader.readLong();
        int futTyp = reader.readInt();
        final PlatformAsyncResult res = target.processInStreamAsync(type, reader);
        if (res == null)
            throw new IgniteException("PlatformTarget.processInStreamAsync should not return null.");
        IgniteFuture fut = res.future();
        if (fut == null)
            throw new IgniteException("PlatformAsyncResult.future() should not return null.");
        return PlatformFutureUtils.listen(platformCtx, fut, futId, futTyp, new PlatformFutureUtils.Writer() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
                res.write(writer, obj);
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean canWrite(Object obj, Throwable err) {
                return err == null;
            }
        }, target);
    } catch (Exception e) {
        throw target.convertException(e);
    }
}
Also used : PlatformFutureUtils(org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils) IgniteFuture(org.apache.ignite.lang.IgniteFuture) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) IgniteException(org.apache.ignite.IgniteException) IgniteException(org.apache.ignite.IgniteException) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 43 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx in project ignite by apache.

the class PlatformCache method writeResult.

/**
 * Writes the result to reused stream, if any.
 */
public long writeResult(PlatformMemory mem, Object obj, PlatformWriterClosure clo) {
    if (obj == null)
        return FALSE;
    PlatformOutputStream out = mem.output();
    BinaryRawWriterEx writer = platformCtx.writer(out);
    if (clo == null)
        writer.writeObjectDetached(obj);
    else
        clo.write(writer, obj);
    out.synchronize();
    return TRUE;
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Example 44 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx in project ignite by apache.

the class PlatformCacheEntryProcessorImpl method execute0.

/**
 * Executes interop entry processor on a given entry, updates entry and returns result.
 *
 * @param ctx Context.
 * @param entry Entry.
 * @return Processing result.
 */
private Object execute0(PlatformContext ctx, MutableEntry entry) {
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writeEntryAndProcessor(entry, writer);
        out.synchronize();
        ctx.gateway().cacheInvoke(mem.pointer());
        PlatformInputStream in = mem.input();
        in.synchronize();
        BinaryRawReaderEx reader = ctx.reader(in);
        return readResultAndUpdateEntry(ctx, entry, reader);
    }
}
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 45 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx in project ignite by apache.

the class PlatformAffinityFunction method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteException {
    // userFunc is null when there is nothing overridden
    if (userFunc == null)
        return;
    assert ignite != null;
    ctx = PlatformUtils.platformContext(ignite);
    assert ctx != null;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(userFunc);
        out.synchronize();
        baseTarget = baseFunc != null ? new PlatformAffinityFunctionTarget(ctx, baseFunc) : null;
        PlatformTargetProxyImpl baseTargetProxy = baseTarget != null ? new PlatformTargetProxyImpl(baseTarget, ctx) : null;
        ptr = ctx.gateway().affinityFunctionInit(mem.pointer(), baseTargetProxy);
    }
}
Also used : PlatformTargetProxyImpl(org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Aggregations

BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)50 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)43 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)42 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteException (org.apache.ignite.IgniteException)8 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)5 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)3 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)2 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)2 PlatformTargetProxyImpl (org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl)2 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 Nullable (org.jetbrains.annotations.Nullable)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1