Пример #1
0
        public TalkerSession(SessionTypeEnum sessionType, string busAddress)
        {
            topLevelTreeNode = null;
            bus = MQFactory.Instance.createMessagingBus();
            if (sessionType == SessionTypeEnum.Server)
            {
                talkerConnection = bus.create(new Uri(busAddress));
                ptpTalkerSession = talkerConnection.createPTPSession <T>("serverPTP", "ptpSimpleSession");
            }
            else if (sessionType == SessionTypeEnum.Client)
            {
                talkerConnection = bus.connect(new Uri(busAddress));
                ptpTalkerSession = talkerConnection.createPTPSession <T>("clientPTP", "ptpSimpleSession");
            }
            else
            {
                throw new Exception("Session Type must be either Server or Client");
            }
            this.sessionType = sessionType;

            talkerConnectionListener = new TalkerConnectionListener();
            talkerConnection.addListener(talkerConnectionListener);
            ptpTalkerSession.addListener(this);

            talkerConnection.start();
        }
Пример #2
0
        public void testPTPSession()
        {
            IMessagingBus        bus = MQFactory.Instance.createMessagingBus();
            IMQConnection        serverConnection = null;
            IMQConnection        clientConnection = null;
            IPTPSession <String> ptpClientSession = null;
            IPTPSession <String> ptpServerSession = null;

            try {
                serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                ptpServerSession = serverConnection.createPTPSession <String>("serverPTP", "ptpSimpleSession");
                ptpServerSession.addListener(new TestPTPSessionListener());
                serverConnection.start();

                clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333"));
                ptpClientSession = clientConnection.createPTPSession <String>("clientPTP", "ptpSimpleSession");
                ptpClientSession.addListener(new TestPTPSessionListener());
                clientConnection.start();

                string result = ptpClientSession.call("Hello from PTP Client", 20);
                Assert.Equals(result, "Hello from RPC/PTP");
                ptpClientSession.callAsync("Hello from Server 2", new TestRPCAsyncCallBack(), 20);

                Thread.Sleep(2000);
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                throw e;
            }
            finally {
                if (ptpClientSession != null)
                {
                    ptpClientSession.close();
                }
                if (ptpServerSession != null)
                {
                    ptpServerSession.close();
                }

                if (clientConnection != null)
                {
                    clientConnection.close();
                }
                if (serverConnection != null)
                {
                    serverConnection.close();
                }
                if (bus != null)
                {
                    bus.close();
                }
            }
        }