Search in sources :

Example 31 with BinaryMetadata

use of org.apache.ignite.internal.binary.BinaryMetadata 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)

Example 32 with BinaryMetadata

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

the class PlatformContextImpl method writeMetadata0.

/**
 * Write binary metadata.
 *
 * @param writer Writer.
 * @param meta Metadata.
 */
private void writeMetadata0(BinaryRawWriterEx writer, BinaryType meta) {
    if (meta == null)
        writer.writeBoolean(false);
    else {
        writer.writeBoolean(true);
        BinaryMetadata meta0 = ((BinaryTypeImpl) meta).metadata();
        PlatformUtils.writeBinaryMetadata(writer, meta0, false);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Aggregations

BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)32 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)11 HashMap (java.util.HashMap)9 BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 BinaryObject (org.apache.ignite.binary.BinaryObject)6 LinkedHashMap (java.util.LinkedHashMap)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 IgniteException (org.apache.ignite.IgniteException)3 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)3 Array (java.lang.reflect.Array)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2