Ejemplo n.º 1
0
    static void Main(String[] args)
    {
        LBMContext          ctx       = null;                               /* Context object: container for UM "instance". */
        LBMReceiver         lateRcv   = null;                               /* Receiver object: for sending messages. */
        LBMReceiverCallback cb        = new LBMReceiverCallback(onReceive); /* Wrapping the onReceive functor in a callback */
        LBMSource           early_src = null;                               /* Source object: for sending messages. */

        ctx = new LBMContext();


        try
        {
            LBMTopic            srcTopic = null;
            LBMSourceAttributes srcAttr  = null;

            srcAttr = new LBMSourceAttributes();

            srcAttr.setValue("late_join", "1");
            srcAttr.setValue("retransmit_retention_size_threshold", "1");

            srcTopic  = ctx.allocTopic("test.topic", srcAttr);
            early_src = new LBMSource(ctx, srcTopic);

            early_src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error initializing LBM objects:  " + ex.Message);
            System.Environment.Exit(1);
        }

        {
            LBMTopic topic = null;
            topic = ctx.lookupTopic("test.topic");

            lateRcv = new LBMReceiver(ctx, topic, onReceive, null, null);
        }

        Thread.Sleep(100);

        try {
            early_src.close();
            lateRcv.close();
            ctx.close();
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }
    }
Ejemplo n.º 2
0
    static void Main(String[] args)
    {
        LBMContext ctx = null;      /* Context object: container for UM "instance". */
        LBMReceiver lateRcv = null; /* Receiver object: for sending messages. */
        LBMReceiverCallback cb = new LBMReceiverCallback(onReceive);    /* Wrapping the onReceive functor in a callback */
        LBMSource early_src = null;   /* Source object: for sending messages. */

        ctx = new LBMContext();

        try
        {
            LBMTopic srcTopic = null;
            LBMSourceAttributes srcAttr = null;

            srcAttr = new LBMSourceAttributes();

            srcAttr.setValue("late_join", "1");
            srcAttr.setValue("retransmit_retention_size_threshold", "1");

            srcTopic = ctx.allocTopic("test.topic", srcAttr);
            early_src = new LBMSource(ctx, srcTopic);

            early_src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error initializing LBM objects:  " + ex.Message);
            System.Environment.Exit(1);
        }

        {
            LBMTopic topic = null;
            topic = ctx.lookupTopic("test.topic");

            lateRcv = new LBMReceiver(ctx, topic, onReceive, null, null);
        }

        Thread.Sleep(100);

        try {
            early_src.close();
            lateRcv.close();
            ctx.close();
        }
        catch(LBMException ex)
        {
            System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }
    }
Ejemplo n.º 3
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
        LBMSource src = null; /* Source object: for sending messages. */
        LBM lbm = new LBM();

        /*** Initialization: create necessary UM objects. ***/
        try
        {
            LBMTopic topic = null;
            LBMSourceAttributes srcAttr = null;

            lbm.setLogger(new LBMLogging(logger));

            ctx = new LBMContext();
            srcAttr = new LBMSourceAttributes();
            srcAttr.setValue("late_join", "1");
            topic = ctx.allocTopic("test.topic", srcAttr);
            src = ctx.createSource(topic, null, null, null);
        }
        catch (LBMException ex)
        {
            System.Console.Error.Write("Error initializing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }

        /* Cleanup */
        src.close();
        ctx.close();
    }
Ejemplo n.º 4
0
        } // UmCtxCreate

        private void UmSrcCreate()
        {
            LBMSourceAttributes srcAttr = new LBMSourceAttributes("29west_tmon_context", _topicName);

            // Configure the tmon source.
            if (_cfgFile != null)
            {
                SourceAttrSetoptFromFile(srcAttr, _cfgFile);
            }

            // Any options supplied in transport_opts override
            // Step through transport options to find source opts
            foreach (var opt in _transportOpts)
            {
                string[] keyVal = opt.Split('=');
                if (keyVal.Length != 2)
                {
                    throw new TmonException("invalid transport option '" + opt + "' in '" + _transportOptsStr + "'");
                }
                string[] scopeOpt = keyVal[0].Split('|');
                if (scopeOpt.Length == 2 &&
                    scopeOpt[0].Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    srcAttr.setValue(scopeOpt[1], keyVal[1]);
                }
            } // foreach

            LBMTopic topic = _tmonUmContext.allocTopic(_topicName, srcAttr);

            _tmonUmSource = _tmonUmContext.createSource(topic, null, null, null);
        } // UmSrcCreate
