当前位置: 首页>>代码示例>>C#>>正文


C# Messenger.GetMessage方法代码示例

本文整理汇总了C#中Messenger.GetMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Messenger.GetMessage方法的具体用法?C# Messenger.GetMessage怎么用?C# Messenger.GetMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Messenger的用法示例。


在下文中一共展示了Messenger.GetMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunAcceptor

        private static void RunAcceptor(string uri, string acceptorName)
        {
            var messenger = new Messenger(uri);
            var promisedToAcceptNoEarlierThan = 0;
            var lastAccepted = -1;
            var lastAcceptedValue = "";

            while (true)
            {
                var currMessage = messenger.GetMessage<AcceptorReceived>();

                if (currMessage.TimePeriod <= lastAccepted) continue;

                switch (currMessage.Type)
                {
                    case "prepare":
                        if (currMessage.TimePeriod > promisedToAcceptNoEarlierThan)
                            promisedToAcceptNoEarlierThan = currMessage.TimePeriod;

                        messenger.PostMessage(new Promised
                        {
                            By = acceptorName,
                            TimePeriod = currMessage.TimePeriod,
                            HaveAccepted = lastAccepted > 0,
                            LastAcceptedTimePeriod = lastAccepted,
                            LastAcceptedValue = lastAcceptedValue
                        });

                        break;

                    case "proposed":

                        if (currMessage.TimePeriod < promisedToAcceptNoEarlierThan)
                            continue;

                        lastAccepted = currMessage.TimePeriod;
                        lastAcceptedValue = currMessage.Value;

                        messenger.PostMessage(new Accepted
                        {
                            By = acceptorName,
                            TimePeriod = currMessage.TimePeriod,
                            Value = currMessage.Value,
                        });

                        break;
                }
            }
        }
开发者ID:relentless,项目名称:paxos-dojo,代码行数:49,代码来源:Program.cs

示例2: RunNode

        private static void RunNode(string uri)
        {
            var messenger = new Messenger(uri);

            while (true)
            {
                // Receive messages like this
                var currMessage = messenger.GetMessage<Accepted>();

                Console.WriteLine("Received 'accepted' message by {0} for value '{1}' in time period {2}", currMessage.By, currMessage.Value, currMessage.TimePeriod);

                // Send messages back like this
                messenger.PostMessage(new Promised
                {
                    By = "foo",
                    TimePeriod = currMessage.TimePeriod,
                });
            }
        }
开发者ID:relentless,项目名称:paxos-dojo,代码行数:19,代码来源:Program.cs

示例3: RunLearner

        private static void RunLearner(string uri)
        {
            var messenger = new Messenger(uri);
            var received = new List<Accepted>();

            while (true)
            {
                var currMessage = messenger.GetMessage<Accepted>();

                var matchingMessage = received.FirstOrDefault(
                    prevMessage => currMessage.TimePeriod == prevMessage.TimePeriod && currMessage.By != prevMessage.By);

                received.Add(currMessage);

                if (matchingMessage == null) continue;

                Console.WriteLine("Learned value '{0}' in time period {1}", currMessage.Value, currMessage.TimePeriod);
            }
        }
开发者ID:relentless,项目名称:paxos-dojo,代码行数:19,代码来源:Program.cs

示例4: RunProposer

        private static void RunProposer(string uri, string freeValue)
        {
            var messenger = new Messenger(uri);
            var received = new List<Promised>();
            var latestProposedTimePeriod = 0;

            while (true)
            {
                var currMessage = messenger.GetMessage<Promised>();
                if (currMessage.TimePeriod <= latestProposedTimePeriod) continue;

                var matchingMessage =
                    received.FirstOrDefault(
                        prevMessage =>
                            currMessage.TimePeriod == prevMessage.TimePeriod && currMessage.By != prevMessage.By);

                received.Add(currMessage);

                if (matchingMessage == null) continue;

                var value = freeValue;

                if (currMessage.HaveAccepted)
                {
                    value = currMessage.LastAcceptedValue;
                }

                if (matchingMessage.HaveAccepted && (!currMessage.HaveAccepted
                                                     ||
                                                     matchingMessage.LastAcceptedTimePeriod >
                                                     currMessage.LastAcceptedTimePeriod))
                    value = matchingMessage.LastAcceptedValue;

                messenger.PostMessage(new Proposed
                {
                    TimePeriod = currMessage.TimePeriod,
                    Value = value,
                });

                Console.WriteLine("Proposed value '{0}' in time period {1}", value, currMessage.TimePeriod);

                latestProposedTimePeriod = currMessage.TimePeriod;
            }
        }
开发者ID:relentless,项目名称:paxos-dojo,代码行数:44,代码来源:Program.cs


注:本文中的Messenger.GetMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。