Search in sources :

Example 11 with PlatformMemory

use of org.apache.ignite.internal.processors.platform.memory.PlatformMemory 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 12 with PlatformMemory

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

the class PlatformFullTask method map.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) {
    assert arg == null;
    lock.readLock().lock();
    try {
        assert !done;
        Collection<ClusterNode> nodes = compute.clusterGroup().nodes();
        PlatformMemoryManager memMgr = ctx.memory();
        try (PlatformMemory mem = memMgr.allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeLong(taskPtr);
            write(writer, nodes, subgrid);
            out.synchronize();
            ctx.gateway().computeTaskMap(mem.pointer());
            PlatformInputStream in = mem.input();
            in.synchronize();
            BinaryRawReaderEx reader = ctx.reader(in);
            return read(reader, nodes);
        }
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) PlatformMemoryManager(org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManager) 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) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with PlatformMemory

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

Example 14 with PlatformMemory

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

the class PlatformDotNetConfigurationClosure method prepare.

/**
 * Prepare .Net size.
 *
 * @param igniteCfg Ignite configuration.
 * @param interopCfg Interop configuration.
 */
@SuppressWarnings("ConstantConditions")
private void prepare(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx interopCfg) {
    cfg = igniteCfg;
    try (PlatformMemory outMem = memMgr.allocate()) {
        try (PlatformMemory inMem = memMgr.allocate()) {
            PlatformOutputStream out = outMem.output();
            GridBinaryMarshaller marshaller = PlatformUtils.marshaller();
            BinaryRawWriterEx writer = marshaller.writer(out);
            PlatformConfigurationUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
            // Write .NET beans
            List<PlatformDotNetLifecycleBean> beans = beans(igniteCfg);
            writer.writeInt(beans.size());
            for (PlatformDotNetLifecycleBean bean : beans) {
                writer.writeString(bean.getTypeName());
                writer.writeMap(bean.getProperties());
            }
            // Write .NET affinity functions
            List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(igniteCfg);
            writer.writeInt(affFuncs.size());
            for (PlatformDotNetAffinityFunction func : affFuncs) {
                writer.writeString(func.getTypeName());
                writer.writeMap(func.getProperties());
            }
            out.synchronize();
            gate.extensionCallbackInLongLongOutLong(PlatformUtils.OP_PREPARE_DOT_NET, outMem.pointer(), inMem.pointer());
            processPrepareResult(marshaller.reader(inMem.input()));
        }
    }
}
Also used : GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) 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) PlatformDotNetLifecycleBean(org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean)

Example 15 with PlatformMemory

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

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