Search in sources :

Example 11 with PlatformOutputStream

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

the class PlatformContinuousQueryRemoteFilter method deploy.

/**
 * Deploy filter to native platform.
 */
private void deploy() {
    lock.writeLock().lock();
    try {
        // 1. Do not deploy if the filter has been closed concurrently.
        if (closed)
            throw new CacheEntryListenerException("Failed to deploy the filter because it has been closed.");
        // 2. Deploy.
        PlatformContext ctx = PlatformUtils.platformContext(grid);
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeObject(filter);
            out.synchronize();
            ptr = ctx.gateway().continuousQueryFilterCreate(mem.pointer());
        } catch (Exception e) {
            // 3. Close in case of failure.
            close();
            throw new CacheEntryListenerException("Failed to deploy the filter.", e);
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) 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) IOException(java.io.IOException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 12 with PlatformOutputStream

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

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

the class PlatformDotNetCacheStore method doInvoke.

/**
 * Perform actual invoke.
 *
 * @param task Task.
 * @param readClo Reader.
 * @return Result.
 * @throws org.apache.ignite.IgniteCheckedException If failed.
 */
protected int doInvoke(IgniteInClosure<BinaryRawWriterEx> task, IgniteInClosure<BinaryRawReaderEx> readClo) throws IgniteCheckedException {
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeLong(ptr);
        task.apply(writer);
        out.synchronize();
        int res = platformCtx.gateway().cacheStoreInvoke(mem.pointer());
        if (res != 0) {
            // Read error
            Object nativeErr = platformCtx.reader(mem.input()).readObjectDetached();
            throw platformCtx.createNativeException(nativeErr);
        }
        if (readClo != null) {
            BinaryRawReaderEx reader = platformCtx.reader(mem);
            readClo.apply(reader);
        }
        return res;
    }
}
Also used : 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 14 with PlatformOutputStream

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

the class PlatformClusterNodeFilterImpl method apply.

/**
 * {@inheritDoc}
 */
@Override
public boolean apply(ClusterNode clusterNode) {
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(pred);
        ctx.writeNode(writer, clusterNode);
        out.synchronize();
        return ctx.gateway().clusterNodeFilterApply(mem.pointer()) != 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 15 with PlatformOutputStream

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

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