Search in sources :

Example 31 with PlatformMemory

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

the class PlatformUtils method evaluateContinuousQueryEvent.

/**
 * Evaluate the filter.
 *
 * @param ctx Context.
 * @param filterPtr Native filter pointer.
 * @param evt Event.
 * @return Result.
 * @throws CacheEntryListenerException In case of failure.
 */
public static boolean evaluateContinuousQueryEvent(PlatformContext ctx, long filterPtr, CacheEntryEvent evt) throws CacheEntryListenerException {
    assert filterPtr != 0;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        out.writeLong(filterPtr);
        writeCacheEntryEvent(ctx.writer(out), evt);
        out.synchronize();
        return ctx.gateway().continuousQueryFilterApply(mem.pointer()) == 1;
    } catch (Exception e) {
        throw toCacheEntryListenerException(e);
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) CacheException(javax.cache.CacheException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException)

Example 32 with PlatformMemory

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

the class PlatformAbstractJob method createJob.

/**
 * Create job in native platform if needed.
 *
 * @param ctx Context.
 * @return {@code True} if job was created, {@code false} if this is local job and creation is not necessary.
 * @throws org.apache.ignite.IgniteCheckedException If failed.
 */
protected boolean createJob(PlatformContext ctx) throws IgniteCheckedException {
    if (ptr == 0) {
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeObject(job);
            out.synchronize();
            ptr = ctx.gateway().computeJobCreate(mem.pointer());
        }
        return true;
    } else
        return false;
}
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 33 with PlatformMemory

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

the class PlatformAbstractTask method result.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" })
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
    assert rcvd.isEmpty() : "Should not cache result in Java for interop task";
    lock.readLock().lock();
    try {
        assert !done;
        PlatformAbstractJob job = res.getJob();
        assert job.pointer() != 0;
        Object res0bj = res.getData();
        int plc;
        if (res0bj == PlatformAbstractJob.LOC_JOB_RES)
            // Processing local job execution result.
            plc = ctx.gateway().computeTaskLocalJobResult(taskPtr, job.pointer());
        else {
            // Processing remote job execution result or exception.
            try (PlatformMemory mem = ctx.memory().allocate()) {
                PlatformOutputStream out = mem.output();
                BinaryRawWriterEx writer = ctx.writer(out);
                writer.writeLong(taskPtr);
                writer.writeLong(job.pointer());
                writer.writeUuid(res.getNode().id());
                writer.writeBoolean(res.isCancelled());
                IgniteException err = res.getException();
                PlatformUtils.writeInvocationResult(writer, res0bj, err);
                out.synchronize();
                plc = ctx.gateway().computeTaskJobResult(mem.pointer());
            }
        }
        ComputeJobResultPolicy plc0 = ComputeJobResultPolicy.fromOrdinal((byte) plc);
        assert plc0 != null : plc;
        return plc0;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) 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 34 with PlatformMemory

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

the class PlatformAbstractTask method onDone.

/**
 * Callback invoked when task future is completed and all resources could be safely cleaned up.
 *
 * @param e If failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void onDone(Exception e) {
    lock.writeLock().lock();
    try {
        assert !done;
        if (e == null)
            // Normal completion.
            ctx.gateway().computeTaskComplete(taskPtr, 0);
        else {
            PlatformNativeException e0 = X.cause(e, PlatformNativeException.class);
            try (PlatformMemory mem = ctx.memory().allocate()) {
                PlatformOutputStream out = mem.output();
                BinaryRawWriterEx writer = ctx.writer(out);
                if (e0 == null) {
                    writer.writeBoolean(false);
                    writer.writeString(e.getClass().getName());
                    writer.writeString(e.getMessage());
                    writer.writeString(X.getFullStackTrace(e));
                } else {
                    writer.writeBoolean(true);
                    writer.writeObject(e0.cause());
                }
                out.synchronize();
                ctx.gateway().computeTaskComplete(taskPtr, mem.pointer());
            }
        }
    } finally {
        // Done flag is set irrespective of any exceptions.
        done = true;
        lock.writeLock().unlock();
    }
}
Also used : PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException) 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 35 with PlatformMemory

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

the class PlatformClosureJob method execute0.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Object execute0(PlatformContext ctx) throws IgniteCheckedException {
    if (task == null) {
        // Remote job execution.
        assert ptr == 0;
        createJob(ctx);
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            out.writeLong(ptr);
            // cancel
            out.writeBoolean(false);
            out.synchronize();
            ctx.gateway().computeJobExecute(mem.pointer());
            PlatformInputStream in = mem.input();
            in.synchronize();
            BinaryRawReaderEx reader = ctx.reader(in);
            return PlatformUtils.readInvocationResult(ctx, reader);
        } finally {
            ctx.gateway().computeJobDestroy(ptr);
        }
    } else {
        // Local job execution.
        assert ptr != 0;
        return runLocal(ctx, false);
    }
}
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)

Aggregations

PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)47 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)43 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)42 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)13 IgniteException (org.apache.ignite.IgniteException)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)8 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)3 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)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 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1