Example #1
0
        public void ChangeChannelTest()
        {
            bool         waiting  = true;
            const string channel1 = "channel1";
            const string channel2 = "channel2";
            const string channel3 = "channel3";

            const string          message           = "message";
            ITransmitter <string> stringTransmitter = StringChannel.CreateTransmitter(channel1);
            IReceiver <string>    stringReceiver    = StringChannel.CreateReceiver(channel2);

            stringReceiver.Received += (sender, args) => { waiting = false; };
            stringTransmitter.Send(message);

            Thread.Sleep(200);
            Assert.IsNull(stringReceiver.LastMessage);

            stringTransmitter.SetChannel(channel3);
            stringReceiver.SetChannel(channel3);

            stringTransmitter.Send(message);

            while (waiting)
            {
                Thread.Sleep(200);
            }

            Assert.IsNotNull(stringReceiver.LastMessage);
        }
Example #2
0
        public LogPanel(JamochaGui gui)
            : base(gui)
        {
            InitBlock();
            //UPGRADE_ISSUE: Constructor 'java.awt.BorderLayout.BorderLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtBorderLayout"'
            setLayout(new BorderLayout());
            logChannel = gui.Engine.MessageRouter.openChannel("gui_log", InterestType.ALL);
            detailView = new JTextArea();
            detailView.setEditable(false);
            //UPGRADE_NOTE: If the given Font Name does not exist, a default Font instance is created. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1075"'
            //UPGRADE_TODO: Method 'java.awt.Font.Plain' was converted to 'System.Drawing.FontStyle.Regular' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtFontPLAIN_f"'
            detailView.setFont(new System.Drawing.Font("Courier", 12, (System.Drawing.FontStyle) System.Drawing.FontStyle.Regular));
            cellRenderer = new LogTableCellRenderer(this);
            logTable = new AnonymousClassJTable(this, dataModel);
            logTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            logTable.SelectionModel.addListSelectionListener(this);
            pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(logTable), new JScrollPane(detailView));
            pane.setDividerLocation(gui.Preferences.getInt("log.dividerlocation", 300));
            //UPGRADE_ISSUE: Field 'java.awt.BorderLayout.CENTER' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtBorderLayout"'
            add(pane, BorderLayout.CENTER);

            SupportClass.ThreadClass logThread = new AnonymousClassThread(this);
            logThread.Start();
            clearButton = new JButton("Clear Log", IconLoader.getImageIcon("monitor"));
            clearButton.addActionListener(this);
            JPanel buttonPanel = new JPanel();
            //UPGRADE_ISSUE: Constructor 'java.awt.FlowLayout.FlowLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtFlowLayout"'
            //UPGRADE_ISSUE: Field 'java.awt.FlowLayout.RIGHT' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtFlowLayout"'
            buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 1));
            buttonPanel.add(clearButton);
            //UPGRADE_ISSUE: Field 'java.awt.BorderLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000"'
            add(buttonPanel, BorderLayout.PAGE_END);
        }
Example #3
0
        public void TestSingleChannelCreation()
        {
            const string      channelName = "channel";
            IChannel <string> channel     = StringChannel.GetChannel(channelName);

            Assert.AreEqual(channelName, channel.ChannelName);
        }
Example #4
0
        public void TransmitterCreationTest()
        {
            const string          channelName       = "channel";
            ITransmitter <string> stringTransmitter = StringChannel.CreateTransmitter(channelName);

            Assert.AreEqual(channelName, stringTransmitter.Channel.ChannelName);
        }
