Exemple #1
0
        static void Main(string[] args)
        {
            LBMContext ctx = null; /* Context object: container for UM "instance". */
            LBMSource src = null; /* Source object: for sending messages. */
            LBMEventQueue evq = null; /* Event Queue object: process source events on app thread */
            SrcCB cb = null;


            /*** Create a source using an event queue ***/
            try
            {
                LBMTopic topic = null;
                LBMSourceAttributes srcAttr = null;

                ctx = new LBMContext();
                srcAttr = new LBMSourceAttributes();

                /* create callback to process events */
                cb = new SrcCB();

                /* define Event Queue. This allows us to process events on an  */
                /* application thread, as opposed to the default behavior,     */
                /* which is to process events on the (internal) context thread.*/
                evq = new LBMEventQueue();

                topic = ctx.allocTopic("test.topic", srcAttr);
                src = new LBMSource(ctx, topic, evq);
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }


            /* run the event queue for 60 seconds       */
            /* all the source events will be processed  */
            /* in this thread
            evq.run(60000);

            try
            {
                src.close();
                ctx.close();
                evq.close();
            }
            catch (LBMException ex)
            {
                System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
                System.Environment.Exit(1);
            }

        } /* main */
    } /* class eventQ */
Exemple #2
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);
                }
            }
        }
    }
Exemple #3
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 */