Ejemplo n.º 5
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
        LBMSource  src = null; /* Source object: for sending messages. */
        LBM        lbm = new LBM();

        /*** Initialization: create necessary UM objects. ***/
        try
        {
            LBMTopic            topic   = null;
            LBMSourceAttributes srcAttr = null;

            lbm.setLogger(new LBMLogging(logger));

            ctx     = new LBMContext();
            srcAttr = new LBMSourceAttributes();
            srcAttr.setValue("late_join", "1");
            topic = ctx.allocTopic("test.topic", srcAttr);
            src   = ctx.createSource(topic, null, null, null);
        }
        catch (LBMException ex)
        {
            System.Console.Error.Write("Error initializing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }

        /* Cleanup */
        src.close();
        ctx.close();
    } /* main */
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null &&
                System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null)
            {
                SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt");
            }
            LBM lbm = new LBM();

            lbm.setLogger(new LBMLogging(logger));

            int    send_rate    = 0;                                                    //	Used for lbmtrm | lbtru transports
            int    retrans_rate = 0;                                                    //
            char   protocol     = '\0';                                                 //
            int    linger       = 5;
            int    delay        = 1;
            string target       = null;
            string topic        = null;
            int    msglen       = 25;
            long   bytes_sent   = 0;
            int    pause        = 0;
            int    i;
            int    n          = args.Length;
            bool   error      = false;
            bool   done       = false;
            bool   topic_less = 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)
                        {
                            System.Console.Error.WriteLine("lbmimsg 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 "-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 "-M":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        msgs = Convert.ToInt32(args[i]);
                        break;

                    case "-o":
                        topic_less = true;
                        break;

                    case "-P":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        pause = 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 "-T":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        target = args[i];
                        break;

                    default:
                        if (args[i].StartsWith("-"))
                        {
                            error = true;
                        }
                        else
                        {
                            done = true;
                        }
                        break;
                    }
                    if (error || done)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    /* type conversion exception */
                    System.Console.Error.WriteLine("lbmimsg: error\n" + e.Message + "\n");
                    print_help_exit(1);
                }
            }

            if (error || (i >= n && !topic_less))
            {
                /* An error occurred processing the command line - print help and exit */
                print_help_exit(1);
            }

            if (n > i && topic_less)
            {
                /* User chose topic-less and yet specified a topic - print help and exit */
                System.Console.Error.WriteLine("lbmimsg: error--selected topic-less option and still specified topic");
                print_help_exit(1);
            }

            if (i < n)
            {
                topic = args[i];
            }

            byte [] message = new byte[msglen];

            LBMSourceAttributes  sattr = new LBMSourceAttributes();
            LBMContextAttributes cattr = new LBMContextAttributes();

            /* Check if protocol needs to be set to lbtrm | lbtru */
            if (protocol == 'M')
            {
                try
                {
                    sattr.setValue("transport", "LBTRM");
                    cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }
            if (protocol == 'U')
            {
                try
                {
                    sattr.setValue("transport", "LBTRU");
                    cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }

            LBMContext ctx = new LBMContext(cattr);

            if (delay > 0)
            {
                System.Console.Out.WriteLine("Will start sending in {0} second{1}...\n",
                                             delay, ((delay > 1) ? "s" : ""));

                System.Threading.Thread.Sleep(delay * 1000);
            }

            System.Console.Out.WriteLine("Sending {0}{1} immediate messages of size {2} bytes to target <{3}> topic <{4}>\n",
                                         msgs, (topic_less == true ? " topic-less" : ""), msglen,
                                         (target == null ? "" : target), (topic == null ? "" : topic));
            System.Console.Out.Flush();
            long start_time = System.DateTime.Now.Ticks;

            for (int count = 0; count < msgs; count++)
            {
                try
                {
                    if (target == null)
                    {
                        ctx.send(topic, message, msglen, 0);
                    }
                    else
                    {
                        ctx.send(target, topic, message, msglen, 0);
                    }
                }
                catch (LBMException ex)
                {
                    if (target != null && ex.errorNumber() == LBM.EOP)
                    {
                        System.Console.Error.WriteLine("LBM send() error: no connection to target while sending unicast immediate message");
                    }
                    else
                    {
                        System.Console.Error.WriteLine("LBM send() error: " + ex.Message);
                    }
                }
                bytes_sent += msglen;
                if (pause > 0)
                {
                    System.Threading.Thread.Sleep(pause);
                }
            }
            long   end_time = System.DateTime.Now.Ticks;
            double secs     = (end_time - start_time) / 10000000.0;

            System.Console.Out.WriteLine("Sent {0} messages of size {1} bytes in {2} seconds.\n",
                                         msgs, msglen, secs);

            print_bw(secs, msgs, bytes_sent);
            System.Console.Out.Flush();
            if (linger > 0)
            {
                System.Console.Out.WriteLine("Lingering for {0} second{1}...\n",
                                             linger, ((linger > 1) ? "s" : ""));
                System.Threading.Thread.Sleep(linger * 1000);
            }
        }
Ejemplo n.º 7
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
        LBMSource  src = null; /* Source object: for sending messages. */

        SrcCB srccb = null;

        /*** Initialization: create necessary UM objects. ***/
        try
        {
            LBMTopic            topic   = null;
            LBMSourceAttributes srcAttr = null;

            srccb   = new SrcCB();
            ctx     = new LBMContext();
            srcAttr = new LBMSourceAttributes();
            srcAttr.setValue("ume_store", "127.0.0.1:29999");
            srcAttr.setValue("ume_store_behavior", "qc");
            topic = ctx.allocTopic("test.topic", srcAttr);
            src   = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null);
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }

        while (true)
        {
            if (srcReady == 1)
            {
                /*** Send a message. ***/
                try
                {
                    src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }
                catch (LBMException ex)
                {
                    /* Error trying to send, wait 1 second and try again */
                    try
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                    catch (Exception eex)
                    {
                        System.Console.Error.WriteLine("Error Thread.sleep interrupted: " + eex.Message);
                        System.Environment.Exit(1);
                    }
                }
            }
            else
            {
                /* No quorum, wait 1 second and check again */
                System.Console.Out.Write("Source is not ready to send (no quorum)");
                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception eex)
                {
                    System.Console.Error.WriteLine("Error Thread.sleep interrupted: " + eex.Message);
                    System.Environment.Exit(1);
                }
            }
        }
    } /* main */
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            LBMContext          ctx     = null; /* Container for UM instance */
            LBMTopic            topic1  = null; /* Object used to create topic */
            LBMTopic            topic2  = null; /* Object used to create topic */
            LBMSource           src1    = null; /* Used for sending messages on a single topic */
            LBMSource           src2    = null; /* Used for sending messages on a single topic */
            LBMSourceAttributes srcAttr = null; /* Object used to configure sources */
            int resPort;
            int desPort;

            /* We are using certain lbm objects that require an application level   */
            /* memory manager called the LBMObjectRecycler to cleanup               */
            LBMObjectRecycler objRec = new LBMObjectRecycler();

            try
            {
                /* create ctxAttr to set config values before creating context */
                LBMContextAttributes ctxAttr = new LBMContextAttributes();
                ctxAttr.setObjectRecycler(objRec, null);

                /* Modify resolver address by setting attributes */
                ctxAttr.setValue("resolver_multicast_address", "224.10.11.12");

                /* Create a context with default attributes */
                ctx = new LBMContext(ctxAttr);
                /* Create source attributes object, used to configure sources */
                srcAttr = new LBMSourceAttributes();
                srcAttr.setObjectRecycler(objRec, null);

                /* Set configuration value using strings */
                srcAttr.setValue("transport", "lbtrm");

                /* The Java API only accepts string values. ints, for example */
                /* must be converted to strings */
                desPort = 14001;
                srcAttr.setValue("transport_lbtrm_destination_port", desPort.ToString());

                /* Create topic for the first source with configured attributes */
                topic1 = new LBMTopic(ctx, "test.topic1", srcAttr);
                src1   = new LBMSource(ctx, topic1);
                /* Modify Configuration for second topic to use a new port */
                desPort = 14002;
                srcAttr.setValue("transport_lbtrm_destination_port", desPort.ToString());

                /* Create second topic and source using modified configuration values */
                topic2 = new LBMTopic(ctx, "test.topic2", srcAttr);
                src2   = new LBMSource(ctx, topic2);
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
            System.Console.Out.WriteLine("Context Attributes: ");
            List <LBMConfigOption> cfgOptList = ctx.dumpAttributeList();

            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            System.Console.Out.WriteLine("Source #1 Attributes: ");
            cfgOptList = src1.dumpAttributeList();
            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            System.Console.Out.WriteLine("Source #2 Attributes: ");
            cfgOptList = src2.dumpAttributeList();
            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            /* Cleanup all LBM objects */
            try
            {
                objRec.close();
                src2.close();
                src1.close();
                ctx.close();
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
        }
Ejemplo n.º 9
0
        public static int Main(string[] args)
        {
            lbmlatping latping = null;

            LBMContext           ctx      = null;
            LBMContextAttributes ctx_attr = null;

            LBMTopic            ping_src_topic      = null;
            LBMSourceAttributes ping_src_topic_attr = null;
            LBMSource           ping_src            = null;

            LBMTopic pong_rcv_topic = null;
            LBMReceiverAttributes pong_rcv_topic_attr = null;
            lbmlatpingreceiver    pong_rcv            = null;

            latping = new lbmlatping(args);
            if (latping.cpu >= 0)
            {
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latping.cpu);
            }
            try
            {
                /* Create the context. */
                ctx_attr = new LBMContextAttributes();
                ctx_attr.setValue("resolver_cache", "0");
                ctx_attr.setValue("operational_mode", "sequential");
                ctx_attr.setValue("request_tcp_port_high", "50000");
                ctx = new LBMContext(ctx_attr);
                ctx_attr.dispose();

                /* Create the ping source. */
                ping_src_topic_attr = new LBMSourceAttributes();
                ping_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0");
                ping_src_topic_attr.setValue("transport", "lbtsmx");
                ping_src_topic = new LBMTopic(ctx, "lbmlat-ping", ping_src_topic_attr);
                ping_src_topic_attr.dispose();
                ping_src         = new LBMSource(ctx, ping_src_topic);
                latping.ping_src = ping_src;

                /* Perform some configuration validation */
                const int smx_header_size  = 16;
                int       max_payload_size =
                    Convert.ToInt32(ping_src.getAttributeValue("transport_lbtsmx_datagram_max_size")) + smx_header_size;
                if (latping.msgbuf.Length > max_payload_size)
                {
                    /* The SMX transport doesn't fragment, so payload must be within maximum size limits */
                    System.Console.WriteLine("Error: Message size requested is larger than configured SMX datagram size.");
                    System.Environment.Exit(1);
                }

                /* Create the pong receiver. */
                pong_rcv_topic_attr = new LBMReceiverAttributes();
                pong_rcv_topic_attr.enableSingleReceiverCallback(true);
                pong_rcv_topic = new LBMTopic(ctx, "lbmlat-pong", pong_rcv_topic_attr);
                pong_rcv_topic_attr.dispose();
                pong_rcv = new lbmlatpingreceiver(ctx, pong_rcv_topic, latping);

                /* Run the context just long enough to advertise. */
                ctx.processEvents(1000);

                /* The ponger kicks things off as soon as he's discovered our ping source. */
                while (true)
                {
                    System.Threading.Thread.Sleep(1000000);
                    //ctx.processEvents(1000000);
                }
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine(e.ToString());
            }
            return(0);
        }
        static void Main(string[] args)
        {
            LBMContext ctx = null;  /* Context object: container for UM "instance". */
            LBMSource src = null;   /* Source object: for sending messages. */

            try
            {
                LBMTopic topic = null;
                LBMSourceAttributes srcAttr = null;

                ctx = new LBMContext();
                srcAttr = new LBMSourceAttributes();
                srcAttr.setValue("ume_store", "127.0.0.1:29999");
                srcAttr.setValue("ume_flight_size", maxFlightSize.ToString());
                topic = ctx.allocTopic("test.topic", srcAttr);
                src = new LBMSource(ctx, topic);
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error initializing LBM objects:  " + ex.Message);
                System.Environment.Exit(1);
            }

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

            while (true)
            {
                /*** Send a message. ***/
                try
                {
                    src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }
                catch (LBMEWouldBlockException ex)
                {
                    try
                    {
                        int currentFlightSize = src.getInflight(LBM.FLIGHT_SIZE_TYPE_UME);

                        if (currentFlightSize == maxFlightSize)
                        {
                            System.Console.Error.WriteLine("Source is blocked on flight. Exiting");
                            break;
                        }
                    }
                    catch (LBMException exInflight)
                    {
                        System.Console.Error.WriteLine("Error getting flightsize: " + exInflight.Message);
                    }
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error sending: " + ex.Message);
                }
            }

            /*** Cleanup: delete UM objects. ***/
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
                System.Environment.Exit(1);
            }

            try
            {
                src.close();
                ctx.close();
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
        }
