예제 #1
0
        public void testPollingUnSubscribe()
        {
            PollingClient client = new PollingClient(SUB_PORT);

            try
            {
                client.subscribe(REMOTE_HOST, REMOTE_PORT, REMOTE_TABLE_NAME, 0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.Write(ex.StackTrace);
                Assert.Fail(ex.Message);
            }
            PollingClient client1 = new PollingClient(SUB_PORT);

            try
            {
                client1.unsubscribe(REMOTE_HOST, REMOTE_PORT, REMOTE_TABLE_NAME);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
예제 #2
0
    public virtual void PollingClient()
    {
        PollingClient client = new PollingClient(subscribePORT);

        try
        {
            TopicPoller poller1 = client.subscribe(HOST, PORT, "Trades");
            int         count   = 0;
            bool        started = false;
            long        start   = DateTime.Now.Ticks;
            long        last    = DateTime.Now.Ticks;
            while (true)
            {
                List <IMessage> msgs = poller1.poll(1000);
                if (msgs == null)
                {
                    count = 0;
                    start = DateTime.Now.Ticks;
                    continue;
                }
                if (msgs.Count > 0 && started == false)
                {
                    started = true;
                    start   = DateTime.Now.Ticks;
                }

                count += msgs.Count;
                for (int i = 0; i < msgs.Count; ++i)
                {
                    BasicTime time = (BasicTime)msgs[i].getEntity(1);
                    Console.Write("time:" + time + " ");
                    string symbol = msgs[i].getEntity(2).getString();
                    Console.Write("sym:" + symbol + " ");
                    int qty = ((BasicInt)msgs[i].getEntity(3)).getValue();
                    Console.Write("qty:" + qty + " ");
                    double?price = ((BasicDouble)msgs[i].getEntity(4)).getValue();
                    Console.Write("price:" + price + " \n");
                }
                if (msgs.Count > 0)
                {
                    if (((BasicInt)msgs[msgs.Count - 1].getEntity(0)).getValue() == -1)
                    {
                        break;
                    }
                }
                long now = DateTime.Now.Ticks;
                if (now - last >= 1000)
                {
                    long endtime = DateTime.Now.Ticks;
                    Console.WriteLine(count + " messages took " + (endtime - start) + "ms, throughput: " + count / ((endtime - start) / 1000.0) + " messages/s");
                    last = now;
                }
            }
            long end = DateTime.Now.Ticks;
            Console.WriteLine(count + " messages took " + (end - start) + "ms, throughput: " + count / ((end - start) / 1000.0) + " messages/s");
            client.unsubscribe(HOST, PORT, "Trades");
        }
        catch (IOException e)
        {
            Console.WriteLine(e.ToString());
            Console.Write(e.StackTrace);
        }
        Environment.Exit(0);
    }