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;
            }
        }
Ejemplo n.º 3
0
        public void GetNextRequest_MultipleRequestExist_ShouldReturnOldesRequestAndDeleteFromPending()
        {
            var service = new Service("service");

            for (int i = 0; i < 10; i++)
            {
                var request = new NetMQMessage();
                request.Push("DATA");
                request.Push("SERVICE");
                request.Push($"HEADER_{i}");

                service.AddRequest(request);
            }

            for (int i = 0; i < 5; i++)
            {
                var req = service.GetNextRequest();

                Assert.That(req.First.ConvertToString(), Is.EqualTo($"HEADER_{i}"));
            }

            Assert.That(service.PendingRequests.Count, Is.EqualTo(5));
        }
Ejemplo n.º 4
0
        public void GetNextRequest_SingleRequestExist_ShouldReturnOldesRequestAndDeleteFromPending()
        {
            var request = new NetMQMessage();
            request.Push("DATA");
            request.Push("SERVICE");
            request.Push("HEADER");

            var service = new Service("service");

            service.AddRequest(request);

            Assert.That(service.GetNextRequest(), Is.EqualTo(request));
            Assert.That(service.PendingRequests.Count, Is.EqualTo(0));
        }