/// <summary>
        /// This is the main constructor.
        /// </summary>
        /// <param name="resourceTracker">The resource tracker.</param>
        /// <param name="client">The client to hold.</param>
        /// <param name="mappingChannelId">The mapping channel.param>
        /// <param name="maxAllowedPollWait">The maximum permitted poll length.</param>
        public ClientPriorityHolder(IResourceTracker resourceTracker
                                    , ClientHolder client
                                    , string mappingChannelId
                                    , IListenerClientPollAlgorithm priorityAlgorithm
                                    )
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (priorityAlgorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }

            mPriorityAlgorithm = priorityAlgorithm;

            Client = client;

            mMappingChannel = mappingChannelId;

            //Create the metrics container to hold the calculations for poll priority and reservation amount.
            mMetrics = new ClientPriorityHolderMetrics(mPriorityAlgorithm
                                                       , resourceTracker?.RegisterRequestRateLimiter(client.Name, client.ResourceProfiles)
                                                       , client.Priority
                                                       , client.Weighting
                                                       );

            mPriorityAlgorithm.InitialiseMetrics(mMetrics);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="rateLimiter"></param>
        /// <param name="priority"></param>
        /// <param name="weighting"></param>
        public ClientPriorityHolderMetrics(IListenerClientPollAlgorithm algorithm
                                           , IResourceRequestRateLimiter rateLimiter
                                           , int priority
                                           , decimal weighting)
        {
            Algorithm         = algorithm;
            RateLimiter       = rateLimiter;
            Priority          = priority;
            PriorityWeighting = weighting;

            PollTimeReduceRatio = algorithm.PollTimeReduceRatio;

            MaxAllowedPollWait  = algorithm.MaxAllowedWaitBetweenPolls;
            MinExpectedPollWait = algorithm.MinExpectedWaitBetweenPolls;

            if (MinExpectedPollWait > MaxAllowedPollWait)
            {
                MinExpectedPollWait = MaxAllowedPollWait;
            }

            mCapacityPercentage = algorithm.CapacityPercentage;
        }
Exemple #3
0
        /// <summary>
        /// This constructor build up the poll collection and sets the correct poll priority.
        /// </summary>
        /// <param name="listeners"></param>
        /// <param name="resourceTracker"></param>
        /// <param name="algorithm"></param>
        /// <param name="iterationId"></param>
        public ClientPriorityCollection(
            List <IListener> listeners
            , IResourceTracker resourceTracker
            , IListenerClientPollAlgorithm algorithm
            , long iterationId
            )
        {
            mPriorityAlgorithm = algorithm;
            mIteration         = iterationId;
            Created            = DateTime.UtcNow;

            //Get the list of active clients.
            mListenerClients = new Dictionary <Guid, ClientPriorityHolder>();
            foreach (var listener in listeners)
            {
                if (listener.ListenerClients != null)
                {
                    foreach (var client in listener.ListenerClients)
                    {
                        var holder = new ClientPriorityHolder(resourceTracker, client, listener.ListenerMappingChannelId, algorithm);
                        mListenerClients.Add(holder.Id, holder);
                    }
                }
            }

            //Get the supported levels.
            mListenerPollLevels = mListenerClients
                                  .Select((c) => c.Value.Priority)
                                  .Distinct()
                                  .OrderByDescending((i) => i)
                                  .ToArray();

            mReprioritise = 0;

            //Finally create a poll chain for each individual priority level
            Reprioritise();
        }