Search in sources :

Example 1 with BinaryRawReaderEx

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

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

the class PlatformProcessorImpl method getOrCreateCacheFromConfig.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy getOrCreateCacheFromConfig(long memPtr) throws IgniteCheckedException {
    BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
    CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
    IgniteCacheProxy cache = reader.readBoolean() ? (IgniteCacheProxy) ctx.grid().getOrCreateCache(cfg, PlatformConfigurationUtils.readNearConfiguration(reader)) : (IgniteCacheProxy) ctx.grid().getOrCreateCache(cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 3 with BinaryRawReaderEx

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

the class ClientMessageParser method decode.

/**
 * {@inheritDoc}
 */
@Override
public ClientListenerRequest decode(byte[] msg) {
    assert msg != null;
    BinaryInputStream inStream = new BinaryHeapInputStream(msg);
    // skipHdrCheck must be true (we have 103 op code).
    BinaryRawReaderEx reader = new BinaryReaderExImpl(marsh.context(), inStream, null, null, true, true);
    return decode(reader);
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx)

Example 4 with BinaryRawReaderEx

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

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

the class PlatformUtils method readBinaryMetadata.

/**
 * Reads the binary metadata.
 *
 * @param reader Reader.
 * @return Binary type metadata.
 */
public static BinaryMetadata readBinaryMetadata(BinaryRawReaderEx reader) {
    int typeId = reader.readInt();
    String typeName = reader.readString();
    String affKey = reader.readString();
    Map<String, BinaryFieldMetadata> fields = readLinkedMap(reader, new PlatformReaderBiClosure<String, BinaryFieldMetadata>() {

        @Override
        public IgniteBiTuple<String, BinaryFieldMetadata> read(BinaryRawReaderEx reader) {
            String name = reader.readString();
            int typeId = reader.readInt();
            int fieldId = reader.readInt();
            return new IgniteBiTuple<String, BinaryFieldMetadata>(name, new BinaryFieldMetadata(typeId, fieldId));
        }
    });
    Map<String, Integer> enumMap = null;
    boolean isEnum = reader.readBoolean();
    if (isEnum) {
        int size = reader.readInt();
        enumMap = new LinkedHashMap<>(size);
        for (int idx = 0; idx < size; idx++) enumMap.put(reader.readString(), reader.readInt());
    }
    // Read schemas
    int schemaCnt = reader.readInt();
    List<BinarySchema> schemas = null;
    if (schemaCnt > 0) {
        schemas = new ArrayList<>(schemaCnt);
        for (int i = 0; i < schemaCnt; i++) {
            int id = reader.readInt();
            int fieldCnt = reader.readInt();
            List<Integer> fieldIds = new ArrayList<>(fieldCnt);
            for (int j = 0; j < fieldCnt; j++) fieldIds.add(reader.readInt());
            schemas.add(new BinarySchema(id, fieldIds));
        }
    }
    return new BinaryMetadata(typeId, typeName, fields, affKey, schemas, isEnum, enumMap);
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) BinarySchema(org.apache.ignite.internal.binary.BinarySchema)

Aggregations

BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)21 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)14 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)13 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 Nullable (org.jetbrains.annotations.Nullable)3 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)2 PlatformFutureUtils (org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)1 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)1