Ejemplo n.º 11
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
        LBMSource src = null; /* Source object: for sending messages. */

        SrcCB srccb = null;

        /*** Initialization: create necessary UM objects. ***/
        try
        {
            LBMTopic topic = null;
            LBMSourceAttributes srcAttr = null;

            srccb = new SrcCB();
            ctx = new LBMContext();
            srcAttr = new LBMSourceAttributes();
            srcAttr.setValue("ume_store", "127.0.0.1:29999");
            srcAttr.setValue("ume_store_behavior", "qc");
            topic = ctx.allocTopic("test.topic", srcAttr);
            src = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null);
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }

        while (true)
        {
            if (srcReady == 1)
            {
                /*** Send a message. ***/
                try
                {
                    src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }
                catch (LBMException ex)
                {
                    /* Error trying to send, wait 1 second and try again */
                    try
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                    catch (Exception eex)
                    {
                        System.Console.Error.WriteLine("Error Thread.sleep interrupted: " + eex.Message);
                        System.Environment.Exit(1);
                    }
                }
            }
            else
            {
                /* No quorum, wait 1 second and check again */
                System.Console.Out.Write("Source is not ready to send (no quorum)");
                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception eex)
                {
                    System.Console.Error.WriteLine("Error Thread.sleep interrupted: " + eex.Message);
                    System.Environment.Exit(1);
                }
            }
        }
    }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            LBMContext ctx = null;  /* Context object: container for UM "instance". */
            LBMSource  src = null;  /* Source object: for sending messages. */

            try
            {
                LBMTopic            topic   = null;
                LBMSourceAttributes srcAttr = null;

                ctx     = new LBMContext();
                srcAttr = new LBMSourceAttributes();
                srcAttr.setValue("ume_store", "127.0.0.1:29999");
                srcAttr.setValue("ume_flight_size", maxFlightSize.ToString());
                topic = ctx.allocTopic("test.topic", srcAttr);
                src   = new LBMSource(ctx, topic);
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error initializing LBM objects:  " + ex.Message);
                System.Environment.Exit(1);
            }

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

            while (true)
            {
                /*** Send a message. ***/
                try
                {
                    src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }
                catch (LBMEWouldBlockException ex)
                {
                    try
                    {
                        int currentFlightSize = src.getInflight(LBM.FLIGHT_SIZE_TYPE_UME);

                        if (currentFlightSize == maxFlightSize)
                        {
                            System.Console.Error.WriteLine("Source is blocked on flight. Exiting");
                            break;
                        }
                    }
                    catch (LBMException exInflight)
                    {
                        System.Console.Error.WriteLine("Error getting flightsize: " + exInflight.Message);
                    }
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error sending: " + ex.Message);
                }
            }

            /*** Cleanup: delete UM objects. ***/
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine("Error System.Threading.Thread.Sleep() exception:  " + ex.Message);
                System.Environment.Exit(1);
            }

            try
            {
                src.close();
                ctx.close();
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
        } /* Main */
