Search in sources :

Example 1 with GridBinaryMarshaller

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

the class ClientBinaryMarshaller method createImpl.

/**
 * Create new marshaller implementation.
 */
private GridBinaryMarshaller createImpl(BinaryConfiguration binCfg) {
    IgniteConfiguration igniteCfg = new IgniteConfiguration();
    if (binCfg == null) {
        binCfg = new BinaryConfiguration();
        binCfg.setCompactFooter(false);
    }
    igniteCfg.setBinaryConfiguration(binCfg);
    BinaryContext ctx = new BinaryContext(metaHnd, igniteCfg, new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(marshCtx);
    ctx.configure(marsh, binCfg);
    ctx.registerUserTypesSchema();
    return new GridBinaryMarshaller(ctx);
}
Also used : NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 2 with GridBinaryMarshaller

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

the class PlatformUtils method marshaller.

/**
 * Create binary marshaller.
 *
 * @return Marshaller.
 */
public static GridBinaryMarshaller marshaller() {
    BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration(), new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextImpl(null, null));
    ctx.configure(marsh);
    return new GridBinaryMarshaller(ctx);
}
Also used : MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 3 with GridBinaryMarshaller

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

the class PlatformDotNetConfigurationClosure method prepare.

/**
 * Prepare .Net size.
 *
 * @param igniteCfg Ignite configuration.
 * @param interopCfg Interop configuration.
 */
private void prepare(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx interopCfg) {
    cfg = igniteCfg;
    try (PlatformMemory outMem = memMgr.allocate()) {
        try (PlatformMemory inMem = memMgr.allocate()) {
            PlatformOutputStream out = outMem.output();
            GridBinaryMarshaller marshaller = PlatformUtils.marshaller();
            BinaryRawWriterEx writer = marshaller.writer(out);
            PlatformConfigurationUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
            // Write .NET beans
            List<PlatformDotNetLifecycleBean> beans = beans(igniteCfg);
            writer.writeInt(beans.size());
            for (PlatformDotNetLifecycleBean bean : beans) {
                writer.writeString(bean.getTypeName());
                writer.writeMap(bean.getProperties());
            }
            // Write .NET affinity functions
            List<PlatformDotNetAffinityFunction> affFuncs = affinityFunctions(igniteCfg);
            writer.writeInt(affFuncs.size());
            for (PlatformDotNetAffinityFunction func : affFuncs) {
                writer.writeString(func.getTypeName());
                writer.writeMap(func.getProperties());
            }
            out.synchronize();
            gate.extensionCallbackInLongLongOutLong(PlatformUtils.OP_PREPARE_DOT_NET, outMem.pointer(), inMem.pointer());
            processPrepareResult(marshaller.reader(inMem.input()));
        }
    }
}
Also used : GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) 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) PlatformDotNetLifecycleBean(org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean)

Example 4 with GridBinaryMarshaller

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

the class GridCacheProcessor method withBinaryContext.

/**
 * @param c Closure.
 * @return Closure result.
 * @throws IgniteCheckedException If failed.
 */
private <T> T withBinaryContext(IgniteOutClosureX<T> c) throws IgniteCheckedException {
    IgniteCacheObjectProcessor objProc = ctx.cacheObjects();
    BinaryContext oldCtx = null;
    if (objProc instanceof CacheObjectBinaryProcessorImpl) {
        GridBinaryMarshaller binMarsh = ((CacheObjectBinaryProcessorImpl) objProc).marshaller();
        oldCtx = binMarsh == null ? null : binMarsh.pushContext();
    }
    try {
        return c.applyx();
    } finally {
        if (objProc instanceof CacheObjectBinaryProcessorImpl)
            GridBinaryMarshaller.popContext(oldCtx);
    }
}
Also used : CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 5 with GridBinaryMarshaller

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

the class CacheObjectBinaryProcessorImpl method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    if (marsh instanceof BinaryMarshaller) {
        if (ctx.clientNode())
            ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED);
        transport = new BinaryMetadataTransport(metadataLocCache, ctx, log);
        BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {

            @Override
            public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
                assert newMeta != null;
                assert newMeta instanceof BinaryTypeImpl;
                if (!discoveryStarted) {
                    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
                    BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;
                    BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, ((BinaryTypeImpl) newMeta).metadata());
                    if (oldMeta != mergedMeta)
                        metadataLocCache.putIfAbsent(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
                    return;
                }
                BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
                CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(binaryCtx));
            }

            @Override
            public BinaryType metadata(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
            }

            @Override
            public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
            }

            @Override
            public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
            }
        };
        BinaryMarshaller bMarsh0 = (BinaryMarshaller) marsh;
        binaryCtx = new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
        IgniteUtils.invoke(BinaryMarshaller.class, bMarsh0, "setBinaryContext", binaryCtx, ctx.config());
        binaryMarsh = new GridBinaryMarshaller(binaryCtx);
        binaries = new IgniteBinaryImpl(ctx, this);
        if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
            BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();
            if (bCfg != null) {
                Map<String, Object> map = new HashMap<>();
                map.put("globIdMapper", bCfg.getIdMapper() != null ? bCfg.getIdMapper().getClass().getName() : null);
                map.put("globSerializer", bCfg.getSerializer() != null ? bCfg.getSerializer().getClass() : null);
                map.put("compactFooter", bCfg.isCompactFooter());
                if (bCfg.getTypeConfigurations() != null) {
                    Map<Object, Object> typeCfgsMap = new HashMap<>();
                    for (BinaryTypeConfiguration c : bCfg.getTypeConfigurations()) {
                        typeCfgsMap.put(c.getTypeName() != null, Arrays.asList(c.getIdMapper() != null ? c.getIdMapper().getClass() : null, c.getSerializer() != null ? c.getSerializer().getClass() : null, c.isEnum()));
                        if (c.isEnum())
                            BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
                    }
                    map.put("typeCfgs", typeCfgsMap);
                }
                ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
            }
        }
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryType(org.apache.ignite.binary.BinaryType) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BinaryMetadataHandler(org.apache.ignite.internal.binary.BinaryMetadataHandler) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)6 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)5 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryType (org.apache.ignite.binary.BinaryType)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)2 BinaryMetadataHandler (org.apache.ignite.internal.binary.BinaryMetadataHandler)2 BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 NullLogger (org.apache.ignite.logger.NullLogger)2 MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)1 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)1 IncompleteCacheObject (org.apache.ignite.internal.processors.cache.IncompleteCacheObject)1 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)1