Search in sources :

Example 1 with PlatformMemory

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

the class PlatformProcessorImpl method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    try (PlatformMemory mem = platformCtx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = platformCtx.writer(out);
        writer.writeString(ctx.igniteInstanceName());
        out.synchronize();
        platformCtx.gateway().onStart(this, mem.pointer());
    }
    // At this moment all necessary native libraries must be loaded, so we can process with store creation.
    storeLock.writeLock().lock();
    try {
        for (StoreInfo store : pendingStores) registerStore0(store.store, store.convertBinary);
        pendingStores.clear();
        started = true;
    } finally {
        storeLock.writeLock().unlock();
    }
    // Add Interop node attributes.
    ctx.addNodeAttribute(PlatformUtils.ATTR_PLATFORM, interopCfg.platform());
}
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 2 with PlatformMemory

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

the class PlatformTargetProxyImpl method inStreamAsync.

/** {@inheritDoc} */
@Override
public void inStreamAsync(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
        BinaryRawReaderEx reader = platformCtx.reader(mem);
        long futId = reader.readLong();
        int futTyp = reader.readInt();
        final PlatformAsyncResult res = target.processInStreamAsync(type, reader);
        if (res == null)
            throw new IgniteException("PlatformTarget.processInStreamAsync should not return null.");
        IgniteFuture fut = res.future();
        if (fut == null)
            throw new IgniteException("PlatformAsyncResult.future() should not return null.");
        PlatformFutureUtils.listen(platformCtx, fut, futId, futTyp, new PlatformFutureUtils.Writer() {

            /** {@inheritDoc} */
            @Override
            public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
                res.write(writer, obj);
            }

            /** {@inheritDoc} */
            @Override
            public boolean canWrite(Object obj, Throwable err) {
                return err == null;
            }
        }, target);
    } catch (Exception e) {
        throw target.convertException(e);
    }
}
Also used : PlatformFutureUtils(org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils) IgniteFuture(org.apache.ignite.lang.IgniteFuture) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) IgniteException(org.apache.ignite.IgniteException) IgniteException(org.apache.ignite.IgniteException) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 3 with PlatformMemory

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

the class PlatformAtomicReference method createInstance.

/**
     * Creates an instance or returns null.
     *
     * @param ctx Context.
     * @param name Name.
     * @param memPtr Pointer to a stream with initial value. 0 for default value.
     * @param create Create flag.
     * @return Instance of a PlatformAtomicReference, or null when Ignite reference with specific name is null.
     */
public static PlatformAtomicReference createInstance(PlatformContext ctx, String name, long memPtr, boolean create) {
    assert ctx != null;
    assert name != null;
    Object initVal = null;
    if (memPtr != 0) {
        try (PlatformMemory mem = ctx.memory().get(memPtr)) {
            initVal = ctx.reader(mem).readObjectDetached();
        }
    }
    GridCacheAtomicReferenceImpl atomicRef = (GridCacheAtomicReferenceImpl) ctx.kernalContext().grid().atomicReference(name, initVal, create);
    if (atomicRef == null)
        return null;
    return new PlatformAtomicReference(ctx, atomicRef);
}
Also used : GridCacheAtomicReferenceImpl(org.apache.ignite.internal.processors.datastructures.GridCacheAtomicReferenceImpl) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 4 with PlatformMemory

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

the class PlatformCacheEntryFilterImpl method setIgniteInstance.

/**
 * @param ignite Ignite instance.
 */
@IgniteInstanceResource
public void setIgniteInstance(Ignite ignite) {
    ctx = PlatformUtils.platformContext(ignite);
    if (ptr != 0)
        return;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(pred);
        out.synchronize();
        ptr = ctx.gateway().cacheEntryFilterCreate(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) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource)

Example 5 with PlatformMemory

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

Aggregations

PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)52 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)48 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)45 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)14 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)11 IgniteException (org.apache.ignite.IgniteException)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 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 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1