Пример #1
0
        public void Init()
        {
            LBMObjectRecycler objRec = new LBMObjectRecycler();

            //Lower the defaults for messages since we expect a lower rate that request will be arriving
            objRec.setLocalMsgPoolSize(10);
            objRec.setSharedMsgPoolSize(20);

            LBMContextAttributes lbmContextAttributes = new LBMContextAttributes();

            lbmContextAttributes.setObjectRecycler(objRec, null);

            LBMReceiverAttributes lbmReceiverAttributes = new LBMReceiverAttributes();

            lbmReceiverAttributes.setObjectRecycler(objRec, null);

            LBMContext lbmContext = new LBMContext(lbmContextAttributes);
            LBMTopic   lbmTopic   = new LBMTopic(lbmContext, "test.topic", lbmReceiverAttributes);

            var lbmEventQueue = new LBMRespEventQueue();

            var lbmReveiver = new LBMRespReceiver(lbmContext, lbmTopic, lbmEventQueue, 1, false);

            lbmContext.enableImmediateMessageReceiver(lbmEventQueue);
            lbmContext.addImmediateMessageReceiver(lbmReveiver.onReceiveImmediate);

            lbmEventQueue.run(0);

            Console.ReadLine();
        }
Пример #2
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  response_len = 25;
            int  responses    = 1;
            int  i;
            int  n     = args.Length;
            bool error = false;
            bool done  = false;
            LBMObjectRecycler objRec = new LBMObjectRecycler();

            //Lower the defaults for messages since we expect a lower rate that request will be arriving
            objRec.setLocalMsgPoolSize(10);
            objRec.setSharedMsgPoolSize(20);

            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("lbmresp error: " + Ex.Message);
                            error = true;
                        }
                        break;

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

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

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

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

                    case "-r":
                        if (++i >= n)
                        {
                            error = true;
                            break;
                        }
                        responses = Convert.ToInt32(args[i]);
                        if (responses <= 0)
                        {
                            /*Negative # of responses not allowed*/
                            print_help_exit(1);
                        }
                        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 */
                    System.Console.Error.WriteLine("lbmresp: 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);
            }
            byte[] response_buffer     = new byte[response_len];
            LBMContextAttributes cattr = new LBMContextAttributes();

            cattr.setObjectRecycler(objRec, null);
            LBMContext        ctx = new LBMContext(cattr);
            LBMRespEventQueue evq = null;
            //LBMTopic topic =  ctx.lookupTopic(args[i]);
            LBMReceiverAttributes rattr = new LBMReceiverAttributes();

            rattr.setObjectRecycler(objRec, null);
            LBMTopic        topic = new LBMTopic(ctx, args[i], rattr);
            LBMRespReceiver rcv;

            if (eventq)
            {
                System.Console.Error.WriteLine("Event queue in use");
                evq = new LBMRespEventQueue();
                rcv = new LBMRespReceiver(ctx, topic, evq, verbose, end_on_eos);
                ctx.enableImmediateMessageReceiver(evq);
            }
            else
            {
                System.Console.Error.WriteLine("No event queue");
                rcv = new LBMRespReceiver(ctx, topic, verbose, end_on_eos);
                ctx.enableImmediateMessageReceiver();
            }
            ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(rcv.onReceiveImmediate));
            try {
                ASCIIEncoding enc = new ASCIIEncoding();
                while (true)
                {
                    if (!eventq)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    else
                    {
                        evq.run(100);
                    }
                    if (rcv.request != null)
                    {
                        System.Console.Out.WriteLine("Sending response. " +
                                                     "{0} response{1} of {2} bytes{3} ({4} total bytes).\n",
                                                     responses, (responses == 1 ? "" : "s"), response_len,
                                                     (responses == 1 ? "" : " each"), responses * response_len);
                        System.Console.Out.Flush();
                        for (i = 0; i < responses; i++)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendFormat("response {0}", i);
                            enc.GetBytes(sb.ToString(), 0, sb.ToString().Length, response_buffer, 0);
                            rcv.request.respond(response_buffer, response_len, 0);
                        }
                        rcv.request.dispose();
                        objRec.doneWithMessage(rcv.request);
                        rcv.request = null;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: {0}", e.Message);
            }
        }