예제 #1
0
    static void Main(String[] args)
    {
        LBMContext ctx = null;           /* Context object: container for UM "instance". */
                LBMReceiver rcv = null;          /* Receiver object: for receiving messages. */
                LBMTopic rtopic = null;          /* Topic object */
                LBMReceiverAttributes rcv_attr;  /* Receiver attribute object */

                /* Initialize and create receiver and receiver callback */
                LBMReceiverCallback myReceiverCallback = new LBMReceiverCallback(onReceive);

                /*** Initialization: create necessary UM objects. ***/
                ctx = new LBMContext();
                rcv_attr = new LBMReceiverAttributes();

                UMERcvRecInfo umerecinfocb = new UMERcvRecInfo();
                rcv_attr.setRecoverySequenceNumberCallback(umerecinfocb.setRecoverySequenceNumberInfo, null);

                rtopic = new LBMTopic(ctx, "test.topic", rcv_attr);
                rcv = new LBMReceiver(ctx, rtopic, myReceiverCallback, null);

                while(true)
                {

                }
    }
예제 #2
0
    static void Main(String[] args)
    {
        LBMContext            ctx    = null;     /* Context object: container for UM "instance". */
        LBMReceiver           rcv    = null;     /* Receiver object: for receiving messages. */
        LBMTopic              rtopic = null;     /* Topic object */
        LBMReceiverAttributes rcv_attr;          /* Receiver attribute object */

        /* Initialize and create receiver and receiver callback */
        LBMReceiverCallback myReceiverCallback = new LBMReceiverCallback(onReceive);

        /*** Initialization: create necessary UM objects. ***/
        ctx      = new LBMContext();
        rcv_attr = new LBMReceiverAttributes();

        UMERcvRecInfo umerecinfocb = new UMERcvRecInfo();

        rcv_attr.setRecoverySequenceNumberCallback(umerecinfocb.setRecoverySequenceNumberInfo, null);

        rtopic = new LBMTopic(ctx, "test.topic", rcv_attr);
        rcv    = new LBMReceiver(ctx, rtopic, myReceiverCallback, null);

        while (true)
        {
        }
    }     /* main */
