Ejemplo n.º 1
0
        /// <summary>
        ///     sends as much pending requests as there are waiting workers
        ///     of the specified service by
        ///     a) add the request to the pending requests within this service
        ///        if there is a message
        ///     b) remove all expired workers of this service
        ///     c) while there are waiting workers
        ///             get the next pending request
        ///             send to the worker
        /// </summary>
        private void ServiceDispatch(Service service, NetMQMessage message)
        {
            DebugLog($"Service [{service.Name}] dispatches -> {(message == null ? "PURGING" : "message = " + message)}");

            // if message is 'null' just send pending requests
            if (!ReferenceEquals(message, null))
            {
                service.AddRequest(message);
            }

            // remove all expired workers!
            Purge();

            // if there are requests pending and workers are waiting dispatch the requests
            // as long as there are workers and requests
            while (service.CanDispatchRequests())
            {
                var worker = service.GetNextWorker();

                if (service.PendingRequests.Count > 0)
                {
                    var request = service.GetNextRequest();

                    DebugLog($"Service Dispatch -> pending request {request} to {worker.Id}");

                    WorkerSend(worker, MDPCommand.Request, request);
                }
                else
                {
                    // no more requests -> we're done
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     sends as much pending requests as there are waiting workers 
        ///     of the specified service by
        ///     a) add the request to the pending requests within this service
        ///        if there is a message
        ///     b) remove all expired workers of this service
        ///     c) while there are waiting workers 
        ///             get the next pending request
        ///             send to the worker
        /// </summary>
        private void ServiceDispatch (Service service, NetMQMessage message)
        {
            DebugLog (string.Format ("Service [{0}] dispatches -> {1}",
                                     service.Name,
                                     message == null ? "PURGING" : "message = " + message));

            // if message is 'null' just send pending requests
            if (!ReferenceEquals (message, null))
                service.AddRequest (message);

            // remove all expired workers!
            Purge ();

            // if there are requests pending and workers are waiting dispatch the requests
            // as long as there are workers and requests
            while (service.CanDispatchRequests ())
            {
                var worker = service.GetNextWorker ();

                if (service.PendingRequests.Count > 0)
                {
                    var request = service.GetNextRequest ();

                    DebugLog (string.Format ("Service Dispatch -> pending request {0} to {1}", request, worker.Id));

                    WorkerSend (worker, MDPCommand.Request, request);
                }
                else
                    // no more requests -> we're done
                    break;
            }
        }