Example #5
0
        static void Main(string[] args)
        {
            var port = 1055;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }

            var server = new ReactiveListener(port);

            server.Connections.Subscribe(socket =>
            {
                Console.WriteLine("New socket connected {0}", socket.GetHashCode());

                var protocol = new StringChannel(socket);

                // Here we hook the "echo" prototocol
                protocol.Receiver.Subscribe(
                    s => { Console.Write(s); protocol.SendAsync(s).Wait(); },
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                socket.Disconnected += (sender, e) => Console.WriteLine("Socket disconnected {0}", sender.GetHashCode());
                socket.Disposed     += (sender, e) => Console.WriteLine("Socket disposed {0}", sender.GetHashCode());
            });

            server.Start();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
Example #6
0
        public void TransmitMessageToMultipleReceiverTest()
        {
            bool         rcv1Waiting = true;
            bool         rcv2Waiting = true;
            const string channel     = "channel";
            const string message     = "message";

            ITransmitter <string> stringTransmitter = StringChannel.CreateTransmitter(channel);
            IReceiver <string>    receiver1         = StringChannel.CreateReceiver(channel);
            IReceiver <string>    receiver2         = StringChannel.CreateReceiver(channel);

            receiver1.Received += (sender, args) =>
            {
                Assert.AreEqual(channel, args.Channel.ChannelName);
                rcv1Waiting = false;
            };

            receiver2.Received += (sender, args) =>
            {
                Assert.AreEqual(channel, args.Channel.ChannelName);
                rcv2Waiting = false;
            };

            stringTransmitter.Send(message);

            while (rcv1Waiting && rcv2Waiting)
            {
                Thread.Sleep(200);
            }

            Assert.AreEqual(message, receiver1.LastMessage);
            Assert.AreEqual(message, receiver2.LastMessage);
        }
Example #7
0
        static void Main(string[] args)
        {
            var port = 1055;
            if (args.Length > 0)
                port = int.Parse(args[0]);

            var server = new ReactiveListener(port);

            server.Connections.Subscribe(socket =>
            {
                Console.WriteLine("New socket connected {0}", socket.GetHashCode());

                var protocol = new StringChannel(socket);

                // Here we hook the "echo" prototocol
                protocol.Receiver.Subscribe(
                    s => { Console.Write(s); protocol.SendAsync(s).Wait(); }, 
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                socket.Disconnected += (sender, e) => Console.WriteLine("Socket disconnected {0}", sender.GetHashCode());
                socket.Disposed += (sender, e) => Console.WriteLine("Socket disposed {0}", sender.GetHashCode());
            });

            server.Start();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
Example #8
0
        public void ReceiverCreationTest()
        {
            const string       channelName    = "channel";
            IReceiver <string> stringReceiver = StringChannel.CreateReceiver(channelName);

            Assert.IsNull(stringReceiver.LastMessage);
            Assert.AreEqual(channelName, stringReceiver.Channel.ChannelName);
        }
Example #9
0
        public void ReusableChannelCreationTest()
        {
            const string      channelName = "channel";
            IChannel <string> channelA    = StringChannel.GetChannel(channelName);
            IChannel <string> channelB    = StringChannel.GetChannel(channelName);

            Assert.AreEqual(channelA, channelB);
        }
Example #10
0
 public void SetChannel(string channelName)
 {
     if (Channel != null)
     {
         Channel.Parsed -= ChannelOnParsed;
     }
     Channel         = StringChannel.GetChannel(channelName);
     Channel.Parsed += ChannelOnParsed;
 }
Example #11
0
        public void MultipleChannelCreationTest()
        {
            const string channelName  = "channel";
            const string channel2Name = "channels";

            IChannel <string> channel1 = StringChannel.GetChannel(channelName);
            IChannel <string> channel2 = StringChannel.GetChannel(channel2Name);

            Assert.AreEqual(channelName, channel1.ChannelName);
            Assert.AreEqual(channel2Name, channel2.ChannelName);
        }
Example #12
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    throw new ArgumentException("Usage: reactiveclient host [port]");
                }

                var host = args[0];
                var port = 1055;

                if (args.Length > 1)
                {
                    port = int.Parse(args[1]);
                }

                var client   = new ReactiveClient(host, port);
                var protocol = new StringChannel(client);

                protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(
                    s => Console.Write(s),
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                client.ConnectAsync().Wait();

                string line = null;

                while ((line = Console.ReadLine()) != "")
                {
                    if (line == "r")
                    {
                        Console.WriteLine("Reconnecting...");
                        client.Disconnect();
                        client.ConnectAsync().Wait();
                        Console.WriteLine("IsConnected = {0}", client.IsConnected);
                    }
                    else
                    {
                        Console.WriteLine("Sending");
                        protocol.SendAsync(line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed: {0}", e);
            }
        }
Example #13
0
        public void UnregisteredChannelTest()
        {
            const int             waitTimeout       = 300;
            const string          channel1          = "channel1";
            const string          channel2          = "channel2";
            const string          message           = "message";
            ITransmitter <string> stringTransmitter = StringChannel.CreateTransmitter(channel1);
            IReceiver <string>    stringReceiver    = StringChannel.CreateReceiver(channel2);

            Assert.IsNull(stringReceiver.LastMessage);
            stringTransmitter.Send(message);

            Thread.Sleep(waitTimeout);
            Assert.IsNull(stringReceiver.LastMessage);
        }
        public void when_parsing_bytes_then_raises_messages()
        {
            var bytes = new BlockingCollection<byte>();
            var socket = Mock.Of<IReactiveSocket>(x => x.Receiver == bytes.GetConsumingEnumerable().ToObservable(TaskPoolScheduler.Default));

            var protocol = new StringChannel(socket);
            var message = "";

            protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(s => message = s);

            protocol.Convert("Hello").ToList().ForEach(b => bytes.Add(b));

            Thread.Sleep(200);

            Assert.NotNull(message);
            Assert.Equal("Hello", message);
        }
Example #15
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                    throw new ArgumentException("Usage: reactiveclient host [port]");

                var host = args[0];
                var port = 1055;

                if (args.Length > 1)
                    port = int.Parse(args[1]);

                var client = new ReactiveClient(host, port);
                var protocol = new StringChannel(client);

                protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(
                    s => Console.Write(s),
                    e => Console.WriteLine(e),
                    () => Console.WriteLine("Socket receiver completed"));

                client.ConnectAsync().Wait();

                string line = null;

                while ((line = Console.ReadLine()) != "")
                {
                    if (line == "r")
                    {
                        Console.WriteLine("Reconnecting...");
                        client.Disconnect();
                        client.ConnectAsync().Wait();
                        Console.WriteLine("IsConnected = {0}", client.IsConnected);
                    }
                    else
                    {
                        Console.WriteLine("Sending");
                        protocol.SendAsync(line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed: {0}", e);
            }
        }
Example #16
0
        public void when_parsing_bytes_then_raises_messages()
        {
            var bytes  = new BlockingCollection <byte>();
            var socket = Mock.Of <IReactiveSocket>(x => x.Receiver == bytes.GetConsumingEnumerable().ToObservable(TaskPoolScheduler.Default));

            var protocol = new StringChannel(socket);
            var message  = "";

            protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(s => message = s);

            protocol.Convert("Hello").ToList().ForEach(b => bytes.Add(b));

            Thread.Sleep(200);

            Assert.NotNull(message);
            Assert.Equal("Hello", message);
        }
Example #17
0
        public void TransmitMessageToSingleReceiverTest()
        {
            bool         waiting = true;
            const string channel = "channel";
            const string message = "message";

            ITransmitter <string> stringTransmitter = StringChannel.CreateTransmitter(channel);
            IReceiver <string>    stringReceiver    = StringChannel.CreateReceiver(channel);

            stringReceiver.Received += (sender, args) =>
            {
                Assert.AreEqual(channel, args.Channel.ChannelName);
                waiting = false;
            };

            stringTransmitter.Send(message);

            while (waiting)
            {
                Thread.Sleep(200);
            }

            Assert.AreEqual(message, stringReceiver.LastMessage);
        }
Example #18
0
        public void MultiTransmitMessageToSingleReceiverTest()
        {
            bool rcv1Waiting = true;
            bool rcv2Waiting = true;

            const string channel  = "channel";
            const string message1 = "message1";
            const string message2 = "message2";

            ITransmitter <string> transmitter1 = StringChannel.CreateTransmitter(channel);
            ITransmitter <string> transmitter2 = StringChannel.CreateTransmitter(channel);
            IReceiver <string>    receiver1    = StringChannel.CreateReceiver(channel);

            receiver1.Received += (sender, args) =>
            {
                if (args.Message.Equals(message1))
                {
                    rcv1Waiting = false;
                }

                if (args.Message.Equals(message2))
                {
                    rcv2Waiting = false;
                }
            };

            transmitter1.Send(message1);
            transmitter2.Send(message2);

            while (rcv1Waiting && rcv2Waiting)
            {
                Thread.Sleep(200);
            }

            Assert.IsNotNull(receiver1.LastMessage);
        }
Example #19
0
 public void SetChannel(string channelName)
 {
     Channel = StringChannel.GetChannel(channelName);
 }