Ejemplo n.º 13
0
        private lbmpong(string[] args)
        {
            if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null &&
                System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null)
            {
                SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt");
            }
            LBM lbm = new LBM();

            lbm.setLogger(new LBMLogging(logger));

            process_cmdline(args);

            if (use_mim && !eventq)
            {
                System.Console.Out.WriteLine("Using mim requires event queue to send from receive callback - forcing use");
                eventq = true;
            }
            if (msecpause > 0 && !eventq)
            {
                System.Console.Out.WriteLine("Setting pause value requires event queue - forcing use");
                eventq = true;
            }
            LBMSourceAttributes  sattr = new LBMSourceAttributes();
            LBMContextAttributes cattr = new LBMContextAttributes();

            /* Check if protocol needs to be set to lbtrm | lbtru */
            if (protocol == 'M')
            {
                try
                {
                    sattr.setValue("transport", "LBTRM");
                    cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }
            if (protocol == 'U')
            {
                try
                {
                    sattr.setValue("transport", "LBTRU");
                    cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }

            LBMContext        ctx = new LBMContext(cattr);
            PongLBMEventQueue evq = null;

            if (eventq)
            {
                System.Console.Error.WriteLine("Event queue in use");
                evq = new PongLBMEventQueue();
            }
            else
            {
                System.Console.Error.WriteLine("No event queue");
            }
            System.Console.Out.Flush();
            LBMSource       src = null;
            PongLBMReceiver rcv;
            LBMTopic        src_topic = null;
            LBMTopic        rcv_topic;

            if (ping)
            {
                System.Console.Error.WriteLine(
                    "Sending " + msgs + " " + msglen +
                    " byte messages to topic lbmpong/ping pausing "
                    + msecpause + " msec between");
                if (!use_mim)
                {
                    src_topic = ctx.allocTopic("lbmpong/ping", sattr);
                }
                rcv_topic = ctx.lookupTopic("lbmpong/pong");
            }
            else
            {
                rcv_topic = ctx.lookupTopic("lbmpong/ping");
                if (!use_mim)
                {
                    src_topic = ctx.allocTopic("lbmpong/pong", sattr);
                }
            }
            PongSrcCB srccb = new PongSrcCB();

            if (!use_mim)
            {
                src     = ctx.createSource(src_topic, new LBMSourceEventCallback(srccb.onSourceEvent), null);
                use_smx = src.getAttributeValue("transport").ToLower().Contains("smx");

                if (use_smx)
                {
                    /* Perform configuration validation */
                    const int smx_header_size  = 16;
                    int       max_payload_size =
                        Convert.ToInt32(src.getAttributeValue("transport_lbtsmx_datagram_max_size")) + smx_header_size;
                    if (msglen > max_payload_size)
                    {
                        /* The SMX transport doesn't fragment, so payload must be within maximum size limits */
                        System.Console.WriteLine("Error: Message size requested is larger than configured SMX datagram size.");
                        System.Environment.Exit(1);
                    }
                }
            }
            rcv = new PongLBMReceiver(ctx, rcv_topic, evq, src, ping, msecpause, msgs, verbose,
                                      end_on_eos, rtt_collect, rtt_ignore, use_mim);
            System.Threading.Thread.Sleep(5000);
            if (ping)
            {
                byte [] message = new byte[msglen];
                rcv.start();

                format(message, 0, System.Diagnostics.Stopwatch.GetTimestamp() * lbmpong.pspertick / 1000);
                if (use_mim)
                {
                    ctx.send("lbmpong/ping", message, msglen, LBM.MSG_FLUSH);
                }
                else if (use_smx)
                {
                    try
                    {
                        IntPtr writeBuff;
                        if (src.buffAcquire(out writeBuff, (uint)msglen, 0) == 0)
                        {
                            Marshal.Copy(message, 0, writeBuff, msglen);
                            src.buffsComplete();
                        }
                    }
                    catch (LBMException ex)
                    {
                        System.Console.Error.WriteLine("Error (while doing SMX acquire/complete): " + ex.Message);
                        System.Environment.Exit(1);
                    }
                }
                else
                {
                    src.send(message, msglen, LBM.MSG_FLUSH);
                }
            }
            if (eventq)
            {
                evq.run(run_secs * 1000);
            }
            else
            {
                System.Threading.Thread.Sleep(run_secs * 1000);
            }

            System.Console.Error.WriteLine("Quitting....");
            if (!use_mim)
            {
                src.close();
            }
            rcv.close();
            ctx.close();
            if (eventq)
            {
                evq.close();
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null &&
                System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null)
            {
                SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt");
            }
            LBM lbm = new LBM();

            lbm.setLogger(new LBMLogging(logger));

            LBMObjectRecycler objRec = new LBMObjectRecycler();

            int          send_rate            = 0;                                      //	Used for lbmtrm | lbtru transports
            int          retrans_rate         = 0;                                      //
            char         protocol             = '\0';                                   //
            int          linger               = 5;
            int          delay                = 1;
            int          msglen               = 25;
            int          pause                = 0;
            bool         do_stats             = false;
            int          initial_topic_number = default_initial_topic_number;
            string       topicroot            = default_topic_root;
            int          num_srcs             = default_num_sources;
            int          num_thrds            = default_num_threads;
            int          i;
            int          n = args.Length;
            bool         monitor_context       = false;
            int          monitor_context_ivl   = 0;
            bool         monitor_source        = false;
            int          monitor_source_ivl    = 0;
            string       application_id        = null;
            int          mon_format            = LBMMonitor.FORMAT_CSV;
            int          mon_transport         = LBMMonitor.TRANSPORT_LBM;
            string       mon_format_options    = null;
            string       mon_transport_options = null;
            bool         error = false;
            bool         done  = false;
            const string OPTION_MONITOR_CTX            = "--monitor-ctx";
            const string OPTION_MONITOR_SRC            = "--monitor-src";
            const string OPTION_MONITOR_TRANSPORT      = "--monitor-transport";
            const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts";
            const string OPTION_MONITOR_FORMAT         = "--monitor-format";
            const string OPTION_MONITOR_FORMAT_OPTS    = "--monitor-format-opts";
            const string OPTION_MONITOR_APPID          = "--monitor-appid";

            for (i = 0; i < n; i++)
            {
                try
                {
                    switch (args[i])
                    {
                    case OPTION_MONITOR_APPID:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        application_id = args[i];
                        break;

                    case OPTION_MONITOR_CTX:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        monitor_context     = true;
                        monitor_context_ivl = Convert.ToInt32(args[i]);
                        break;

                    case OPTION_MONITOR_SRC:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        monitor_source     = true;
                        monitor_source_ivl = Convert.ToInt32(args[i]);
                        break;

                    case OPTION_MONITOR_FORMAT:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        if (args[i].ToLower().CompareTo("csv") == 0)
                        {
                            mon_format = LBMMonitor.FORMAT_CSV;
                        }
                        else
                        {
                            error = true;
                            break;
                        }
                        break;

                    case OPTION_MONITOR_TRANSPORT:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        if (args[i].ToLower().CompareTo("lbm") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_LBM;
                        }
                        else if (args[i].ToLower().CompareTo("udp") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_UDP;
                        }
                        else if (args[i].ToLower().CompareTo("lbmsnmp") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_LBMSNMP;
                        }
                        else
                        {
                            error = true;
                            break;
                        }
                        break;

                    case OPTION_MONITOR_TRANSPORT_OPTS:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        mon_transport_options += args[i];
                        break;

                    case OPTION_MONITOR_FORMAT_OPTS:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        mon_format_options += args[i];
                        break;

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

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

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

                    case "-i":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        initial_topic_number = Convert.ToInt32(args[i]);
                        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 "-M":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        msgs = Convert.ToInt32(args[i]);
                        break;

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

                    case "-r":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        topicroot = 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":
                        do_stats = true;
                        break;

                    case "-S":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        num_srcs = Convert.ToInt32(args[i]);
                        if (num_srcs > max_num_sources)
                        {
                            System.Console.Error.WriteLine("Too many sources specified. Max number of sources is " + max_num_sources);
                            System.Environment.Exit(1);
                        }
                        break;

                    case "-T":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        num_thrds = Convert.ToInt32(args[i]);
                        if (num_thrds > max_num_threads)
                        {
                            System.Console.Error.WriteLine("Too many threads specified. Max number of threads is " + max_num_threads);
                            System.Environment.Exit(1);
                        }
                        break;

                    default:
                        if (args[i].StartsWith("-"))
                        {
                            System.Console.Out.WriteLine("DEFAULT ERROR=TRUE");
                            error = true;
                        }
                        else
                        {
                            done = true;
                        }
                        break;
                    }
                    if (error || done)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    /* type conversion exception */
                    System.Console.Error.WriteLine("lbmmsrc: error\n" + e.Message + "\n");
                    print_help_exit(1);
                }
            }
            if (error)
            {
                /* An error occurred processing the command line - print help and exit */
                print_help_exit(1);
            }
            byte [] message = new byte[msglen];
            if (num_thrds > num_srcs)
            {
                System.Console.Error.WriteLine("Number of threads must be less than or equal to number of sources");
                System.Environment.Exit(1);
            }
            LBMSourceAttributes sattr = new LBMSourceAttributes();

            sattr.setObjectRecycler(objRec, null);
            LBMContextAttributes cattr = new LBMContextAttributes();

            cattr.setObjectRecycler(objRec, null);

            /* Check if protocol needs to be set to lbtrm | lbtru */
            if (protocol == 'M')
            {
                try
                {
                    sattr.setValue("transport", "LBTRM");
                    cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }
            if (protocol == 'U')
            {
                try
                {
                    sattr.setValue("transport", "LBTRU");
                    cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }

            LBMContext       ctx       = new LBMContext(cattr);
            LBMMonitorSource lbmmonsrc = null;

            if (monitor_context || monitor_source)
            {
                lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options);
                if (monitor_context)
                {
                    lbmmonsrc.start(ctx, application_id, monitor_context_ivl);
                }
            }
            MSrcCB srccb = new MSrcCB();

            LBMSource [] sources = new LBMSource[num_srcs];;
            for (i = 0; i < num_srcs; i++)
            {
                int    topicnum  = initial_topic_number + i;
                string topicname = topicroot + "." + topicnum;

                LBMTopic topic = ctx.allocTopic(topicname, sattr);
                sources[i] = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null);
                if (i > 1 && (i % 1000) == 0)
                {
                    System.Console.Out.WriteLine("Created " + i + " sources");
                }
                if (monitor_source)
                {
                    lbmmonsrc.start(sources[i],
                                    application_id + "(" + i + ")",
                                    monitor_source_ivl);
                }
            }

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

            System.Console.Out.WriteLine("Created " + num_srcs + " sources. Will start sending data now.\n");
            System.Console.Out.WriteLine("Using " + num_thrds + " threads to send " +
                                         msgs + " messages of size " + msglen +
                                         " bytes (" + (msgs / num_thrds) + " messages per thread).");
            System.Console.Out.Flush();
            LBMSrcThread [] srcthreads = new LBMSrcThread[num_thrds];
            for (i = 1; i < num_thrds; i++)
            {
                srcthreads[i] = new LBMSrcThread(i, num_thrds, message, msglen, msgs / num_thrds, sources, num_srcs, pause);
                srcthreads[i].start();
            }
            srcthreads[0] = new LBMSrcThread(0, num_thrds, message, msglen, msgs / num_thrds, sources, num_srcs, pause);
            srcthreads[0].run();
            System.Console.Out.WriteLine("\nDone sending on thread 0. Waiting for any other threads to finish.");
            for (i = 1; i < num_thrds; i++)
            {
                System.Console.Out.WriteLine("Joining thread " + i);
                srcthreads[i].join();
                System.Console.Out.WriteLine("Joined thread " + i);
            }
            System.Console.Out.Flush();
            if (linger > 0)
            {
                System.Console.Out.WriteLine("\nLingering for {0} second{1}...\n",
                                             linger, ((linger > 1) ? "s" : ""));
                System.Threading.Thread.Sleep(linger * 1000);
            }
            if (do_stats)
            {
                print_stats(ctx, num_srcs, sources[0].getAttributeValue("transport"), objRec);
            }
            System.Console.Out.WriteLine("Quitting...");
            objRec.close();
            for (i = 0; i < num_srcs; i++)
            {
                sources[i].close();
            }
            ctx.close();
        }
Ejemplo n.º 15
0
        public static int Main(string[] args)
        {
            lbmlatpong latpong = null;

            LBMContext           ctx      = null;
            LBMContextAttributes ctx_attr = null;

            LBMTopic            pong_src_topic      = null;
            LBMSourceAttributes pong_src_topic_attr = null;
            LBMSource           pong_src            = null;

            LBMTopic ping_rcv_topic = null;
            LBMReceiverAttributes ping_rcv_topic_attr = null;
            lbmlatpongreceiver    ping_rcv            = null;

            latpong = new lbmlatpong(args);
            if (latpong.cpu >= 0)
            {
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latpong.cpu);
            }

            /* Create the context. */
            ctx_attr = new LBMContextAttributes();
            ctx_attr.setValue("resolver_cache", "0");
            ctx_attr.setValue("operational_mode", "sequential");
            ctx_attr.setValue("request_tcp_port_high", "50000");
            ctx_attr.setValue("transport_lbtipc_receiver_thread_behavior", "busy_wait");
            ctx = new LBMContext(ctx_attr);
            ctx_attr.dispose();

            /* Create the pong source. */
            pong_src_topic_attr = new LBMSourceAttributes();
            pong_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0");
            pong_src_topic_attr.setValue("transport", "lbtsmx");
            pong_src_topic = new LBMTopic(ctx, "lbmlat-pong", pong_src_topic_attr);
            pong_src_topic_attr.dispose();
            pong_src         = new LBMSource(ctx, pong_src_topic);
            latpong.pong_src = pong_src;

            /* Create the ping receiver. */
            ping_rcv_topic_attr = new LBMReceiverAttributes();
            ping_rcv_topic_attr.enableSingleReceiverCallback(true);
            ping_rcv_topic_attr.setSourceNotificationCallbacks(
                new LBMSourceCreationCallback(latpong.onNewSource),
                new LBMSourceDeletionCallback(latpong.onSourceDelete),
                null);
            ping_rcv_topic = new LBMTopic(ctx, "lbmlat-ping", ping_rcv_topic_attr);
            ping_rcv_topic_attr.dispose();
            ping_rcv = new lbmlatpongreceiver(ctx, ping_rcv_topic, latpong, pong_src);

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Run the context until we've discovered the pinger's source. */
            while (!latpong.found_pinger)
            {
                ctx.processEvents(1000);
            }

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Send in a dummy pong message to kick things off. */
            IntPtr writeBuff;

            if (pong_src.buffAcquire(out writeBuff, (uint)16, 0) == 0)
            {
                Marshal.WriteInt64(writeBuff, 0, 1234567890);
                pong_src.buffsComplete();
            }

            /* Wait forever. */
            while (true)
            {
                System.Threading.Thread.Sleep(1000000);
                // ctx.processEvents(1000000);
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null &&
                System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null)
            {
                SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt");
            }
            LBM lbm = new LBM();

            lbm.setLogger(new LBMLogging(logger));

            LBMObjectRecycler objRec = new LBMObjectRecycler();

            int          send_rate    = 0;                                              //	Used for lbmtrm | lbtru transports
            int          retrans_rate = 0;                                              //
            char         protocol     = '\0';                                           //
            int          msglen       = 25;
            int          linger       = 5;
            int          delay        = 1;
            ulong        bytes_sent   = 0;
            int          pause        = 0;
            int          i;
            bool         block                         = true;
            int          hfbits                        = 32;
            int          n                             = args.Length;
            bool         monitor_context               = false;
            int          monitor_context_ivl           = 0;
            bool         monitor_source                = false;
            int          monitor_source_ivl            = 0;
            string       application_id                = null;
            int          mon_format                    = LBMMonitor.FORMAT_CSV;
            int          mon_transport                 = LBMMonitor.TRANSPORT_LBM;
            string       mon_format_options            = null;
            string       mon_transport_options         = null;
            bool         error                         = false;
            bool         done                          = false;
            bool         use_hf                        = false;
            ulong        seq_counter                   = 0;
            long         channel                       = -1;
            string       tape_file                     = null;
            StreamReader tape_scanner                  = null;
            int          tape_msgs_sent                = 0;
            const string OPTION_MONITOR_CTX            = "--monitor-ctx";
            const string OPTION_MONITOR_SRC            = "--monitor-src";
            const string OPTION_MONITOR_TRANSPORT      = "--monitor-transport";
            const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts";
            const string OPTION_MONITOR_FORMAT         = "--monitor-format";
            const string OPTION_MONITOR_FORMAT_OPTS    = "--monitor-format-opts";
            const string OPTION_MONITOR_APPID          = "--monitor-appid";

            for (i = 0; i < n; i++)
            {
                try
                {
                    switch (args[i])
                    {
                    case OPTION_MONITOR_APPID:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        application_id = args[i];
                        break;

                    case OPTION_MONITOR_CTX:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        monitor_context     = true;
                        monitor_context_ivl = Convert.ToInt32(args[i]);
                        break;

                    case OPTION_MONITOR_SRC:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        monitor_source     = true;
                        monitor_source_ivl = Convert.ToInt32(args[i]);
                        break;

                    case OPTION_MONITOR_FORMAT:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        if (args[i].ToLower().CompareTo("csv") == 0)
                        {
                            mon_format = LBMMonitor.FORMAT_CSV;
                        }
                        else
                        {
                            error = true;
                            break;
                        }
                        break;

                    case OPTION_MONITOR_TRANSPORT:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        if (args[i].ToLower().CompareTo("lbm") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_LBM;
                        }
                        else if (args[i].ToLower().CompareTo("udp") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_UDP;
                        }
                        else if (args[i].ToLower().CompareTo("lbmsnmp") == 0)
                        {
                            mon_transport = LBMMonitor.TRANSPORT_LBMSNMP;
                        }
                        else
                        {
                            error = true;
                            break;
                        }
                        break;

                    case OPTION_MONITOR_TRANSPORT_OPTS:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        mon_transport_options += args[i];
                        break;

                    case OPTION_MONITOR_FORMAT_OPTS:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        mon_format_options += args[i];
                        break;

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

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

                    case "-D":
                        if (verifiable)
                        {
                            System.Console.Error.WriteLine("Unable to use SDM because verifiable messages are on. Turn off verifiable messages (-V).");
                            System.Environment.Exit(1);
                        }
                        sdm = true;
                        break;

                    case "-f":
                        use_hf = true;
                        break;

                    case "-i":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        seq_counter = ulong.Parse(args[i]);
                        break;

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

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

                    case "-n":
                        block = false;
                        break;

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

                    case "-M":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        msgs = long.Parse(args[i]);
                        break;

                    case "-N":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        channel = Convert.ToInt64(args[i]);
                        break;

                    case "-P":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        pause = 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;
                        }
                        tape_file = args[i];
                        if (!File.Exists(tape_file))
                        {
                            System.Console.Error.WriteLine("{0} does not exist. Verify the file specified by (-t) exists.", tape_file);
                            print_help_exit(1);
                        }
                        tape_scanner = new StreamReader(tape_file);
                        break;

                    case "-V":
                        if (sdm)
                        {
                            System.Console.Error.WriteLine("Unable to use verifiable messages because sdm is on. Turn off sdm (-D).");
                            System.Environment.Exit(1);
                        }
                        verifiable = true;
                        break;

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

                        if (hfbits != 32 && hfbits != 64)
                        {
                            Console.WriteLine("-x " + hfbits + " invalid, HF sequence numbers must be 32 or 64 bit");
                            print_help_exit(1);
                        }
                        break;

                    default:
                        if (args[i].StartsWith("-"))
                        {
                            error = true;
                        }
                        else
                        {
                            done = true;
                        }
                        break;
                    }
                    if (error || done)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    /* type conversion exception */
                    System.Console.Error.WriteLine("lbmsrc: 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);
            }
            if (tape_scanner != null && !use_hf)
            {
                print_help_exit(1);
            }

            byte [] message = new byte[msglen];

            if (verifiable)
            {
                int min_msglen = VerifiableMessage.MINIMUM_VERIFIABLE_MSG_LEN;
                if (msglen < min_msglen)
                {
                    System.Console.WriteLine("Specified message length " + msglen + " is too small for verifiable message.");
                    System.Console.WriteLine("Setting message length to minimum (" + min_msglen + ").");
                    msglen = min_msglen;
                }
            }

            LBMSourceAttributes sattr = new LBMSourceAttributes();

            sattr.setObjectRecycler(objRec, null);
            LBMContextAttributes cattr = new LBMContextAttributes();

            cattr.setObjectRecycler(objRec, null);

            /* Check if protocol needs to be set to lbtrm | lbtru */
            if (protocol == 'M')
            {
                try
                {
                    sattr.setValue("transport", "LBTRM");
                    cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }
            if (protocol == 'U')
            {
                try
                {
                    sattr.setValue("transport", "LBTRU");
                    cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString());
                    cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString());
                }
                catch (LBMException ex)
                {
                    System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message);
                    System.Environment.Exit(1);
                }
            }

            LBMContext ctx   = new LBMContext(cattr);
            LBMTopic   topic = ctx.allocTopic(args[i], sattr);
            LBMSource  src;
            SrcCB      srccb = new SrcCB();

            if (use_hf)
            {
                src = ctx.createHotFailoverSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null);
            }
            else
            {
                src = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null);
            }

            LBMSourceChannelInfo channel_info = null;
            LBMSourceSendExInfo  exInfo       = null;

            if (channel != -1)
            {
                if (use_hf)
                {
                    Console.WriteLine("Error creating channel: cannot send on channels with hot failover.");
                    Environment.Exit(1);
                }
                channel_info = src.createChannel(channel);
                exInfo       = new LBMSourceSendExInfo(LBM.SRC_SEND_EX_FLAG_CHANNEL, null, channel_info);
            }

            SrcStatsTimer stats;

            if (stats_sec > 0)
            {
                stats = new SrcStatsTimer(ctx, src, stats_sec * 1000, null, objRec);
            }
            LBMMonitorSource lbmmonsrc = null;

            if (monitor_context || monitor_source)
            {
                lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options);
                if (monitor_context)
                {
                    lbmmonsrc.start(ctx, application_id, monitor_context_ivl);
                }
                else
                {
                    lbmmonsrc.start(src, application_id, monitor_source_ivl);
                }
            }

            if (delay > 0)
            {
                System.Console.Out.WriteLine("Will start sending in {0} second{1}...\n",
                                             delay, ((delay > 1) ? "s" : ""));

                System.Threading.Thread.Sleep(delay * 1000);
            }

            System.Console.Out.WriteLine("Sending {0} messages of size {1} bytes to topic [{2}]\n",
                                         msgs, msglen, args[i]);
            System.Console.Out.Flush();
            long start_time = System.DateTime.Now.Ticks;
            long msgcount   = 0;

            if (verifiable)
            {
                message = VerifiableMessage.constructVerifiableMessage(msglen);
            }
            else if (sdm) // If using SDM messages, create the message now
            {
                CreateSDMessage();
            }

            // hfexinfo holds hot failover sequence number at bit size
            LBMSourceSendExInfo hfexinfo = null;

            if (use_hf)
            {
                int hfflags = (hfbits == 64) ? LBM.SRC_SEND_EX_FLAG_HF_64 : LBM.SRC_SEND_EX_FLAG_HF_32;
                hfexinfo = new LBMSourceSendExInfo(hfflags, null);
            }
            for (msgcount = 0; msgcount < msgs;)
            {
                try {
                    // If using SDM messages, Update the sequence number
                    if (sdm)
                    {
                        byte [] m = UpdateSDMessage(seq_counter);
                        if (m != null)
                        {
                            message = m;
                            msglen  = message.Length;
                        }
                    }

                    bool sendReset = false;
                    srccb.blocked = true;

                    if (use_hf)
                    {
                        if (tape_scanner != null)
                        {
                            string tape_str, tape_line = null;
                            tape_line = tape_scanner.ReadLine();

                            if (tape_line == null)
                            {
                                break;
                            }

                            // Make sure the hf optional send ex flag is off
                            hfexinfo.setFlags(hfexinfo.flags() & ~LBM.SRC_SEND_EX_FLAG_HF_OPTIONAL);
                            if (tape_line.EndsWith("o"))
                            {
                                tape_str = tape_line.Substring(0, tape_line.Length - 1);
                                hfexinfo.setFlags(hfexinfo.flags() | LBM.SRC_SEND_EX_FLAG_HF_OPTIONAL);
                            }
                            else if (tape_line.EndsWith("r"))
                            {
                                tape_str  = tape_line.Substring(0, tape_line.Length - 1);
                                sendReset = true;
                            }
                            else
                            {
                                tape_str = tape_line;
                            }

                            if (hfbits == 64)
                            {
                                hfexinfo.setHfSequenceNumber64(ulong.Parse(tape_str));
                            }
                            else
                            {
                                hfexinfo.setHfSequenceNumber32(uint.Parse(tape_str));
                            }
                        }
                        else if (hfbits == 64)
                        {
                            hfexinfo.setHfSequenceNumber64(seq_counter);
                        }
                        else
                        {
                            hfexinfo.setHfSequenceNumber32((uint)seq_counter);
                        }

                        if (sendReset)
                        {
                            ((LBMHotFailoverSource)src).sendReceiverReset(LBM.MSG_FLUSH, hfexinfo);
                        }
                        else
                        {
                            ((LBMHotFailoverSource)src).send(message, msglen, 0, block ? 0 : LBM.SRC_NONBLOCK, hfexinfo);
                        }
                        if (tape_scanner != null)
                        {
                            tape_msgs_sent++;
                        }
                    }
                    else if (exInfo != null)
                    {
                        src.send(message, msglen, block ? 0 : LBM.SRC_NONBLOCK, exInfo);
                    }
                    else
                    {
                        src.send(message, msglen, block ? 0 : LBM.SRC_NONBLOCK);
                    }
                    srccb.blocked = false;
                    if (tape_scanner == null)
                    {
                        seq_counter++;
                        msgcount++;
                    }
                }
                catch (LBMEWouldBlockException) {
                    while (srccb.blocked)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    continue;
                }
                bytes_sent += (ulong)msglen;
                if (pause > 0)
                {
                    System.Threading.Thread.Sleep(pause);
                }
            }
            long   end_time = System.DateTime.Now.Ticks;
            double secs     = (end_time - start_time) / 10000000.0;

            System.Console.Out.WriteLine("Sent {0} messages of size {1} bytes in {2} seconds.\n",
                                         (tape_scanner == null) ? msgs : tape_msgs_sent, msglen, secs);

            print_bw(secs, (tape_scanner == null) ? msgs : tape_msgs_sent, bytes_sent);
            System.Console.Out.Flush();
            if (linger > 0)
            {
                System.Console.Out.WriteLine("Lingering for {0} second{1}...\n",
                                             linger, ((linger > 1) ? "s" : ""));
                System.Threading.Thread.Sleep(linger * 1000);
            }
            stats = new SrcStatsTimer(ctx, src, 0, null, objRec);
            if (channel_info != null)
            {
                src.deleteChannel(channel_info);
            }
            objRec.close();
            src.close();

            if (tape_scanner != null)
            {
                tape_scanner.Close();
                tape_scanner.Dispose();
            }
            ctx.close();
        }
