コード例 #1
0
 public void setWrcvr(LBMWildcardReceiver wrcvr)
 {
     _wrcvr = wrcvr;
 }
コード例 #2
0
ファイル: lbmwrcv.cs プロジェクト: mallickhruday/MyDemos
        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  i;
            int  n     = args.Length;
            bool error = false;
            bool done  = false;

            List <uint>  channels            = new List <uint>();
            bool         monitor_context     = false;
            int          monitor_context_ivl = 0;
            long         dereg                         = 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;
            const string OPTION_MONITOR_CTX            = "--monitor-ctx";
            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_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("lbmwrcv error: " + Ex.Message);
                            error = true;
                        }
                        break;

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

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

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

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

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

                    case "-s":
                        print_stats_flag = true;
                        break;

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

                    case "-v":
                        verbose = 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("lbmwrcv: 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);
            }
            LBMWRcvSourceNotify srcNotify = new LBMWRcvSourceNotify();

            LBMContextAttributes lbmContextAttributes = new LBMContextAttributes();

            lbmContextAttributes.enableSourceNotification();
            LBMContext ctx = new LBMContext(lbmContextAttributes);

            ctx.addSourceNotifyCallback(new LBMSourceNotification(srcNotify.sourceNotification));

            LBMWildcardReceiverAttributes lbmWildcardReceiverAttributes = new LBMWildcardReceiverAttributes();
            string pattern      = args[i];
            string pattern_type = lbmWildcardReceiverAttributes.getValue("pattern_type");

            LBMWRcvTopicFilter topicFilter;

            if (pattern == "*" &&
                (pattern_type.ToUpper() == "PCRE" ||
                 pattern_type.ToLower() == "regex"))
            {
                topicFilter  = new LBMWRcvTopicFilter();
                pattern_type = "appcb";
                lbmWildcardReceiverAttributes.setValue("pattern_type", pattern_type);
                lbmWildcardReceiverAttributes.setPatternCallback(new LBMWildcardPatternCallback(topicFilter.comparePattern), null);
            }

            System.Console.Error.WriteLine("Creating wildcard receiver for pattern [" + pattern + "] - using pattern type: " + pattern_type);
            LBMWRcvReceiver wrcv = new LBMWRcvReceiver(verbose, end_on_eos);

            LBMWildcardReceiver lbmWildcardReceiver;
            LBMWRcvEventQueue   evq = null;

            if (eventq)
            {
                System.Console.Error.WriteLine("Event queue in use");
                evq = new LBMWRcvEventQueue();
                lbmWildcardReceiver = new LBMWildcardReceiver(ctx, pattern, null, lbmWildcardReceiverAttributes, wrcv.onReceive, null, evq);
                ctx.enableImmediateMessageReceiver(evq);
            }
            else
            {
                System.Console.Error.WriteLine("No event queue");
                lbmWildcardReceiver = new LBMWildcardReceiver(ctx, pattern, null, lbmWildcardReceiverAttributes, wrcv.onReceive, null);
                ctx.enableImmediateMessageReceiver();
            }
            ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(wrcv.onReceiveImmediate), null);

            wrcv.setWrcvr(lbmWildcardReceiver);
            wrcv.setDereg(dereg);

            if (channels.Count > 0)
            {
                System.Console.Error.Write("Subscribing to channels: ");
                foreach (uint channel in channels)
                {
                    try
                    {
                        lbmWildcardReceiver.subscribeChannel(channel, wrcv.onReceive, null);
                        System.Console.Error.Write("{0} ", channel);
                    }
                    catch (Exception e)
                    {
                        System.Console.Error.WriteLine();
                        System.Console.Error.WriteLine(e.Message);
                    }
                }
                System.Console.Error.WriteLine();
            }

            LBMMonitorSource lbmmonsrc = null;

            if (monitor_context)
            {
                lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options);
                lbmmonsrc.start(ctx, application_id, monitor_context_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;

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

                have_stats = false;
                while (!have_stats)
                {
                    try
                    {
                        stats      = ctx.getReceiverStatistics(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 */
                    }
                }

                lost = 0;
                for (int stat = 0; stat < stats.size(); stat++)
                {
                    lost += stats.lost(stat);
                }
                /* Account for loss in previous iteration */
                lost_tmp = lost;
                if (last_lost <= lost)
                {
                    lost -= last_lost;
                }
                else
                {
                    lost = 0;
                }
                last_lost = lost_tmp;

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

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

                if (print_stats_flag)
                {
                    print_stats(stats, evq);
                }

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

            System.Console.Error.WriteLine("Quitting.... received " + wrcv.total_msg_count + " messages");

            if (channels.Count > 0)
            {
                /* Unsubscribe from channels */
                foreach (uint channel in channels)
                {
                    lbmWildcardReceiver.unsubscribeChannel(channel);
                }
            }

            lbmWildcardReceiver.close();
            ctx.close();

            if (eventq)
            {
                evq.close();
            }
        }
コード例 #3
0
ファイル: TmonExample.cs プロジェクト: UltraMessaging/tmon
        void Run(string[] args)
        {
            string cfgFile = "application.cfg";
            string test    = "1";

            if (args.Length == 2)
            {
                cfgFile = args[0];
                test    = args[1];
            }
            else if (args.Length == 1)
            {
                cfgFile = args[0];
            }
            else if (args.Length != 0)
            {
                throw new TmonException("TmonExample: bad arg count (" + args.Length + ")");
            }

            LBM lbm = new LBM();

            lbm.setLogger(this.Logger);

            _timeOfDay = new TmonGetTimeOfDay();

            LBM.setConfiguration(cfgFile);

            MyLog("Creating context.");
            // Context name must be alpha, numeric, underscore, hyphen.
            LBMContextAttributes ctxAttr = new LBMContextAttributes("tmon_example_ctx");
            LBMContext           ctx     = new LBMContext(ctxAttr);

            MyLog("Creating topic monitor.");
            TmonContext tmonContext = new TmonContext(ctx);

            tmonContext.InitSender(); // I.e. this tmon context is for sending reports.

            MyLog("Creating wildcard rcv for '^.*2$' (will resolv, no msg)");
            TmonReceiver          tmonWRcv = tmonContext.ReceiverCreate(ReceiverType.Wildcard, "^.*2$");
            LBMReceiverAttributes rcvAttr  = new LBMReceiverAttributes("29west_tmon_context", "wc2");

            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonWRcv);
            LBMWildcardReceiver wrcv = new LBMWildcardReceiver(ctx, "^.*2$", rcvAttr,
                                                               null, this.OnReceive, null);

            MyLog("Creating rcv for 'src\\1' (will resolv, rcv msg)");
            TmonReceiver tmonRcv1 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src\\1");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src\\1");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcv1);
            LBMReceiver rcv1 = new LBMReceiver(ctx, ctx.lookupTopic("src\\1", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating rcv for 'src3' (will resolve, no msg)");
            TmonReceiver tmonRcv3 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src3");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src3");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcv3);
            LBMReceiver rcv3 = new LBMReceiver(ctx, ctx.lookupTopic("src3", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating rcv for 'srcx' (will not resolve)");
            TmonReceiver tmonRcvx = tmonContext.ReceiverCreate(ReceiverType.Regular, "srcx");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "srcx");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcvx);
            LBMReceiver rcvx = new LBMReceiver(ctx, ctx.lookupTopic("srcx", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating src for 'src\\1' (will resolve, send msg)");
            TmonSource          tmonSrc1 = tmonContext.SourceCreate("src\\1");
            LBMSourceAttributes srcAttr  = new LBMSourceAttributes("29west_tmon_context", "src\\1");
            LBMSource           src1     = ctx.createSource(ctx.allocTopic("src\\1", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Creating src for 'src,2' (wildcard resolve, no msg)");
            TmonSource tmonSrc2 = tmonContext.SourceCreate("src,2");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "src,2");
            LBMSource src2 = ctx.createSource(ctx.allocTopic("src,2", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Creating src for 'src3' (will resolve, no msg)");
            TmonSource tmonSrc3 = tmonContext.SourceCreate("src3");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "src3");
            LBMSource src3 = ctx.createSource(ctx.allocTopic("src3", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Delete receiver for 'src,2' to get DC delete without BOS or EOS");
            wrcv.close();
            tmonWRcv.Close();

            MyLog("Sleeping 6 for BOS triggered by TSNI for 'src\\1', 'src3'");
            Thread.Sleep(6000);

            MyLog("Deleting rcv for 'src3' while src still up - should get DC delete without EOS");
            rcv3.close();
            tmonRcv3.Close();

            string msg = "Hello!";

            if (test.Equals("1"))
            {
                MyLog("Sending to 'src\\1'");
                src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0);

                MyLog("Wait for msg receive or EOS");
                while (_messagesReceived == 0)
                {
                    Thread.Sleep(1000);
                }
            }
            else if (test.Equals("2"))
            {
                MyLog("Sending 120 msgs to 'src\\1'");
                for (int i = 0; i < 120; i++)
                {
                    src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0);
                } // for
                MyLog("lingering 10 sec");
                Thread.Sleep(10000);
            }
            else
            {
                throw new TmonException("TmonExample: bad test number (" + test + ")");
            }

            MyLog("Delete sources");
            src1.close();
            tmonSrc1.Close();
            src2.close();
            tmonSrc2.Close();
            src3.close();
            tmonSrc3.Close();

            MyLog("Sleeping 6 sec for EOS and DC delete for 'src\\1'.");
            Thread.Sleep(6000);

            MyLog("Deleting rcvs for 'src\\1'");
            rcv1.close();
            tmonRcv1.Close();

            MyLog("Generate rolling EOS on srcx");
            LBM.setLbtrmSrcLossRate(100);
            TmonSource tmonSrcx = tmonContext.SourceCreate("srcx");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "srcx");
            LBMSource srcx = ctx.createSource(ctx.allocTopic("srcx", srcAttr));

            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Start SMs going.
            Thread.Sleep(13750);                                    // Wait 2.5 * RM activity timeouts.

            MyLog("Generate BOS on srcx and msg");
            LBM.setLbtrmSrcLossRate(0);
            msg = "1";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS.
            Thread.Sleep(100);

            MyLog("Generate unrecoverable loss on srcx");
            LBM.setLbtrmSrcLossRate(100);
            msg = "2";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "3";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // 2*nak gen ivl.
            msg = "4";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event.
            Thread.Sleep(100);

            MyLog("Generate suppressed unrecoverable loss");
            LBM.setLbtrmSrcLossRate(0);
            msg = "1";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(100);
            msg = "2";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "3";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // 2*nak gen ivl.
            msg = "4";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event.
            Thread.Sleep(100);

            Thread.Sleep(10100); // Expire tmon's 10-second loss suppression.

            MyLog("Generate unrecoverable burst loss");
            LBM.setLbtrmSrcLossRate(100);
            msg = "5";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "6";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "7";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "8";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "9";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // Wait for BURST.

            MyLog("Delete rcvx, srcx.");
            rcvx.close();
            tmonRcvx.Close();
            srcx.close();
            tmonSrcx.Close();

            MyLog("Deleting tmon_ctx.");
            tmonContext.Close();

            MyLog("Deleting context.");
            ctx.close();
        } // Run