Search in sources :

Example 1 with PlatformInputStream

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

the class PlatformAbstractService method invokeMethod.

/**
 * {@inheritDoc}
 */
@Override
public Object invokeMethod(String mthdName, boolean srvKeepBinary, Object[] args) throws IgniteCheckedException {
    assert ptr != 0;
    assert platformCtx != null;
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeLong(ptr);
        writer.writeBoolean(srvKeepBinary);
        writer.writeString(mthdName);
        if (args == null)
            writer.writeBoolean(false);
        else {
            writer.writeBoolean(true);
            writer.writeInt(args.length);
            for (Object arg : args) writer.writeObjectDetached(arg);
        }
        out.synchronize();
        platformCtx.gateway().serviceInvokeMethod(mem.pointer());
        PlatformInputStream in = mem.input();
        in.synchronize();
        BinaryRawReaderEx reader = platformCtx.reader(in);
        return PlatformUtils.readInvocationResult(platformCtx, reader);
    }
}
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) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 2 with PlatformInputStream

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

the class PlatformUtils method errorData.

/**
 * Get error data.
 *
 * @param err Error.
 * @return Error data.
 */
public static byte[] errorData(Throwable err) {
    if (err instanceof PlatformExtendedException) {
        PlatformContext ctx = ((PlatformExtendedException) err).context();
        try (PlatformMemory mem = ctx.memory().allocate()) {
            // Write error data.
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            try {
                PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class));
            } finally {
                out.synchronize();
            }
            // Read error data into separate array.
            PlatformInputStream in = mem.input();
            in.synchronize();
            int len = in.remaining();
            assert len > 0;
            byte[] arr = in.array();
            byte[] res = new byte[len];
            System.arraycopy(arr, 0, res, 0, len);
            return res;
        }
    } else
        return null;
}
Also used : PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) 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 3 with PlatformInputStream

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

the class PlatformAbstractService method invokeMethod.

/**
 * {@inheritDoc}
 */
@Override
public Object invokeMethod(String mthdName, boolean srvKeepBinary, boolean deserializeResult, @Nullable Object[] args, @Nullable Map<String, Object> callAttrs) throws IgniteCheckedException {
    assert ptr != 0;
    assert platformCtx != null;
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeLong(ptr);
        writer.writeBoolean(srvKeepBinary);
        writer.writeString(mthdName);
        if (args == null)
            writer.writeBoolean(false);
        else {
            writer.writeBoolean(true);
            writer.writeInt(args.length);
            for (Object arg : args) writer.writeObjectDetached(arg);
        }
        writer.writeMap(callAttrs);
        out.synchronize();
        platformCtx.gateway().serviceInvokeMethod(mem.pointer());
        PlatformInputStream in = mem.input();
        in.synchronize();
        BinaryRawReaderEx reader = platformCtx.reader(in);
        return PlatformUtils.readInvocationResult(platformCtx, reader, deserializeResult);
    }
}
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) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 4 with PlatformInputStream

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

the class PlatformAbstractService method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(ServiceContext ctx) throws Exception {
    assert ptr == 0;
    assert platformCtx != null;
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeBoolean(srvKeepBinary);
        writer.writeObject(svc);
        writeServiceContext(ctx, writer);
        out.synchronize();
        ptr = platformCtx.gateway().serviceInit(mem.pointer());
        PlatformInputStream in = mem.input();
        in.synchronize();
        BinaryRawReaderEx reader = platformCtx.reader(in);
        PlatformUtils.readInvocationResult(platformCtx, reader);
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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)

Example 5 with PlatformInputStream

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

Aggregations

PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)13 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)11 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)10 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)8 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Nullable (org.jetbrains.annotations.Nullable)3 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)2 PlatformExternalMemory (org.apache.ignite.internal.processors.platform.memory.PlatformExternalMemory)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)1 PlatformMemoryManager (org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManager)1 NotNull (org.jetbrains.annotations.NotNull)1