Search in sources :

Example 36 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx 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 37 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx 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 38 with BinaryRawWriterEx

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

the class PlatformStreamReceiverImpl method receive.

/**
 * {@inheritDoc}
 */
@Override
public void receive(IgniteCache<Object, Object> cache, Collection<Map.Entry<Object, Object>> collection) throws IgniteException {
    assert ctx != null;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        out.writeLong(ptr);
        out.writeBoolean(keepBinary);
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(pred);
        writer.writeInt(collection.size());
        for (Map.Entry<Object, Object> e : collection) {
            writer.writeObject(e.getKey());
            writer.writeObject(e.getValue());
        }
        out.synchronize();
        PlatformCache cache0 = new PlatformCache(ctx, cache, keepBinary);
        PlatformTargetProxy cacheProxy = new PlatformTargetProxyImpl(cache0, ctx);
        ctx.gateway().dataStreamerStreamReceiverInvoke(ptr, cacheProxy, mem.pointer(), keepBinary);
    }
}
Also used : PlatformCache(org.apache.ignite.internal.processors.platform.cache.PlatformCache) PlatformTargetProxy(org.apache.ignite.internal.processors.platform.PlatformTargetProxy) PlatformTargetProxyImpl(org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) Map(java.util.Map) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 39 with BinaryRawWriterEx

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

the class PlatformDotNetCacheStore method initialize.

/**
 * Initialize the store.
 *
 * @param ctx Context.
 * @param convertBinary Convert binary flag.
 * @throws org.apache.ignite.IgniteCheckedException
 */
public void initialize(GridKernalContext ctx, boolean convertBinary) throws IgniteCheckedException {
    A.ensure(typName != null || nativeFactory != null, "Either typName or nativeFactory must be set in PlatformDotNetCacheStore");
    platformCtx = PlatformUtils.platformContext(ctx.grid());
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        write(writer, convertBinary);
        out.synchronize();
        try {
            ptr = platformCtx.gateway().cacheStoreCreate(mem.pointer());
        } catch (IgniteException e) {
            // CacheAffinitySharedManager.processClientCacheStartRequests()
            throw new IgniteCheckedException("Could not create .NET CacheStore", e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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 40 with BinaryRawWriterEx

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

the class PlatformProcessorImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeString(ctx.igniteInstanceName());
        out.synchronize();
        platformCtx.gateway().onStart(new PlatformTargetProxyImpl(this, platformCtx), mem.pointer());
    }
    // At this moment all necessary native libraries must be loaded, so we can process with store creation.
    storeLock.writeLock().lock();
    try {
        for (StoreInfo store : pendingStores) registerStore0(store.store, store.convertBinary);
        pendingStores.clear();
        started = true;
    } finally {
        storeLock.writeLock().unlock();
    }
    // Add Interop node attributes.
    ctx.addNodeAttribute(PlatformUtils.ATTR_PLATFORM, interopCfg.platform());
}
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)

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