Пример #1
0
    static void Main(String[] args)
    {
        LBMContext          ctx = null;                               /* Context object: container for UM "instance". */
        LBMReceiver         rcv = null;                               /* Source object: for sending messages. */
        LBMEventQueue       evq = null;                               /* Event Queue object: process receiver events on app thread */
        LBMReceiverCallback cb  = new LBMReceiverCallback(onReceive); /* Wrapping the onReceive functor in a callback */

        ctx = new LBMContext();
        evq = new LBMEventQueue();
        {
            LBMTopic topic = null;
            topic = ctx.lookupTopic("test.topic");

            /* The event queue object is passed into the receiver constructor */
            /* This causes events to be queued in an unbounded Q.  In order   */
            /* to process these messages the evq.Run() method must be called  */
            rcv = new LBMReceiver(ctx, topic, onReceive, null, evq);
        }


        /* run the event queue for 60 seconds           */
        /* all the receiver events will be processed    */
        /* in this thread. This includes message        */
        /* processing.							        */
        evq.run(60000);

        try {
            /* Shutdown order is important.  Event Queues should */
            /* be .close()d after the context and receiver.      */
            rcv.close();
            ctx.close();
            evq.close();
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }
    }
Пример #2
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
        LBMReceiver rcv = null; /* Source object: for sending messages. */
        LBMEventQueue evq = null; /* Event Queue object: process receiver events on app thread */
        LBMReceiverCallback cb = new LBMReceiverCallback(onReceive);    /* Wrapping the onReceive functor in a callback */

        ctx = new LBMContext();
        evq = new LBMEventQueue();
        {
            LBMTopic topic = null;
            topic = ctx.lookupTopic("test.topic");

            /* The event queue object is passed into the receiver constructor */
            /* This causes events to be queued in an unbounded Q.  In order   */
            /* to process these messages the evq.Run() method must be called  */
            rcv = new LBMReceiver(ctx, topic, onReceive, null, evq);
        }

        /* run the event queue for 60 seconds         	*/
        /* all the receiver events will be processed  	*/
        /* in this thread. This includes message 		*/
        /* processing.							  		*/
        evq.run(60000);

        try {
            /* Shutdown order is important.  Event Queues should */
            /* be .close()d after the context and receiver.      */
            rcv.close();
            ctx.close();
            evq.close();
        }
        catch(LBMException ex)
        {
            System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }
    }
Пример #3
0
    static void Main(String[] args)
    {
        LBMContext ctx = null; /* Context object: container for UM "instance". */
                LBMEventQueue evq = new LBMEventQueue();

                /* Initialization: create necessary UM objects. */
                try {
                        LBMContextAttributes ctxAttr = new LBMContextAttributes();
                        ctx = new LBMContext(ctxAttr);
                }
                catch(LBMException ex)
                {
                        System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
                        System.Environment.Exit(1);
                }

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

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

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

                EQThread evqThread = new EQThread(evq);
                evqThread.start();

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

                src.send(Encoding.ASCII.GetBytes("hello"), 5, LBM.MSG_FLUSH);

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

                evq.stop();
                evqThread.join();

                src.close();
                rcv.close();
                ctx.close();
                evq.close();
    }
Пример #4
0
    static void Main(String[] args)
    {
        LBMContext    ctx = null; /* Context object: container for UM "instance". */
        LBMEventQueue evq = new LBMEventQueue();

        /* Initialization: create necessary UM objects. */
        try
        {
            LBMContextAttributes ctxAttr = new LBMContextAttributes();
            ctx = new LBMContext(ctxAttr);
        }
        catch (LBMException ex)
        {
            System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
            System.Environment.Exit(1);
        }

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

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

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

        EQThread evqThread = new EQThread(evq);

        evqThread.start();

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

        src.send(Encoding.ASCII.GetBytes("hello"), 5, LBM.MSG_FLUSH);

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

        evq.stop();
        evqThread.join();

        src.close();
        rcv.close();
        ctx.close();
        evq.close();
    } /* main */