Ejemplo n.º 17
0
        } // ContextAttrSetoptFromFile

        // Replicate "aux" library's lbmaux_source_attr_setopt_from_file().
        public static unsafe void SourceAttrSetoptFromFile(LBMSourceAttributes srcAttr,
                                                           string fileName)
        {
            string        iLine;
            StringBuilder scope  = new StringBuilder(1025);
            StringBuilder option = new StringBuilder(1025);
            StringBuilder value  = new StringBuilder(1025);

#if (ANYCPU == false)
            size_t matches;
            size_t confLength;
#else
            IntPtr matches;
            IntPtr confLength;
#endif
            int lineNum = 0;

            System.IO.StreamReader configFile =
                new System.IO.StreamReader(fileName);
            while ((iLine = configFile.ReadLine()) != null)
            {
                lineNum++;
                // Skip comment and blank lines.
                if (iLine.Length == 0 || Char.IsWhiteSpace(iLine[0]))
                {
                    continue;
                }
                if (iLine.Length > 1024)
                {
                    configFile.Close();
                    throw new TmonException("File '" + fileName + "', Line " + lineNum + ": too long (" + iLine.Length + ")");
                }

                lbm_parse_config_line(iLine, scope, option, value, &matches, &confLength);
                if ((int)matches == 0)
                {
                    continue; // Blank line, possibly with spaces.
                }
                if ((int)matches != 3 || confLength != iLine.Length)
                {
                    configFile.Close();
                    throw new TmonException("File '" + fileName + "', Line " + lineNum + ": parse error (matches=" + matches + ", confLength=" + (int)confLength + ", line len=" + iLine.Length + ")");
                }

                // If value is a number with commas, strip the commas.
                string scopeStr  = scope.ToString();
                string optionStr = option.ToString();
                string valueStr  = value.ToString();
                if (IsDigitsComma(valueStr))
                {
                    valueStr = valueStr.Replace(",", "");
                }

                // Set source attributes.
                if (scopeStr.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    try {
                        srcAttr.setValue(optionStr, valueStr);
                    } catch (Exception e) {
                        configFile.Close();
                        throw new TmonException("File '" + fileName + "', Line " + lineNum + ": setValue error '" + e.Message + "'");
                    }
                }
            } // while

            configFile.Close();
        } // SourceAttrSetoptFromFile
