public static void Main(String[] args)
    {
        /* Initialization: create necessary UM objects. */
        LBMContext ctx = new LBMContext();

        /* Create LBMReceiverCallback using the method onReceive defined in this class */
        LBMReceiverCallback rcvCallback = new LBMReceiverCallback(onReceive);

        /* Create receiver objects */
        LBMReceiverAttributes rcv_attr = new LBMReceiverAttributes();
        LBMTopic    rtopic             = new LBMTopic(ctx, "test.topic", rcv_attr);
        LBMReceiver rcv = new LBMReceiver(ctx, rtopic, rcvCallback, null, null);

        /* Initialize and create source */
        LBMTopic  stopic = new LBMTopic(ctx, "test.topic", new LBMSourceAttributes());
        LBMSource src    = new LBMSource(ctx, stopic);

        String msgData = "request";

        byte[] bytes = new byte[msgData.Length * sizeof(char)];
        System.Buffer.BlockCopy(msgData.ToCharArray(), 0, bytes, 0, bytes.Length);

        LBMRequest          req = new LBMRequest(bytes, bytes.Length);
        LBMResponseCallback myResponseCallback = new LBMResponseCallback(onResponse);

        req.addResponseCallback(myResponseCallback);

        /* Sleep for 1 second to allow TR to complete */
        try
        {
            System.Threading.Thread.Sleep(1000);
        }
        catch (Exception ex)
        {
            System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
            System.Environment.Exit(1);
        }

        /* Send a message. */
        src.send(req, LBM.MSG_FLUSH | LBM.SRC_BLOCK);

        while (run == 1)
        {
            try
            {
                System.Threading.Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
                System.Environment.Exit(1);
            }
        }

        /* Cleanup: delete UM objects. */
        req.close();
        src.close();
        rcv.close();
        ctx.close();
    }  /* main */
Beispiel #2
0
        public void Init()
        {
            LBMContext    lbmContext    = new LBMContext();
            LBMEventQueue lbmEventQueue = new LBMEventQueue();

            var topicString = "bxu";

            LBMreqCB lbMreqCallBack = new LBMreqCB(0);

            for (int i = 0; i < 10; i++)
            {
                var        requestMsg = Encoding.UTF8.GetBytes(string.Format("request {0}", i));
                LBMRequest lbmRequest = new LBMRequest(requestMsg, requestMsg.Length);
                lbmRequest.addResponseCallback(lbMreqCallBack.onResponse);

                Console.Out.WriteLine("Sending RequestImmediateAndEvent {0}", i);

                lbmContext.send(topicString, lbmRequest, lbmEventQueue, 0);

                var qTimer = new EQTimer(lbmContext, 5000, lbmEventQueue);
                lbmEventQueue.run(LBM.EVENT_QUEUE_BLOCK);

                Console.Out.WriteLine("Done waiting for responses, {0} response{1} ({2} total bytes) received. Deleting request.\n",
                                      lbMreqCallBack.response_count, (lbMreqCallBack.response_count == 1 ? "" : "s"), lbMreqCallBack.response_byte_count);

                lbMreqCallBack.response_count      = 0;
                lbMreqCallBack.response_byte_count = 0;

                lbmRequest.close();
            }

            Console.ReadLine();
        }
Beispiel #3
0
    public static void main(String[] args)
    {
        /* Initialization: create necessary UM objects. */
        LBMContext ctx = new LBMContext();

        /* Create LBMReceiverCallback using the method onReceive defined in this class */
        LBMReceiverCallback rcvCallback = new LBMReceiverCallback(onReceive);

        /* Create receiver objects */
        LBMReceiverAttributes rcv_attr = new LBMReceiverAttributes();
        LBMTopic rtopic = new LBMTopic(ctx, "test.topic", rcv_attr);
        LBMReceiver rcv = new LBMReceiver(ctx, rtopic, rcvCallback, null, null);

        /* Initialize and create source */
        LBMTopic stopic = new LBMTopic(ctx, "test.topic", new LBMSourceAttributes());
        LBMSource src = new LBMSource(ctx, stopic);

        String msgData = "request";
        byte[] bytes = new byte[msgData.Length * sizeof(char)];
        System.Buffer.BlockCopy(msgData.ToCharArray(), 0, bytes, 0, bytes.Length);

        LBMRequest req = new LBMRequest(bytes, bytes.Length);
        LBMResponseCallback myResponseCallback = new LBMResponseCallback(onResponse);
        req.addResponseCallback(myResponseCallback);

        /* Sleep for 1 second to allow TR to complete */
        try
        {
            System.Threading.Thread.Sleep(1000);
        }
        catch (Exception ex)
        {
            System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
            System.Environment.Exit(1);
        }

        /* Send a message. */
        src.send(req, LBM.MSG_FLUSH | LBM.SRC_BLOCK);

        while (run == 1)
        {
            try
            {
                System.Threading.Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
                System.Environment.Exit(1);
            }
        }

        /* Cleanup: delete UM objects. */
        req.close();
        src.close();
        rcv.close();
        ctx.close();
    }
        public void Init()
        {
            LBMContext ldbmContext = new LBMContext();
            var        topicString = "bxu";

            for (int i = 0; i < 10; i++)
            {
                var        requestMsg = Encoding.UTF8.GetBytes(string.Format("request {0}", i));
                LBMRequest lbmRequest = new LBMRequest(requestMsg, requestMsg.Length);
                lbmRequest.addResponseCallback(onResponse);

                Console.Out.WriteLine("Sending SimpleRequestImmediate {0}", i);
                ldbmContext.send(topicString, lbmRequest, 0);

                Thread.Sleep(1000);
            }
        }
        public void Init()
        {
            LBMContext lbmContext  = new LBMContext();
            var        topicString = "bxu";

            var lbmTopic  = lbmContext.allocTopic(topicString, null);
            var lbmSource = lbmContext.createSource(lbmTopic, onSourceEvent, null, null);

            for (int i = 0; i < 10; i++)
            {
                var        requestMsg = Encoding.UTF8.GetBytes(string.Format("request {0}", i));
                LBMRequest lbmRequest = new LBMRequest(requestMsg, requestMsg.Length);
                lbmRequest.addResponseCallback(onResponse);

                Console.Out.WriteLine("Sending SimpleRequestNOImmediate {0}", i);
                lbmSource.send(lbmRequest, 0);

                Thread.Sleep(100);
            }

            Console.ReadLine();
        }
