private DefaultPortableReader CreateReader(IBufferObjectDataInput input, int factoryId, int classId, int version,
                                                   int portableVersion)
        {
            var effectiveVersion = version;

            if (version < 0)
            {
                effectiveVersion = _context.GetVersion();
            }
            var cd = _context.LookupClassDefinition(factoryId, classId, effectiveVersion);

            if (cd == null)
            {
                var begin = input.Position();
                cd = _context.ReadClassDefinition(input, factoryId, classId, effectiveVersion);
                input.Position(begin);
            }
            DefaultPortableReader reader;

            if (portableVersion == effectiveVersion)
            {
                reader = new DefaultPortableReader(this, input, cd);
            }
            else
            {
                reader = new MorphingPortableReader(this, input, cd);
            }
            return(reader);
        }
        private int FindPortableVersion(int factoryId, int classId, IPortable portable)
        {
            int currentVersion = context.GetClassVersion(factoryId, classId);

            if (currentVersion < 0)
            {
                currentVersion = PortableVersionHelper.GetVersion(portable, context.GetVersion());
                if (currentVersion > 0)
                {
                    context.SetClassVersion(factoryId, classId, currentVersion);
                }
            }
            return(currentVersion);
        }
Beispiel #3
0
            internal IClassDefinition Register(IClassDefinition cd)
            {
                if (cd == null)
                {
                    return(null);
                }
                if (cd.GetFactoryId() != _factoryId)
                {
                    throw new HazelcastSerializationException("Invalid factory-id! " + _factoryId + " -> " + cd);
                }
                if (cd is ClassDefinition)
                {
                    var cdImpl = (ClassDefinition)cd;
                    cdImpl.SetVersionIfNotSet(_portableContext.GetVersion());
                }
                var versionedClassId = Bits.CombineToLong(cd.GetClassId(), cd.GetVersion());
                var currentCd        = _versionedDefinitions.GetOrAdd(versionedClassId, cd);

                if (Equals(currentCd, cd))
                {
                    return(cd);
                }
                if (currentCd is ClassDefinition)
                {
                    if (!currentCd.Equals(cd))
                    {
                        throw new HazelcastSerializationException(
                                  "Incompatible class-definitions with same class-id: " + cd + " VS " + currentCd);
                    }
                    return(currentCd);
                }
                _versionedDefinitions.AddOrUpdate(versionedClassId, cd, (key, oldValue) => cd);
                return(cd);
            }