示例#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();
                }
            }
        }
示例#3
0
 public void Close()
 {
     if (bus != null)
     {
         bus.close();
         bus = null;
     }
     if (talkerConnection != null)
     {
         talkerConnection.close(); // not sure why this locks up
         talkerConnection = null;
     }
     if (talkerConnectionListener != null)
     {
         talkerConnectionListener.Close();
         talkerConnectionListener = null;
     }
     if (ptpTalkerSession != null)
     {
         ptpTalkerSession.close();
         ptpTalkerSession = null;
     }
 }
示例#4
0
 public T onMessage(IPTPSession <T> session, ITransport transport, IMessage <T> message)
 {
     messageReceivedEvent(this, message.Body.ToString());
     return(default(T));
 }
示例#5
0
 public String onMessage(IPTPSession <String> session, ITransport transport, IMessage <String> message)
 {
     Console.WriteLine("Received PTP session call: " + message.Body);
     return("Hello from RPC/PTP");
 }