Ejemplo n.º 1
0
        /// <summary>
        /// Reads data from specified reader into current instance.
        /// </summary>
        /// <param name="r">The binary reader.</param>
        private void ReadCore(IBinaryRawReader r)
        {
            // Simple properties
            _clientMode             = r.ReadBooleanNullable();
            IncludedEventTypes      = r.ReadIntArray();
            _metricsExpireTime      = r.ReadTimeSpanNullable();
            _metricsHistorySize     = r.ReadIntNullable();
            _metricsLogFrequency    = r.ReadTimeSpanNullable();
            _metricsUpdateFrequency = r.ReadTimeSpanNullable();
            _networkSendRetryCount  = r.ReadIntNullable();
            _networkSendRetryDelay  = r.ReadTimeSpanNullable();
            _networkTimeout         = r.ReadTimeSpanNullable();
            WorkDirectory           = r.ReadString();
            Localhost = r.ReadString();
            _isDaemon = r.ReadBooleanNullable();
            _isLateAffinityAssignment = r.ReadBooleanNullable();
            _failureDetectionTimeout  = r.ReadTimeSpanNullable();

            // Cache config
            var cacheCfgCount = r.ReadInt();

            CacheConfiguration = new List <CacheConfiguration>(cacheCfgCount);
            for (int i = 0; i < cacheCfgCount; i++)
            {
                CacheConfiguration.Add(new CacheConfiguration(r));
            }

            // Discovery config
            DiscoverySpi = r.ReadBoolean() ? new TcpDiscoverySpi(r) : null;

            // Communication config
            CommunicationSpi = r.ReadBoolean() ? new TcpCommunicationSpi(r) : null;

            // Binary config
            if (r.ReadBoolean())
            {
                BinaryConfiguration = BinaryConfiguration ?? new BinaryConfiguration();

                if (r.ReadBoolean())
                {
                    BinaryConfiguration.CompactFooter = r.ReadBoolean();
                }

                var typeCount = r.ReadInt();

                if (typeCount > 0)
                {
                    var types = new List <BinaryTypeConfiguration>(typeCount);

                    for (var i = 0; i < typeCount; i++)
                    {
                        types.Add(new BinaryTypeConfiguration
                        {
                            TypeName         = r.ReadString(),
                            IsEnum           = r.ReadBoolean(),
                            EqualityComparer = BinaryEqualityComparerSerializer.Read(r)
                        });
                    }

                    BinaryConfiguration.TypeConfigurations = types;
                }
            }

            // User attributes
            UserAttributes = Enumerable.Range(0, r.ReadInt())
                             .ToDictionary(x => r.ReadString(), x => r.ReadObject <object>());

            // Atomic
            if (r.ReadBoolean())
            {
                AtomicConfiguration = new AtomicConfiguration
                {
                    AtomicSequenceReserveSize = r.ReadInt(),
                    Backups   = r.ReadInt(),
                    CacheMode = (CacheMode)r.ReadInt()
                };
            }

            // Tx
            if (r.ReadBoolean())
            {
                TransactionConfiguration = new TransactionConfiguration
                {
                    PessimisticTransactionLogSize = r.ReadInt(),
                    DefaultTransactionConcurrency = (TransactionConcurrency)r.ReadInt(),
                    DefaultTransactionIsolation   = (TransactionIsolation)r.ReadInt(),
                    DefaultTimeout = TimeSpan.FromMilliseconds(r.ReadLong()),
                    PessimisticTransactionLogLinger = TimeSpan.FromMilliseconds(r.ReadInt())
                };
            }

            // Swap
            SwapSpaceSpi = SwapSpaceSerializer.Read(r);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes this instance to a writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        internal void Write(BinaryWriter writer)
        {
            Debug.Assert(writer != null);

            // Simple properties
            writer.WriteBooleanNullable(_clientMode);
            writer.WriteIntArray(IncludedEventTypes == null ? null : IncludedEventTypes.ToArray());

            writer.WriteTimeSpanAsLongNullable(_metricsExpireTime);
            writer.WriteIntNullable(_metricsHistorySize);
            writer.WriteTimeSpanAsLongNullable(_metricsLogFrequency);
            writer.WriteTimeSpanAsLongNullable(_metricsUpdateFrequency);
            writer.WriteIntNullable(_networkSendRetryCount);
            writer.WriteTimeSpanAsLongNullable(_networkSendRetryDelay);
            writer.WriteTimeSpanAsLongNullable(_networkTimeout);
            writer.WriteString(WorkDirectory);
            writer.WriteString(Localhost);
            writer.WriteBooleanNullable(_isDaemon);
            writer.WriteBooleanNullable(_isLateAffinityAssignment);
            writer.WriteTimeSpanAsLongNullable(_failureDetectionTimeout);

            // Cache config
            var caches = CacheConfiguration;

            if (caches == null)
            {
                writer.WriteInt(0);
            }
            else
            {
                writer.WriteInt(caches.Count);

                foreach (var cache in caches)
                {
                    cache.Write(writer);
                }
            }

            // Discovery config
            var disco = DiscoverySpi;

            if (disco != null)
            {
                writer.WriteBoolean(true);

                var tcpDisco = disco as TcpDiscoverySpi;

                if (tcpDisco == null)
                {
                    throw new InvalidOperationException("Unsupported discovery SPI: " + disco.GetType());
                }

                tcpDisco.Write(writer);
            }
            else
            {
                writer.WriteBoolean(false);
            }

            // Communication config
            var comm = CommunicationSpi;

            if (comm != null)
            {
                writer.WriteBoolean(true);

                var tcpComm = comm as TcpCommunicationSpi;

                if (tcpComm == null)
                {
                    throw new InvalidOperationException("Unsupported communication SPI: " + comm.GetType());
                }

                tcpComm.Write(writer);
            }
            else
            {
                writer.WriteBoolean(false);
            }

            // Binary config
            if (BinaryConfiguration != null)
            {
                writer.WriteBoolean(true);

                if (BinaryConfiguration.CompactFooterInternal != null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(BinaryConfiguration.CompactFooter);
                }
                else
                {
                    writer.WriteBoolean(false);
                }

                // Send only descriptors with non-null EqualityComparer to preserve old behavior where
                // remote nodes can have no BinaryConfiguration.
                var types = writer.Marshaller.GetUserTypeDescriptors().Where(x => x.EqualityComparer != null).ToList();

                writer.WriteInt(types.Count);

                foreach (var type in types)
                {
                    writer.WriteString(BinaryUtils.SimpleTypeName(type.TypeName));
                    writer.WriteBoolean(type.IsEnum);
                    BinaryEqualityComparerSerializer.Write(writer, type.EqualityComparer);
                }
            }
            else
            {
                writer.WriteBoolean(false);
            }

            // User attributes
            var attrs = UserAttributes;

            if (attrs == null)
            {
                writer.WriteInt(0);
            }
            else
            {
                writer.WriteInt(attrs.Count);

                foreach (var pair in attrs)
                {
                    writer.WriteString(pair.Key);
                    writer.Write(pair.Value);
                }
            }

            // Atomic
            if (AtomicConfiguration != null)
            {
                writer.WriteBoolean(true);

                writer.WriteInt(AtomicConfiguration.AtomicSequenceReserveSize);
                writer.WriteInt(AtomicConfiguration.Backups);
                writer.WriteInt((int)AtomicConfiguration.CacheMode);
            }
            else
            {
                writer.WriteBoolean(false);
            }

            // Tx
            if (TransactionConfiguration != null)
            {
                writer.WriteBoolean(true);

                writer.WriteInt(TransactionConfiguration.PessimisticTransactionLogSize);
                writer.WriteInt((int)TransactionConfiguration.DefaultTransactionConcurrency);
                writer.WriteInt((int)TransactionConfiguration.DefaultTransactionIsolation);
                writer.WriteLong((long)TransactionConfiguration.DefaultTimeout.TotalMilliseconds);
                writer.WriteInt((int)TransactionConfiguration.PessimisticTransactionLogLinger.TotalMilliseconds);
            }
            else
            {
                writer.WriteBoolean(false);
            }

            // Swap space
            SwapSpaceSerializer.Write(writer, SwapSpaceSpi);

            // Plugins
            if (PluginConfigurations != null)
            {
                var pos = writer.Stream.Position;

                writer.WriteInt(0); // reserve count

                var cnt = 0;

                foreach (var cfg in PluginConfigurations)
                {
                    if (cfg.PluginConfigurationClosureFactoryId != null)
                    {
                        writer.WriteInt(cfg.PluginConfigurationClosureFactoryId.Value);

                        cfg.WriteBinary(writer);

                        cnt++;
                    }
                }

                writer.Stream.WriteInt(pos, cnt);
            }
            else
            {
                writer.WriteInt(0);
            }
        }