Beispiel #6
0
        public void Init()
        {
            LBMContext    lbmContext    = new LBMContext();
            LBMEventQueue lbmEventQueue = new LBMEventQueue();

            var topicString = "bxu";
            var lbmTopic    = lbmContext.allocTopic(topicString, null);
            var lbmSource   = lbmContext.createSource(lbmTopic, onSourceEvent, null, null);

            for (int i = 0; i < 10; i++)
            {
                var        requestMsg = Encoding.UTF8.GetBytes(string.Format("request {0}", i));
                LBMRequest lbmRequest = new LBMRequest(requestMsg, requestMsg.Length);
                lbmRequest.addResponseCallback(onResponse);

                Console.Out.WriteLine("Sending RequestNOImmediateAndEvent {0}", i);

                lbmSource.send(lbmRequest, lbmEventQueue, 0);

                var qTimer = new EQTimer(lbmContext, 5000, lbmEventQueue);
                lbmEventQueue.run(LBM.EVENT_QUEUE_BLOCK);
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            if (Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null &&
                Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null)
            {
                SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt");
            }

            LBM lbm = new LBM();

            lbm.setLogger(logger);

            string target             = null;
            int    send_rate          = 0;              //	Used for lbmtrm | lbtru transports
            int    retrans_rate       = 0;              //
            char   protocol           = '\0';           //
            int    linger             = 5;
            int    msglen             = MIN_ALLOC_MSGLEN;
            int    pause_milliseconds = 5;
            int    delay = 1;
            int    i;
            int    n     = args.Length;
            bool   error = false;
            bool   done  = false;

            for (i = 0; i < n; i++)
            {
                try
                {
                    switch (args[i])
                    {
                    case "-c":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        try
                        {
                            LBM.setConfiguration(args[i]);
                        }
                        catch (LBMException Ex)
                        {
                            Console.Error.WriteLine("lbmreq error: " + Ex.Message);
                            error = true;
                        }
                        break;

                    case "-d":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        delay = Convert.ToInt32(args[i]);
                        break;

                    case "-h":
                        print_help_exit(0);
                        break;

                    case "-i":
                        send_immediate = true;
                        break;

                    case "-q":
                        eventq = true;
                        break;

                    case "-l":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        msglen = Convert.ToInt32(args[i]);
                        break;

                    case "-L":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        linger = Convert.ToInt32(args[i]);
                        break;

                    case "-P":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        pause_milliseconds = Convert.ToInt32(args[i]);
                        break;

                    case "-R":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        requests = Convert.ToInt32(args[i]);
                        break;

                    case "-r":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        ParseRateVars parseRateVars = lbmExampleUtil.parseRate(args[i]);
                        if (parseRateVars.error)
                        {
                            print_help_exit(1);
                        }
                        send_rate    = parseRateVars.rate;
                        retrans_rate = parseRateVars.retrans;
                        protocol     = parseRateVars.protocol;
                        break;

                    case "-s":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        stats_sec = Convert.ToInt32(args[i]);
                        break;

                    case "-T":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        target = args[i];
                        break;

                    case "-v":
                        verbose++;
                        break;

                    default:
                        if (args[i].StartsWith("-"))
                        {
                            error = true;
                        }
                        else
                        {
                            done = true;
                        }
                        break;
                    }
                    if (error || done)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    /* type conversion exception */
                    Console.Error.WriteLine("lbmreq: error\n" + e.Message + "\n");
                    print_help_exit(1);
                }
            }
            if (error || i >= n)
            {
                /* An error occurred processing the command line - print help and exit */
                print_help_exit(1);
            }
            string topic_str = null;

            if (i >= n)
            {
                if (!send_immediate)
                {
                    print_help_exit(1);
                }
            }
            else
            {
                topic_str = args[i];
            }

            byte[] message = null;

            /* if message buffer is too small, then the enc.GetBytes will cause issues.
             *          Therefore, allocate with a MIN_ALLOC_MSGLEN */
            if (msglen < MIN_ALLOC_MSGLEN)
            {
                message = new byte[MIN_ALLOC_MSGLEN];
            }
            else
            {
                message = new byte[msglen];
            }

            LBMSourceAttributes  lbmSourceAttributes  = new LBMSourceAttributes();
            LBMContextAttributes lbmContextAttributes = new LBMContextAttributes();

            /* Check if protocol needs to be set to lbtrm | lbtru */
            if (protocol == 'M')
            {
                try
                {
                    lbmSourceAttributes.setValue("transport", "LBTRM");

                    lbmContextAttributes.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString());
                    lbmContextAttributes.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message);
                    Environment.Exit(1);
                }
            }
            if (protocol == 'U')
            {
                try
                {
                    lbmSourceAttributes.setValue("transport", "LBTRU");

                    lbmContextAttributes.setValue("transport_lbtru_data_rate_limit", send_rate.ToString());
                    lbmContextAttributes.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message);
                    Environment.Exit(1);
                }
            }

            LBMContext       ctx = new LBMContext(lbmContextAttributes);
            LBMreqEventQueue lbmReqEventQueue = null;

            if (eventq)
            {
                lbmReqEventQueue = new LBMreqEventQueue();
                Console.Error.WriteLine("Event queue in use.");
            }
            else
            {
                Console.Error.WriteLine("No event queue\n");
            }

            LBMTopic  topic;
            LBMSource src            = null;
            LBMreqCB  lbMreqCallBack = new LBMreqCB(verbose);

            if (!send_immediate)
            {
                topic = ctx.allocTopic(topic_str, lbmSourceAttributes);
                src   = ctx.createSource(topic, lbMreqCallBack.onSourceEvent, null, lbmReqEventQueue);
                if (delay > 0)
                {
                    Console.Out.WriteLine("Delaying requests for {0} second{1}...\n",
                                          delay, ((delay > 1) ? "s" : ""));
                    Thread.Sleep(delay * 1000);
                }
            }
            ASCIIEncoding enc = new ASCIIEncoding();

            if (requests > 0)
            {
                Console.Out.WriteLine("Will send {0} request{1}\n", requests, (requests == 1 ? "" : "s"));
            }

            Console.Out.Flush();

            for (int count = 0; count < requests; count++)
            {
                LBMTimer      qTimer;
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Request data {0}", count);
                enc.GetBytes(sb.ToString(), 0, sb.ToString().Length, message, 0);

                LBMRequest req = new LBMRequest(message, msglen);
                req.addResponseCallback(lbMreqCallBack.onResponse);

                Console.Out.WriteLine("Sending request " + count);

                if (send_immediate)
                {
                    if (target == null)
                    {
                        if (eventq)
                        {
                            ctx.send(topic_str, req, lbmReqEventQueue, 0);
                        }
                        else
                        {
                            ctx.send(topic_str, req, 0);
                        }
                    }
                    else
                    {
                        if (eventq)
                        {
                            ctx.send(target, topic_str, req, lbmReqEventQueue, 0);
                        }
                        else
                        {
                            ctx.send(target, topic_str, req, 0);
                        }
                    }
                }
                else
                {
                    if (eventq)
                    {
                        src.send(req, lbmReqEventQueue, 0);
                    }
                    else
                    {
                        src.send(req, 0);
                    }
                }

                if (verbose > 0)
                {
                    Console.Out.Write("Sent request " + count + ". ");
                }

                if (!eventq)
                {
                    if (verbose > 0)
                    {
                        Console.Out.WriteLine("Pausing " + pause_milliseconds + " seconds.");
                    }

                    Thread.Sleep(pause_milliseconds);
                }
                else
                {
                    if (verbose > 0)
                    {
                        Console.Out.WriteLine("Creating timer for " + pause_milliseconds + " seconds and initiating event pump.");
                    }

                    qTimer = new EQTimer(ctx, pause_milliseconds, lbmReqEventQueue);
                    lbmReqEventQueue.run(LBM.EVENT_QUEUE_BLOCK);
                }

                Console.Out.WriteLine("Done waiting for responses, {0} response{1} ({2} total bytes) received. Deleting request.\n",
                                      lbMreqCallBack.response_count, (lbMreqCallBack.response_count == 1 ? "" : "s"), lbMreqCallBack.response_byte_count);

                lbMreqCallBack.response_count      = 0;
                lbMreqCallBack.response_byte_count = 0;

                req.close();

                Console.Out.Flush();
            }//end of for

            if (linger > 0)
            {
                Console.Out.WriteLine("\nLingering for {0} second{1}...\n", linger, ((linger > 1) ? "s" : ""));
                Thread.Sleep(linger * 1000);
            }

            Console.Out.WriteLine("Quitting...");
            if (src != null)
            {
                src.close();
            }
            ctx.close();
        }