Search in sources :

Example 21 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.

the class PlatformEventFilterListenerImpl method initialize.

/**
 * {@inheritDoc}
 */
@Override
public void initialize(GridKernalContext gridCtx) {
    ctx = PlatformUtils.platformContext(gridCtx.grid());
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObjectDetached(pred);
        out.synchronize();
        hnd = ctx.gateway().eventFilterCreate(mem.pointer());
    }
}
Also used : 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)

Example 22 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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;
    }
}
Also used : 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)

Example 23 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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;
        }
    }
}
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) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.

the class PlatformMessageFilterImpl method initialize.

/**
 * {@inheritDoc}
 */
@Override
public void initialize(GridKernalContext kernalCtx) {
    if (ptr != 0)
        return;
    ctx = PlatformUtils.platformContext(kernalCtx.grid());
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(pred);
        out.synchronize();
        ptr = ctx.gateway().messagingFilterCreate(mem.pointer());
    }
}
Also used : 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)

Example 25 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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)

Aggregations

PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)51 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)48 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)46 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteException (org.apache.ignite.IgniteException)7 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)4 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)3 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)3 Nullable (org.jetbrains.annotations.Nullable)3 CacheException (javax.cache.CacheException)2 PlatformTargetProxyImpl (org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1