Search in sources :

Example 51 with BinaryRawWriterEx

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

the class PlatformAbstractTask method result.

/**
 * {@inheritDoc}
 */
@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 52 with BinaryRawWriterEx

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

the class PlatformTransactions method processOutStream.

/**
 * {@inheritDoc}
 */
@Override
public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
    switch(type) {
        case OP_CACHE_CONFIG_PARAMETERS:
            TransactionConfiguration txCfg = platformCtx.kernalContext().config().getTransactionConfiguration();
            writer.writeInt(txCfg.getDefaultTxConcurrency().ordinal());
            writer.writeInt(txCfg.getDefaultTxIsolation().ordinal());
            writer.writeLong(txCfg.getDefaultTxTimeout());
            writer.writeLong(txCfg.getTxTimeoutOnPartitionMapExchange());
            break;
        case OP_METRICS:
            TransactionMetrics metrics = txs.metrics();
            writer.writeTimestamp(new Timestamp(metrics.commitTime()));
            writer.writeTimestamp(new Timestamp(metrics.rollbackTime()));
            writer.writeInt(metrics.txCommits());
            writer.writeInt(metrics.txRollbacks());
            break;
        case OP_LOCAL_ACTIVE_TX:
            Collection<Transaction> activeTxs = txs.localActiveTransactions();
            PlatformUtils.writeCollection(writer, activeTxs, new PlatformWriterClosure<Transaction>() {

                @Override
                public void write(BinaryRawWriterEx writer, Transaction tx) {
                    writer.writeLong(registerTx(tx));
                    writer.writeInt(tx.concurrency().ordinal());
                    writer.writeInt(tx.isolation().ordinal());
                    writer.writeLong(tx.timeout());
                    writer.writeString(tx.label());
                }
            });
            break;
        default:
            super.processOutStream(type, writer);
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(org.apache.ignite.transactions.Transaction) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics) Timestamp(java.sql.Timestamp) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Example 53 with BinaryRawWriterEx

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

the class PlatformFutureUtils method writeFutureError.

/**
 * Write future error.
 *
 * @param ctx Context.
 * @param futPtr Future pointer.
 * @param err Error.
 */
private static void writeFutureError(final PlatformContext ctx, long futPtr, Throwable err) {
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx outWriter = ctx.writer(out);
        PlatformUtils.writeError(err, outWriter);
        PlatformUtils.writeErrorData(err, outWriter);
        out.synchronize();
        ctx.gateway().futureError(futPtr, mem.pointer());
    }
}
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 54 with BinaryRawWriterEx

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

the class PlatformFutureUtils method writeToWriter.

/**
 * Write result to a custom writer
 *
 * @param obj Object to write.
 * @param err Error to write.
 * @param ctx Context.
 * @param writer Writer.
 * @param futPtr Future pointer.
 * @return Value indicating whether custom write was performed. When false, default write will be used.
 */
private static boolean writeToWriter(Object obj, Throwable err, PlatformContext ctx, Writer writer, long futPtr) {
    boolean canWrite = writer.canWrite(obj, err);
    if (!canWrite)
        return false;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx outWriter = ctx.writer(out);
        writer.write(outWriter, obj, err);
        out.synchronize();
        ctx.gateway().futureObjectResult(futPtr, mem.pointer());
    }
    return true;
}
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 55 with BinaryRawWriterEx

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

the class PlatformFutureUtils method listen.

/**
 * Listen future.
 *
 * @param ctx Context.
 * @param listenable Listenable entry.
 * @param futPtr Native future pointer.
 * @param typ Expected return type.
 * @param writer Optional writer.
 */
public static void listen(final PlatformContext ctx, PlatformListenable listenable, final long futPtr, final int typ, @Nullable final Writer writer, final PlatformTarget target) {
    final PlatformCallbackGateway gate = ctx.gateway();
    listenable.listen(new IgniteBiInClosure<Object, Throwable>() {

        private static final long serialVersionUID = 0L;

        @Override
        public void apply(Object res, Throwable err) {
            if (err instanceof Exception)
                err = target.convertException((Exception) err);
            if (writer != null && writeToWriter(res, err, ctx, writer, futPtr))
                return;
            if (err != null) {
                writeFutureError(ctx, futPtr, err);
                return;
            }
            try {
                if (typ == TYP_OBJ) {
                    if (res == null)
                        gate.futureNullResult(futPtr);
                    else {
                        try (PlatformMemory mem = ctx.memory().allocate()) {
                            PlatformOutputStream out = mem.output();
                            BinaryRawWriterEx outWriter = ctx.writer(out);
                            outWriter.writeObjectDetached(res);
                            out.synchronize();
                            gate.futureObjectResult(futPtr, mem.pointer());
                        }
                    }
                } else if (res == null)
                    gate.futureNullResult(futPtr);
                else {
                    switch(typ) {
                        case TYP_BYTE:
                            gate.futureByteResult(futPtr, (byte) res);
                            break;
                        case TYP_BOOL:
                            gate.futureBoolResult(futPtr, (boolean) res ? 1 : 0);
                            break;
                        case TYP_SHORT:
                            gate.futureShortResult(futPtr, (short) res);
                            break;
                        case TYP_CHAR:
                            gate.futureCharResult(futPtr, (char) res);
                            break;
                        case TYP_INT:
                            gate.futureIntResult(futPtr, (int) res);
                            break;
                        case TYP_FLOAT:
                            gate.futureFloatResult(futPtr, Float.floatToIntBits((float) res));
                            break;
                        case TYP_LONG:
                            gate.futureLongResult(futPtr, (long) res);
                            break;
                        case TYP_DOUBLE:
                            gate.futureDoubleResult(futPtr, Double.doubleToLongBits((double) res));
                            break;
                        default:
                            assert false : "Should not reach this: " + typ;
                    }
                }
            } catch (Throwable t) {
                writeFutureError(ctx, futPtr, t);
                if (t instanceof Error)
                    throw t;
            }
        }
    });
}
Also used : PlatformCallbackGateway(org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Aggregations

BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)60 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)46 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)45 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteException (org.apache.ignite.IgniteException)8 Map (java.util.Map)5 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)5 HashMap (java.util.HashMap)4 Nullable (org.jetbrains.annotations.Nullable)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)3 Array (java.lang.reflect.Array)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Arrays (java.util.Arrays)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2