Beispiel #1
0
 private void Schedule(Action writeAction)
 {
     _daemon.Schedule(() =>
     {
         _actionQueue.Enqueue(writeAction);
         if (_actionQueue.Count == 1)
         {
             FlushOne();
         }
     });
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var config = DaemonConfig
                .Default()
                .WithMq((conf => conf.WithUdpEmCaster(emcasterConfig =>
                                                          {
                                                              emcasterConfig.AddStressTestLayer(0.1);
                                                              emcasterConfig.AddReliabilityLayer(TimeSpan.FromSeconds(1));
                                                              emcasterConfig.AddRoute("chat");
                                                              emcasterConfig.AddRoute(@"chat/[\w]*");
                                                          })));
            var bus = config.BuildMessageBus();

            Console.Write("Enter user name : ");
            var userName = Console.ReadLine();
            Console.Write("Enter channel : #");
            var channel = Console.ReadLine();

            var daemon = new ThreadPoolDaemon();
            daemon.Schedule(
                () =>
                    {
                        bus.Subscribe<UserJoined>("chat",
                            message => Console.WriteLine("# " + message.UserName + " joined #" + message.Channel));
                        bus.Subscribe<UserMessage>(string.Format(@"chat\{0}", channel),
                            message => Console.WriteLine("{0}>{1}", message.UserName, message.Message));
                        bus.Publish("chat", new UserJoined {Channel = channel, UserName = userName});

                    });
            while (true)
            {
                var line = Console.ReadLine();
                bus.Publish(string.Format(@"chat\{0}", channel), new UserMessage() { Message = line, UserName = userName });
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                _processNo = int.Parse(args[0]);
            }
            if (args.Length >= 2)
            {
                _messagesPerProcess = int.Parse(args[1]);
            }

            _countArray = new int[_processNo];

            _start = DateTime.UtcNow;

            _countDown = _processNo;
            for (int i = 0; i < _processNo; i++)
            {
                int i1     = i; // copy is required, so that closure works as intendent
                var daemon = new ThreadPoolDaemon();
                daemon.Schedule(() => Increment(daemon, i1));
            }

            Console.ReadLine();
        }
Beispiel #4
0
        public void Publish(string path, object message)
        {
            var messageNo = Interlocked.Increment(ref _lastSentMessage);
            var payload   = new Message
            {
                ConnectionId = _connectionId,
                MessageNo    = messageNo,
                InnerObject  = message,
            };

            _outputWindow.Add(path, payload);

            _daemon.Schedule(() => _innerChannel.Publish(path, payload));
            // retry after 300 ms
            // _daemon.ScheduleOne(() => _innerChannel.Publish(path, payload), TimeSpan.FromMilliseconds(300));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var config = DaemonConfig
                         .Default()
                         .WithMq((conf => conf.WithUdpEmCaster(emcasterConfig =>
            {
                emcasterConfig.AddStressTestLayer(0.1);
                emcasterConfig.AddReliabilityLayer(TimeSpan.FromSeconds(1));
                emcasterConfig.AddRoute("chat");
                emcasterConfig.AddRoute(@"chat/[\w]*");
            })));
            var bus = config.BuildMessageBus();

            Console.Write("Enter user name : ");
            var userName = Console.ReadLine();

            Console.Write("Enter channel : #");
            var channel = Console.ReadLine();

            var daemon = new ThreadPoolDaemon();

            daemon.Schedule(
                () =>
            {
                bus.Subscribe <UserJoined>("chat",
                                           message => Console.WriteLine("# " + message.UserName + " joined #" + message.Channel));
                bus.Subscribe <UserMessage>(string.Format(@"chat\{0}", channel),
                                            message => Console.WriteLine("{0}>{1}", message.UserName, message.Message));
                bus.Publish("chat", new UserJoined {
                    Channel = channel, UserName = userName
                });
            });
            while (true)
            {
                var line = Console.ReadLine();
                bus.Publish(string.Format(@"chat\{0}", channel), new UserMessage()
                {
                    Message = line, UserName = userName
                });
            }
        }