Search in sources :

Example 21 with BinaryRawWriterEx

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

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

the class PlatformAbstractService method execute.

/** {@inheritDoc} */
@Override
public void execute(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.writeLong(ptr);
        writer.writeBoolean(srvKeepBinary);
        writeServiceContext(ctx, writer);
        out.synchronize();
        platformCtx.gateway().serviceExecute(mem.pointer());
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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 23 with BinaryRawWriterEx

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

the class PlatformUtils method errorData.

/**
     * Get error data.
     *
     * @param err Error.
     * @return Error data.
     */
@SuppressWarnings("UnusedDeclaration")
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 24 with BinaryRawWriterEx

use of org.apache.ignite.internal.binary.BinaryRawWriterEx 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)

Example 25 with BinaryRawWriterEx

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

the class PlatformEventFilterListenerImpl method initialize.

/** {@inheritDoc} */
@Override
public void initialize(GridKernalContext gridCtx) {
    ctx = PlatformUtils.platformContext(gridCtx.grid());
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObjectDetached(pred);
        out.synchronize();
        hnd = ctx.gateway().eventFilterCreate(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)

Aggregations

BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)46 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)41 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)39 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteException (org.apache.ignite.IgniteException)6 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)3 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)2 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)2 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)2 PlatformTargetProxyImpl (org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl)2 Nullable (org.jetbrains.annotations.Nullable)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1