Search in sources :

Example 11 with BinaryRawReaderEx

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

the class PlatformFullTask method map.

/**
 * {@inheritDoc}
 */
@NotNull
@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) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with BinaryRawReaderEx

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

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

the class PlatformJavaObjectFactoryProxy method readBinary.

/**
 * {@inheritDoc}
 */
@Override
public void readBinary(BinaryReader reader) throws BinaryObjectException {
    BinaryRawReaderEx rawReader = (BinaryRawReaderEx) reader.rawReader();
    factoryTyp = rawReader.readInt();
    clsName = rawReader.readString();
    payload = rawReader.readObjectDetached();
    int propsSize = rawReader.readInt();
    if (propsSize > 0) {
        props = new HashMap<>(propsSize);
        for (int i = 0; i < propsSize; i++) {
            String key = rawReader.readString();
            Object val = rawReader.readObjectDetached();
            props.put(key, val);
        }
    }
}
Also used : BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx)

Example 14 with BinaryRawReaderEx

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

the class PlatformTargetProxyImpl method inObjectStreamOutObjectStream.

/**
 * {@inheritDoc}
 */
@Override
public Object inObjectStreamOutObjectStream(int type, Object arg, long inMemPtr, long outMemPtr) throws Exception {
    PlatformMemory inMem = null;
    PlatformMemory outMem = null;
    try {
        BinaryRawReaderEx reader = null;
        if (inMemPtr != 0) {
            inMem = platformCtx.memory().get(inMemPtr);
            reader = platformCtx.reader(inMem);
        }
        PlatformOutputStream out = null;
        BinaryRawWriterEx writer = null;
        if (outMemPtr != 0) {
            outMem = platformCtx.memory().get(outMemPtr);
            out = outMem.output();
            writer = platformCtx.writer(out);
        }
        PlatformTarget res = target.processInObjectStreamOutObjectStream(type, unwrapProxy(arg), reader, writer);
        if (out != null)
            out.synchronize();
        return wrapProxy(res);
    } catch (Exception e) {
        throw target.convertException(e);
    } finally {
        try {
            if (inMem != null)
                inMem.close();
        } finally {
            if (outMem != null)
                outMem.close();
        }
    }
}
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 15 with BinaryRawReaderEx

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

the class PlatformProcessorImpl method createCacheFromConfig.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy createCacheFromConfig(long memPtr) throws IgniteCheckedException {
    BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
    CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
    IgniteCacheProxy cache = reader.readBoolean() ? (IgniteCacheProxy) ctx.grid().createCache(cfg, PlatformConfigurationUtils.readNearConfiguration(reader)) : (IgniteCacheProxy) ctx.grid().createCache(cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)21 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)14 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)13 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 Nullable (org.jetbrains.annotations.Nullable)3 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)2 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)1 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)1