コード例 #1
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ReplicaHealth obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize);
            if (obj.HealthEvents != null)
            {
                writer.WriteEnumerableProperty(obj.HealthEvents, "HealthEvents", HealthEventConverter.Serialize);
            }

            if (obj.UnhealthyEvaluations != null)
            {
                writer.WriteEnumerableProperty(obj.UnhealthyEvaluations, "UnhealthyEvaluations", HealthEvaluationWrapperConverter.Serialize);
            }

            if (obj.HealthStatistics != null)
            {
                writer.WriteProperty(obj.HealthStatistics, "HealthStatistics", HealthStatisticsConverter.Serialize);
            }

            if (obj.PartitionId != null)
            {
                writer.WriteProperty(obj.PartitionId, "PartitionId", PartitionIdConverter.Serialize);
            }

            writer.WriteEndObject();
        }
コード例 #2
0
        public ReplicaSetPool(IList <TReplicaKey> replicas,
                              Func <TItemKey, TReplicaKey, Pool <TItem> > poolFactory,
                              IEqualityComparer <TReplicaKey> replicaKeyComparer,
                              IEqualityComparer <TItemKey> itemKeyComparer,
                              Func <TItem, TReplicaKey> getReplicaKeyByItem,
                              Func <TItem, TItemKey> getItemKeyByItem,
                              PoolSettings poolSettings,
                              ILog logger,
                              TimeSpan?itemIdleTimeout = null)
        {
            this.logger = logger.ForContext("ReplicaSetPool");
            if (replicas.Count == 0)
            {
                throw new EmptyPoolException("Cannot create empty ReplicaSetPool");
            }
            this.logger.Info("ReplicaSetPool created with client topology: {0}", string.Join(", ", replicas));
            replicaIndicies = new Dictionary <TReplicaKey, int>(replicaKeyComparer);
            replicaHealths  = new ReplicaHealth <TReplicaKey> [replicas.Count];
            for (var idx = 0; idx < replicas.Count; idx++)
            {
                var replica = replicas[idx];
                replicaIndicies.Add(replica, idx);
                replicaHealths[idx] = new ReplicaHealth <TReplicaKey>(replica, aliveHealth);
            }
            this.poolFactory         = poolFactory;
            this.replicaKeyComparer  = replicaKeyComparer;
            this.getReplicaKeyByItem = getReplicaKeyByItem;
            this.getItemKeyByItem    = getItemKeyByItem;
            this.poolSettings        = poolSettings;

            pools                = new ConcurrentDictionary <PoolKey, Pool <TItem> >(new PoolKeyEqualityComparer(replicaKeyComparer, itemKeyComparer));
            disposeEvent         = new ManualResetEvent(false);
            checkDeadItemsThread = new Thread(CheckDeadItemsThread)
            {
                Name         = $"CheckDeadConnectionsForThread {string.Join(", ", replicas)}",
                IsBackground = true
            };
            checkDeadItemsThread.Start();

            if (itemIdleTimeout != null)
            {
                this.logger.Info("Item idle timeout: {0}", itemIdleTimeout.Value);
                unusedItemsCollectorThread = new Thread(() => UnusedItemsCollectorProcedure(itemIdleTimeout.Value))
                {
                    IsBackground = true
                };
                unusedItemsCollectorThread.Start();
            }
        }
コード例 #3
0
        public static ReplicaHealth CreateRandomHealth(this Random random)
        {
            ReplicaHealth health = null;
            Type          targetType;

            if (random.Next() % 2 == 0)
            {
                targetType = typeof(StatefulServiceReplicaHealth);
            }
            else
            {
                targetType = typeof(StatelessServiceInstanceHealth);
            }

            health = (ReplicaHealth)random.CreateRandom(targetType);
            Assert.IsNotNull(health, "Assert EntityHealth 'health' is not null. Input targetType: " + targetType.Name);
            return(health);
        }
コード例 #4
0
        public void ReplicaHealthSerializationTest()
        {
            ReplicaHealth replicaHealth = this.random.CreateRandom <ReplicaHealth>();

            TestUsingSerializer(this.Serializer, replicaHealth);
        }