示例#1
0
        private int SendManagerMessage(ServiceMessageQueue queue, IServiceAddress managerServer, MessageStream messageOut)
        {
            int successCount = 0;

            // Process the message,
            IMessageProcessor     processor = network.Connect(managerServer, ServiceType.Manager);
            IEnumerable <Message> messageIn = processor.Process(messageOut);

            // Handle the response,
            foreach (Message m in messageIn)
            {
                if (m.HasError)
                {
                    log.Error("Manager error: " + m.ErrorMessage);

                    // If we failed, add the message to the retry queue,
                    if (queue != null)
                    {
                        queue.AddMessageStream(managerServer, messageOut, ServiceType.Manager);
                    }
                    // Report the service as down to the tracker,
                    tracker.ReportServiceDownClientReport(managerServer, ServiceType.Manager);
                }
                else
                {
                    // Message successfully sent,
                    ++successCount;
                }
            }

            return(successCount);
        }
示例#2
0
        private int SendRootMessage(ServiceMessageQueue queue, IServiceAddress rootServer, MessageStream messageOut)
        {
            int successCount = 0;

            // Process the message,
            IMessageProcessor     processor = network.Connect(rootServer, ServiceType.Root);
            IEnumerable <Message> messageIn = processor.Process(messageOut);

            // Handle the response,
            foreach (Message m in messageIn)
            {
                if (m.HasError)
                {
                    log.Error("Root error: " + m.ErrorMessage);

                    // If we failed, add the message to the retry queue,
                    if (queue != null)
                    {
                        queue.AddMessageStream(rootServer, messageOut, ServiceType.Root);
                    }

                    // TODO: We should confirm the error is a connection failure before
                    //   reporting the service as down.
                    // Report the service as down to the tracker,
                    tracker.ReportServiceDownClientReport(rootServer, ServiceType.Root);
                }
                else
                {
                    // Message successfully sent,
                    ++successCount;
                }
            }

            return(successCount);
        }
示例#3
0
        private void RetryMessageTask(object state)
        {
            IServiceAddress address = (IServiceAddress)state;

            List <ServiceType>   types;
            List <MessageStream> messages;

            lock (queueMap) {
                // Remove from the queue,
                RetryMessageQueue queue;
                queueMap.TryGetValue(address, out queue);
                queueMap.Remove(address);
                types    = queue.ServiceTypes;
                messages = queue.Queue;
            }
            // Create a message queue
            ServiceMessageQueue messageQueue = CreateServiceMessageQueue();
            // For each message in the queue,
            int sz = types.Count;

            for (int i = 0; i < sz; ++i)
            {
                ServiceType   type          = types[i];
                MessageStream messageStream = messages[i];

                if (type == ServiceType.Manager)
                {
                    SendManagerMessage(messageQueue, address, messageStream);
                }
                else if (type == ServiceType.Root)
                {
                    SendRootMessage(messageQueue, address, messageStream);
                }
                else
                {
                    throw new ApplicationException("Unknown type");
                }
            }
            // Re-enqueue any pending messages,
            messageQueue.Enqueue();
        }
        private int SendRootMessage(ServiceMessageQueue queue, IServiceAddress rootServer, MessageStream messageOut)
        {
            int successCount = 0;

            // Process the message,
            IMessageProcessor processor = network.Connect(rootServer, ServiceType.Root);
            IEnumerable<Message> messageIn = processor.Process(messageOut);

            // Handle the response,
            foreach (Message m in messageIn) {
                if (m.HasError) {
                    log.Error("Root error: " + m.ErrorMessage);

                    // If we failed, add the message to the retry queue,
                    if (queue != null) {
                        queue.AddMessageStream(rootServer, messageOut, ServiceType.Root);
                    }

                    // TODO: We should confirm the error is a connection failure before
                    //   reporting the service as down.
                    // Report the service as down to the tracker,
                    tracker.ReportServiceDownClientReport(rootServer, ServiceType.Root);
                } else {
                    // Message successfully sent,
                    ++successCount;
                }
            }

            return successCount;
        }
        private int SendManagerMessage(ServiceMessageQueue queue, IServiceAddress managerServer, MessageStream messageOut)
        {
            int successCount = 0;

            // Process the message,
            IMessageProcessor processor = network.Connect(managerServer, ServiceType.Manager);
            IEnumerable<Message> messageIn = processor.Process(messageOut);

            // Handle the response,
            foreach (Message m in messageIn) {
                if (m.HasError) {
                    log.Error("Manager error: " + m.ErrorMessage);

                    // If we failed, add the message to the retry queue,
                    if (queue != null) {
                        queue.AddMessageStream(managerServer, messageOut, ServiceType.Manager);
                    }
                    // Report the service as down to the tracker,
                    tracker.ReportServiceDownClientReport(managerServer, ServiceType.Manager);
                } else {
                    // Message successfully sent,
                    ++successCount;
                }
            }

            return successCount;
        }