/// <summary>
        /// This method builds the task tracker for the listener poll.
        /// </summary>
        /// <param name="context">The client priority holder context.</param>
        /// <returns>Returns a tracker of type listener poll.</returns>
        private void TrackerSubmitFromClientPriorityHolder(ClientPriorityHolder context)
        {
            TaskTracker tracker = new TaskTracker(TaskTrackerType.ListenerClientPoll, TimeSpan.FromSeconds(30))
            {
                Priority = TaskTracker.PriorityInternal,
                Context  = context,
                Name     = context.Name
            };

            tracker.Execute = async t =>
            {
                var currentContext = ((ClientPriorityHolder)tracker.Context);

                var payloads = await currentContext.Poll();

                if (payloads != null && payloads.Count > 0)
                {
                    foreach (var payload in payloads)
                    {
                        PayloadSubmit(currentContext.ClientId, payload);
                    }
                }
            };

            tracker.ExecuteComplete = (tr, failed, ex) =>
            {
                var currentContext = ((ClientPriorityHolder)tr.Context);
                TaskAvailability.ReservationRelease(currentContext.Id);
                currentContext.Release(failed);
            };

            TaskSubmit(tracker);
        }
        /// <summary>
        /// This method builds the task tracker for the listener poll.
        /// </summary>
        /// <param name="context">The client priority holder context.</param>
        /// <returns>Returns a tracker of type listener poll.</returns>
        private void TrackerSubmitFromClientPriorityHolder(ClientPriorityHolder context)
        {
            //Create the task that will poll the client for incoming messages.
            TaskTracker tracker = new TaskTracker(TaskTrackerType.ListenerClientPoll, mPolicy.ListenerRequestTimespan)
            {
                Priority = TaskTracker.PriorityInternal,
                Context  = context,
                Name     = context.Name
            };

            //Set the execute function that polls the context and retrieves incoming payloads from the fabric
            //and submits them to be processed.
            tracker.Execute = async t =>
            {
                var currentContext = ((ClientPriorityHolder)tracker.Context);

                var payloads = await currentContext.Poll();

                if (payloads != null && payloads.Count > 0)
                {
                    foreach (var payload in payloads)
                    {
                        PayloadSubmit(currentContext.ClientId, payload);
                    }
                }
            };

            //Set the completion function that releases the slot reservations back in to the pool.
            tracker.ExecuteComplete = (tr, failed, ex) =>
            {
                var currentContext = ((ClientPriorityHolder)tr.Context);
                TaskAvailability.ReservationRelease(currentContext.Id);
                currentContext.Release(failed);
            };

            //Submit the tracker for processing.
            TaskSubmit(tracker);
        }
예제 #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();
        }