Search in sources :

Example 6 with PlatformOutputStream

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

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

the class PlatformTargetProxyImpl method outStream.

/**
 * {@inheritDoc}
 */
@Override
public void outStream(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        target.processOutStream(type, writer);
        out.synchronize();
    } catch (Exception e) {
        throw target.convertException(e);
    }
}
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) IgniteException(org.apache.ignite.IgniteException)

Example 8 with PlatformOutputStream

use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream 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 9 with PlatformOutputStream

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

the class PlatformCacheEntryFilterImpl method apply.

/**
 * {@inheritDoc}
 */
@Override
public boolean apply(Object k, Object v) {
    assert ptr != 0;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeLong(ptr);
        writer.writeObject(k);
        try {
            if (platfromCacheEnabled) {
                // Normally, platform cache already has the value.
                // Put value to platform thread local so it can be requested when missing.
                writer.writeBoolean(false);
                ctx.kernalContext().platform().setThreadLocal(v);
            } else {
                writer.writeBoolean(true);
                writer.writeObject(v);
            }
            out.synchronize();
            return ctx.gateway().cacheEntryFilterApply(mem.pointer()) != 0;
        } finally {
            if (platfromCacheEnabled) {
                ctx.kernalContext().platform().setThreadLocal(null);
            }
        }
    }
}
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 10 with PlatformOutputStream

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

the class PlatformContextImpl method updatePlatformCache.

/**
 * {@inheritDoc}
 */
@Override
public void updatePlatformCache(int cacheId, byte[] keyBytes, byte[] valBytes, int part, AffinityTopologyVersion ver) {
    if (!isPlatformCacheSupported())
        return;
    Boolean useTls = platformCacheUpdateUseThreadLocal.get();
    if (useTls != null && useTls) {
        long cacheIdAndPartition = ((long) part << 32) | cacheId;
        gateway().platformCacheUpdateFromThreadLocal(cacheIdAndPartition, ver.topologyVersion(), ver.minorTopologyVersion());
        return;
    }
    assert keyBytes != null;
    assert part >= 0;
    try (PlatformMemory mem0 = mem.allocate()) {
        PlatformOutputStream out = mem0.output();
        out.writeInt(cacheId);
        out.writeByteArray(keyBytes);
        if (valBytes != null) {
            out.writeBoolean(true);
            out.writeByteArray(valBytes);
            assert ver != null;
            out.writeInt(part);
            out.writeLong(ver.topologyVersion());
            out.writeInt(ver.minorTopologyVersion());
        } else {
            out.writeBoolean(false);
        }
        out.synchronize();
        gateway().platformCacheUpdate(mem0.pointer());
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Aggregations

PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)51 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)48 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)46 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteException (org.apache.ignite.IgniteException)7 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)4 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)3 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)3 Nullable (org.jetbrains.annotations.Nullable)3 CacheException (javax.cache.CacheException)2 PlatformTargetProxyImpl (org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1