Ejemplo n.º 18
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();
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            LBMContext ctx = null;      /* Container for UM instance */
            LBMTopic topic1 = null;		/* Object used to create topic */
            LBMTopic topic2 = null;	    /* Object used to create topic */
            LBMSource src1 = null;      /* Used for sending messages on a single topic */
            LBMSource src2 = null;      /* Used for sending messages on a single topic */
            LBMSourceAttributes srcAttr = null; 	/* Object used to configure sources */
            int resPort;
            int desPort;

            /* We are using certain lbm objects that require an application level 	*/
            /* memory manager called the LBMObjectRecycler to cleanup 				*/
            LBMObjectRecycler objRec = new LBMObjectRecycler();

            try
            {
                /* create ctxAttr to set config values before creating context */
                LBMContextAttributes ctxAttr = new LBMContextAttributes();
                ctxAttr.setObjectRecycler(objRec, null);

                /* Modify resolver address by setting attributes */
                ctxAttr.setValue("resolver_multicast_address", "224.10.11.12");

                /* Create a context with default attributes */
                ctx = new LBMContext(ctxAttr);
                /* Create source attributes object, used to configure sources */
                srcAttr = new LBMSourceAttributes();
                srcAttr.setObjectRecycler(objRec, null);

                /* Set configuration value using strings */
                srcAttr.setValue("transport", "lbtrm");

                /* The Java API only accepts string values. ints, for example */
                /* must be converted to strings */
                desPort = 14001;
                srcAttr.setValue("transport_lbtrm_destination_port", desPort.ToString());

                /* Create topic for the first source with configured attributes */
                topic1 = new LBMTopic(ctx, "test.topic1", srcAttr);
                src1 = new LBMSource(ctx, topic1);
                /* Modify Configuration for second topic to use a new port */
                desPort = 14002;
                srcAttr.setValue("transport_lbtrm_destination_port", desPort.ToString());

                /* Create second topic and source using modified configuration values */
                topic2 = new LBMTopic(ctx, "test.topic2", srcAttr);
                src2 = new LBMSource(ctx, topic2);
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
            System.Console.Out.WriteLine("Context Attributes: ");
            List<LBMConfigOption> cfgOptList = ctx.dumpAttributeList();
            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            System.Console.Out.WriteLine("Source #1 Attributes: ");
            cfgOptList = src1.dumpAttributeList();
            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            System.Console.Out.WriteLine("Source #2 Attributes: ");
            cfgOptList = src2.dumpAttributeList();
            for (int i = 0; i < cfgOptList.Count; i++)
            {
                System.Console.Out.WriteLine(cfgOptList[i].Type + " " + cfgOptList[i].OptionName + " " + cfgOptList[i].Value);
            }
            /* Cleanup all LBM objects */
            try
            {
                objRec.close();
                src2.close();
                src1.close();
                ctx.close();
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }
        }