Search in sources :

Example 1 with PlatformNativeException

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

the class PlatformLogger method log.

/**
     * Logs the message.
     *
     * @param level Log level.
     * @param msg Message.
     * @param e Exception.
     */
private void log(int level, String msg, @Nullable Throwable e) {
    String errorInfo = null;
    if (e != null)
        errorInfo = X.getFullStackTrace(e);
    PlatformNativeException e0 = X.cause(e, PlatformNativeException.class);
    if (ctx != null && e0 != null) {
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeObject(e0.cause());
            out.synchronize();
            gate.loggerLog(level, msg, category, errorInfo, mem.pointer());
        }
    } else {
        gate.loggerLog(level, msg, category, errorInfo, 0);
    }
}
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 2 with PlatformNativeException

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

the class PlatformUtils method writeError.

/**
     * Writes error.
     *
     * @param ex Error.
     * @param writer Writer.
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static void writeError(Throwable ex, BinaryRawWriterEx writer) {
    writer.writeObjectDetached(ex.getClass().getName());
    writer.writeObjectDetached(ex.getMessage());
    writer.writeObjectDetached(X.getFullStackTrace(ex));
    PlatformNativeException nativeCause = X.cause(ex, PlatformNativeException.class);
    if (nativeCause != null) {
        writer.writeBoolean(true);
        writer.writeObjectDetached(nativeCause.cause());
    } else
        writer.writeBoolean(false);
}
Also used : PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException)

Example 3 with PlatformNativeException

use of org.apache.ignite.internal.processors.platform.PlatformNativeException 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 4 with PlatformNativeException

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

the class PlatformUtils method writeInvocationResult.

/**
     * Writes invocation result (of a job/service/etc) using a common protocol.
     *
     * @param writer Writer.
     * @param resObj Result.
     * @param err Error.
     */
public static void writeInvocationResult(BinaryRawWriterEx writer, Object resObj, Exception err) {
    if (err == null) {
        writer.writeBoolean(true);
        writer.writeObject(resObj);
    } else {
        writer.writeBoolean(false);
        PlatformNativeException nativeErr = null;
        if (err instanceof IgniteCheckedException)
            nativeErr = ((IgniteCheckedException) err).getCause(PlatformNativeException.class);
        else if (err instanceof IgniteException)
            nativeErr = ((IgniteException) err).getCause(PlatformNativeException.class);
        if (nativeErr == null) {
            writer.writeBoolean(false);
            writer.writeString(err.getClass().getName());
            writer.writeString(err.getMessage());
            writer.writeString(X.getFullStackTrace(err));
        } else {
            writer.writeBoolean(true);
            writer.writeObject(nativeErr.cause());
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException)

Aggregations

PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)4 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)2 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)2 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1