예제 #3
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();

            string qdelay   = null;
            string qsize    = null;
            string num_srcs = null;
            int    i;
            int    n = args.Length;

            bool monitor_context     = false;
            int  monitor_context_ivl = 0;

            bool         monitor_receiver      = false;
            int          monitor_receiver_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;
            string       regid_offset                  = "1000";
            int          seqnum_offset                 = 0;
            bool         sqn_info                      = false;
            const string OPTION_MONITOR_CTX            = "--monitor-ctx";
            const string OPTION_MONITOR_RCV            = "--monitor-rcv";
            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_RCV:
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        monitor_receiver     = true;
                        monitor_receiver_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("umercv error: " + Ex.Message);
                            error = true;
                        }
                        break;

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

                    case "-E":
                        end_on_eos = true;
                        break;

                    case "-D":
                        dereg = 1;
                        break;

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

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

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

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

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

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

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

                    case "-S":
                        end_on_eos = true;
                        summary    = true;
                        break;

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

                    case "-v":
                        verbose = true;
                        break;

                    case "-z":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        qsize  = args[i];
                        eventq = true;
                        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("umercv: error\n" + e.Message);
                    print_help_exit(1);
                }
            }
            if (error || i >= n)
            {
                /* An error occurred processing the command line - print help and exit */
                print_help_exit(1);
            }
            LBMContextAttributes cattr = new LBMContextAttributes();

            cattr.setObjectRecycler(objRec, null);
            LBMContext            ctx   = new LBMContext(cattr);
            LBMReceiverAttributes rattr = null;
            UMERegistrationId     umeregid;

            rattr = new LBMReceiverAttributes();
            rattr.setObjectRecycler(objRec, null);
            if (num_srcs != null)
            {
                rattr.setValue("resolution_number_of_sources_query_threshold", num_srcs);
            }
            if (regid_offset != null)
            {
                umeregid = new UMERegistrationId(regid_offset);
                rattr.setRegistrationIdCallback(new UMERegistrationIdExCallback(umeregid.setRegistrationId), null);
                System.Console.Out.WriteLine("Will use RegID offset " + regid_offset + ".");
            }
            else
            {
                System.Console.Out.WriteLine("Will not use specific RegID.");
            }

            if (sqn_info)
            {
                UMERcvRecInfo umerecinfocb = new UMERcvRecInfo(seqnum_offset);
                rattr.setRecoverySequenceNumberCallback(umerecinfocb.setRecoverySequenceNumberInfo, null);
                System.Console.Out.WriteLine("Will use seqnum info with low offset " + seqnum_offset + ".");
            }

            if (exack > 0)
            {
                try
                {
                    rattr.setValue("ume_explicit_ack_only", "1");
                }
                catch (LBMException e)
                {
                    System.Console.Error.WriteLine("Error setting ume_explicit_ack_only=" + exack + e.Message);
                    System.Environment.Exit(1);
                }
            }

            LBMTopic         topic = ctx.lookupTopic(args[i], rattr);
            UMERcvReceiver   rcv   = new UMERcvReceiver(verbose, end_on_eos, summary, exack, dereg);
            LBMReceiver      lbmrcv;
            UMERcvEventQueue evq = null;

            if (eventq)
            {
                System.Console.Error.WriteLine("Event queue in use");
                LBMEventQueueAttributes evqattr = null;
                if (qsize != null || qdelay != null)
                {
                    evqattr = new LBMEventQueueAttributes();
                    if (qdelay != null)
                    {
                        evqattr.setValue("queue_delay_warning", qdelay);
                    }
                    if (qsize != null)
                    {
                        evqattr.setValue("queue_size_warning", qsize);
                    }
                }
                evq    = new UMERcvEventQueue(evqattr);
                lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null, evq);
                ctx.enableImmediateMessageReceiver(evq);
            }
            else
            {
                System.Console.Error.WriteLine("No event queue");
                lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null);
                ctx.enableImmediateMessageReceiver();
            }

            rcv.setRcvr(lbmrcv);

            // This immediate-mode receiver is *only* used for topicless
            // immediate-mode sends.  Immediate sends that use a topic
            // are received with normal receiver objects.
            ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(rcv.onReceive));

            LBMMonitorSource lbmmonsrc = null;

            if (monitor_context || monitor_receiver)
            {
                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(lbmrcv, application_id, monitor_receiver_ivl);
                }
            }
            System.Console.Out.Flush();
            long start_time;
            long end_time;
            long last_lost = 0, lost_tmp = 0, lost = 0;
            bool have_stats;
            LBMReceiverStatistics stats = null;
            long stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks;

            for (; ;)
            {
                start_time = System.DateTime.Now.Ticks;
                if (eventq)
                {
                    evq.run(1000);
                }
                else
                {
                    System.Threading.Thread.Sleep(1000);
                }

                have_stats = false;
                while (!have_stats)
                {
                    try
                    {
                        stats      = lbmrcv.getStatistics(nstats);
                        have_stats = true;
                    }
                    catch (LBMException ex)
                    {
                        /* Double the number of stats passed to the API to be retrieved */
                        /* Do so until we retrieve stats successfully or hit the max limit */
                        nstats *= 2;
                        if (nstats > DEFAULT_MAX_NUM_SRCS)
                        {
                            System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message);
                            System.Environment.Exit(1);
                        }
                        /* have_stats is still false */
                    }
                }

                /* If we get here, we have the stats */
                lost = 0;
                for (i = 0; i < stats.size(); i++)
                {
                    lost += stats.lost(i);
                }

                /* Account for loss in previous iteration */
                lost_tmp = lost;
                if (last_lost <= lost)
                {
                    lost -= last_lost;
                }
                else
                {
                    lost = 0;
                }
                last_lost = lost_tmp;

                end_time = System.DateTime.Now.Ticks;

                print_bw((end_time - start_time) / 10000,
                         rcv.msg_count,
                         rcv.byte_count,
                         rcv.unrec_count,
                         lost,
                         rcv.burst_loss,
                         rcv.rx_msgs,
                         rcv.otr_msgs);

                if (stat_secs > 0 && stat_time <= end_time)
                {
                    stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks;
                    print_stats(stats, evq);
                }

                objRec.doneWithReceiverStatistics(stats);

                rcv.msg_count   = 0;
                rcv.byte_count  = 0;
                rcv.unrec_count = 0;
                rcv.burst_loss  = 0;
                rcv.rx_msgs     = 0;
                rcv.otr_msgs    = 0;

                if (reap_msgs != 0 && rcv.total_msg_count >= reap_msgs)
                {
                    break;
                }
            }

            System.Console.Error.WriteLine("Quitting.... received "
                                           + rcv.total_msg_count
                                           + " messages");
            objRec.close();
            lbmrcv.close();
            ctx.close();
            if (eventq)
            {
                evq.close();
            }
            GC.KeepAlive(lbm);
        }