Example #1
0
            /* ************************************************************** */
            #region Construction and Finalization

            /// <summary>
            /// Constructor initialises all member variables.
            /// </summary>
            /// <param name="callback">
            /// The user callback implementation
            /// </param>
            /// <param name="closure">
            /// The closure supplied to the MamaTimer.create function.
            /// </param>
            /// <param name="timer">
            /// The actual C# timer object.
            /// </param>
            internal MamaTimerImpl(MamaTimerCallback callback, object closure, MamaTimer timer)
            {
                // Save arguments in member variables
                mCallback = callback;
                mClosure  = closure;
                mTimer    = timer;
            }
Example #2
0
        public int Run()
        {
            ParseArgs();
            if (helpNeeded)
            {
                DisplayUsage();
                return 0;
            }

            Mama.logToFile(@"mama.log", MamaLogLevel.MAMA_LOG_LEVEL_FINEST);
            bridge = Mama.loadBridge(middlewareName);
            Mama.open();
            MamaTransport transport = new MamaTransport();
            MamaQueue defaultQueue = Mama.getDefaultEventQueue(bridge);
            MamaTimer timer = new MamaTimer();
            MamaSubscription subscription = new MamaSubscription();
            MamaPublisherCS publisher = this;

            transport.create(transportName, bridge);
            timer.create(defaultQueue, publisher, interval, null);
            subscription.createBasic(transport, defaultQueue, publisher, inboundTopic);
            publisher.create(transport, outboundTopic);
            msg = new MamaMsg();

            Mama.start(bridge);
            Mama.close();
            return 0;
        }
        public int Run()
        {
            ParseArgs();
            if (helpNeeded)
            {
                DisplayUsage();
                return(0);
            }

            Mama.logToFile(@"mama.log", MamaLogLevel.MAMA_LOG_LEVEL_FINEST);
            bridge = Mama.loadBridge(middlewareName);
            Mama.open();
            MamaTransport    transport    = new MamaTransport();
            MamaQueue        defaultQueue = Mama.getDefaultEventQueue(bridge);
            MamaTimer        timer        = new MamaTimer();
            MamaSubscription subscription = new MamaSubscription();
            MamaPublisherCS  publisher    = this;

            transport.create(transportName, bridge);
            timer.create(defaultQueue, publisher, interval, null);
            subscription.createBasic(transport, defaultQueue, publisher, inboundTopic);
            publisher.create(transport, outboundTopic);
            msg = new MamaMsg();

            Mama.start(bridge);
            Mama.close();
            return(0);
        }
Example #4
0
 public static extern int mamaTimer_create2(
     ref IntPtr result,
     IntPtr queue,
     MamaTimer.OnTimerTickDelegate tickCallback,
     MamaTimer.OnTimerTickDelegate destroyCallback,
     double interval,
     IntPtr closure);
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     Publish(null);
     if (messageCount_ > 0 && --messageCount_ == 0)
     {
         Mama.stop(bridge);
         return;
     }
 }
 // Timer Callbacks
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     Publish(null);
     if (messageCount > 0 && --messageCount <= 0)
     {
         publisher.destroy();
         System.Threading.Thread.Sleep(1000);                                    // let queued events process
         Mama.stop(bridge);
     }
 }
        public int Run()
        {
            ParseArgs();
            if (helpNeeded)
            {
                DisplayUsage();
                return(0);
            }

            Mama.logToFile(@"mama.log", MamaLogLevel.MAMA_LOG_LEVEL_NORMAL);

            bridge = Mama.loadBridge(middlewareName);

            Mama.open();

            MamaQueue defaultQueue = Mama.getDefaultEventQueue(bridge);

            msg = new MamaMsg();

            MamaTimer timer = new MamaTimer();

            timer.create(defaultQueue, this, interval, null);

            queueGroup = new MamaQueueGroup(bridge, 1);

            MamaTransport transport = new MamaTransport();

            transport.create(transportName, bridge);

            MamaSubscription subscription = null;

            if (nosub == false)
            {
                subscription = new MamaSubscription();
                subscription.createBasic(transport, defaultQueue, this, inboundTopic);
            }

            publisher = new MamaPublisher();
            if (pubCb)
            {
                publisher.createWithCallbacks(transport, queueGroup.getNextQueue(), this, null, outboundTopic, null, null);
            }
            else
            {
                publisher.create(transport, outboundTopic);
            }

            Mama.start(bridge);

            Mama.close();

            return(0);
        }
Example #8
0
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     outer_.OnTimerCallback();
 }
Example #9
0
 public void onDestroy(MamaTimer mamaTimer, object closure)
 {
     Mama.stop(m_bridge);
 }
Example #10
0
 public void onDestroy(MamaTimer mamaTimer, object closure)
 {
 }
Example #11
0
        private void parseCommandLine(string[] args)
        {
            string tport = null;
            uint ft_type = (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST;
            bool displayVersion = false;
            for (int i = 0; i < args.Length; )
            {
                if ((args[i].CompareTo ("-h")) == 0 ||
                    (args[i].CompareTo ("-?")) == 0)
                {
                    usage (0);
                }

                if ((args[i].CompareTo ("-g") == 0) ||
                    (args[i].CompareTo ("-group") == 0))
                {
                    myGroup = args[i+1];
                    i += 2;
                    continue;
                }

                if ((args[i].CompareTo ("-w") == 0) ||
                    (args[i].CompareTo ("-weight") == 0))
                {
                    myWeight = Convert.ToUInt32 (args[i+1]);
                    i += 2;
                    continue;
                }

                if (args[i].CompareTo ("-m") == 0)
                {
                    myMiddleware = args[i+1];
                    i += 2;
                    continue;
                }

                if ((args[i].CompareTo ("-t") == 0) ||
                    (args[i].CompareTo ("-tport") == 0))
                {
                    tport = args[i+1];
                    i += 2;
                    continue;
                }

                if (args[i].CompareTo ("-v") == 0)
                {
                    if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_WARN)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_NORMAL;
                        Mama.enableLogging (mamaLogLevel);
                    }
                    else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_NORMAL)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINE;
                        Mama.enableLogging (mamaLogLevel);
                    }
                    else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_FINE)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINER;
                        Mama.enableLogging (mamaLogLevel);
                    }
                    else
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINEST;
                        Mama.enableLogging (mamaLogLevel);
                    }
                    i++;
                    continue;
                }

                if (args[i].CompareTo ("-version") == 0)
                {
                    displayVersion = true;
                    break;
                }

                if (args[i].CompareTo ("-b") == 0)
                {
                    ft_type = (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE;
                   i++;
                    continue;
                }

                i++;
            }

            myBridge = Mama.loadBridge(myMiddleware);

            Mama.open();

            if (displayVersion)
            {
                Console.WriteLine (Mama.getVersion (myBridge));
                Exit (0);
            }

            myTimer = new MamaTimer();

            myTransport = new MamaTransport();
            myTransport.create(tport, myBridge);

            if (myGroup == null)
            {
                Console.WriteLine ("No FT group name specified");
                usage(1);
            }

            switch (ft_type)
            {
                case (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST:
                    myFtMember = new MamaMulticastFtMember ();
                    break;

                case (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE:
                    myFtMember = new MamaBridgeFtMember ();
                    break;

                default:
                    Console.WriteLine ("No FT type specified");
                    usage(1);
                    break;
            }
        }
Example #12
0
 public void onTimer(MamaTimer timer, object closure)
 {
     printState ("Timer");
 }
Example #13
0
        private void parseCommandLine(string[] args)
        {
            string tport          = null;
            uint   ft_type        = (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST;
            bool   displayVersion = false;

            for (int i = 0; i < args.Length;)
            {
                if ((args[i].CompareTo("-h")) == 0 ||
                    (args[i].CompareTo("-?")) == 0)
                {
                    usage(0);
                }

                if ((args[i].CompareTo("-g") == 0) ||
                    (args[i].CompareTo("-group") == 0))
                {
                    myGroup = args[i + 1];
                    i      += 2;
                    continue;
                }

                if ((args[i].CompareTo("-w") == 0) ||
                    (args[i].CompareTo("-weight") == 0))
                {
                    myWeight = Convert.ToUInt32(args[i + 1]);
                    i       += 2;
                    continue;
                }

                if (args[i].CompareTo("-m") == 0)
                {
                    myMiddleware = args[i + 1];
                    i           += 2;
                    continue;
                }

                if ((args[i].CompareTo("-t") == 0) ||
                    (args[i].CompareTo("-tport") == 0))
                {
                    tport = args[i + 1];
                    i    += 2;
                    continue;
                }

                if (args[i].CompareTo("-v") == 0)
                {
                    if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_WARN)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_NORMAL;
                        Mama.enableLogging(mamaLogLevel);
                    }
                    else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_NORMAL)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINE;
                        Mama.enableLogging(mamaLogLevel);
                    }
                    else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_FINE)
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINER;
                        Mama.enableLogging(mamaLogLevel);
                    }
                    else
                    {
                        mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINEST;
                        Mama.enableLogging(mamaLogLevel);
                    }
                    i++;
                    continue;
                }

                if (args[i].CompareTo("-version") == 0)
                {
                    displayVersion = true;
                    break;
                }

                if (args[i].CompareTo("-b") == 0)
                {
                    ft_type = (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE;
                    i++;
                    continue;
                }

                i++;
            }

            myBridge = Mama.loadBridge(myMiddleware);

            Mama.open();

            if (displayVersion)
            {
                Console.WriteLine(Mama.getVersion(myBridge));
                Exit(0);
            }

            myTimer = new MamaTimer();

            myTransport = new MamaTransport();
            myTransport.create(tport, myBridge);

            if (myGroup == null)
            {
                Console.WriteLine("No FT group name specified");
                usage(1);
            }

            switch (ft_type)
            {
            case (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST:
                myFtMember = new MamaMulticastFtMember();
                break;

            case (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE:
                myFtMember = new MamaBridgeFtMember();
                break;

            default:
                Console.WriteLine("No FT type specified");
                usage(1);
                break;
            }
        }
Example #14
0
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     outer_.OnTimerCallback();
 }
Example #15
0
        public void onTimer(MamaTimer mamaTimer, object closure)
        {
            mamaTimer.destroy();

            // Only continue if the application is not shutting down
            bool shuttingDown = m_killEvent.WaitOne(0, false);
            if (!shuttingDown)
            {
                int i = (int)closure;

                mamaSubscriptions[i].destroy();

                mamaSubscriptions[i] = new MamaSubscription();

                mamaSubscriptions[i].setServiceLevel(mamaServiceLevel.MAMA_SERVICE_LEVEL_REAL_TIME);

                mamaSubscriptions[i].setSubscriptionType(mamaSubscriptionType.MAMA_SUBSC_TYPE_NORMAL);

                mamaSubscriptions[i].setTimeout(10);

                mamaSubscriptions[i].setRetries(3);

                mamaSubscriptions[i].setRequiresInitial(true);

                mamaSubscriptions[i].create(
                    mamaQueueGroup == null ? mamaDefaultQueue : mamaQueueGroup.getNextQueue(),
                    this,
                    mamaSource,
                    mamaSymbols[i]);
                stats.mRecreates++;
            }
        }
Example #16
0
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     mamaTimer.destroy();
 }
Example #17
0
 public void destroy()
 {
     statstimer.destroy();
     statstimer = null;
 }
Example #18
0
        /// <summary>
        /// This is the thread procedure that is executed by the churn thread, it will keep
        /// churning subscriptions until the kill event is set.
        /// </summary>
        private void ChurnThreadProc()
        {

            for (; ; )
            {
                // Check the for kill event
                bool signal = m_killEvent.WaitOne(1000, false);

                // Quit the loop if the kill signal was received
                if (signal)
                {
                    break;
                }

                // Churn subscriptions
                for (int j = 0; j < quota; j++)
                {
                    int i = mamaRandom.Next(0, mamaNumSymbols);

                    MamaTimer timer = new MamaTimer();

                    // Get the queue
                    MamaQueue queue = mamaSubscriptions[i].subscQueue;
                    if (queue != null)
                    {
                        timer.create(queue, this, m_churnTimeout, i);
                    }
                }
            }
        }
Example #19
0
            public void onTimer(MamaTimer mamaTimer, object closure)
            {
                // Destroy the timer
                mamaTimer.destroy();

                // Stop the bridge to unblock the main thread
                Mama.stop(m_bridge);
            }
Example #20
0
            /* ************************************************************** */
            #region Internal Operations

            /// <summary>
            /// This function creates a new impl and returns an IntPtr that can then be passed to
            /// the native layer.
            /// </summary>
            /// <param name="callback">
            /// The user callback implementation
            /// </param>
            /// <param name="closure">
            /// The closure supplied to the MamaTimer.create function.
            /// </param>
            /// <param name="timer">
            /// The actual C# timer object.
            /// </param>
            /// <returns>
            /// The IntPtr that can then be used for the closure.
            /// </returns>
            internal static IntPtr Create(MamaTimerCallback callback, object closure, MamaTimer timer)
            {
                // Allocate a new impl
                MamaTimerImpl impl = new MamaTimerImpl(callback, closure, timer);

                // Create a GC handle
                GCHandle handle = GCHandle.Alloc(impl);

                // Return the native pointer
                return((IntPtr)handle);
            }
Example #21
0
        /// <summary>
        /// This function will run the application and create market data subscriptions.
        /// </summary>
        /// <param name="args">
        /// Command line arguments.
        /// </param>            
        internal void run(string[] args)
        {
            // Install an event handler to capture the Ctrl-C press
            NativeMethods.ControlEventHandler eventHandler = new NativeMethods.ControlEventHandler(this.onControlHandler);
            NativeMethods.SetConsoleCtrlHandler(eventHandler, true);

            // Parse the command line arguments
            bool shouldContinue = parseCommandLine(args);
            if (shouldContinue)
            {
                initializeMama();
                try
                {
                    createSubscriptions();
                    try
                    {
                        // Create a shutdown timer if appropriate
                        if (m_shutdownTime > 0)
                        {
                            // The timer will be destroyed whenever it ticks
                            MamaTimer shutdownTimer = new MamaTimer();
                            shutdownTimer.create(m_defaultQueue, new ListenShutdownTimerCallback(m_bridge), m_shutdownTime, null);
                        }

                        // Start the bridge, this call will block until either Ctrl C is pressed or the shutdown timer ticks
                        Mama.start(m_bridge);
                    }

                    finally
                    {
                        destroySubscriptions();
                    }
                }
                finally
                {
                    // Clean up mama
                    uninitializeMama();
                }
            }
        }
Example #22
0
        public int Run()
        {
            ParseArgs();
            if (helpNeeded)
            {
                DisplayUsage();
                return 0;
            }

            Mama.logToFile(@"mama.log", MamaLogLevel.MAMA_LOG_LEVEL_NORMAL);

            bridge = Mama.loadBridge(middlewareName);

            Mama.open();

            MamaQueue defaultQueue = Mama.getDefaultEventQueue(bridge);
            msg = new MamaMsg();

            MamaTimer timer = new MamaTimer();
            timer.create(defaultQueue, this, interval, null);

            queueGroup = new MamaQueueGroup(bridge, 1);

            MamaTransport transport = new MamaTransport();
            transport.create(transportName, bridge);

            MamaSubscription subscription = null;
            if (nosub == false)
            {
                subscription = new MamaSubscription();
                subscription.createBasic(transport, defaultQueue, this, inboundTopic);
            }

            publisher = new MamaPublisher();
            if (pubCb)
            {
                publisher.createWithCallbacks(transport, queueGroup.getNextQueue(), this, null, outboundTopic, null, null);
            }
            else
            {
                publisher.create(transport, outboundTopic);
            }

            Mama.start(bridge);

            Mama.close();

            return 0;
        }
Example #23
0
 // Timer Callbacks
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     Publish(null);
     if (messageCount > 0 && --messageCount <= 0)
     {
         publisher.destroy();
         System.Threading.Thread.Sleep(1000);                    // let queued events process
         Mama.stop(bridge);
     }
 }
Example #24
0
            public StatsReport(MamaQueue mamaDefaultQueue)
            {
                statstimer = new MamaTimer();

                statstimer.create(mamaDefaultQueue, this, 2, null);

                Console.WriteLine("    Time" + " {0, -4} {1, -4} {2, -4} {3, -4} {4, -2}",
                    "Create", "Inital", "OtherMsg", "Error", "Recreate");
            }
Example #25
0
            /* ************************************************************** */
            #region Construction and Finalization

            /// <summary>
            /// Constructor initialises all member variables.
            /// </summary>
            /// <param name="callback">
            /// The user callback implementation
            /// </param>
            /// <param name="closure">
            /// The closure supplied to the MamaTimer.create function.
            /// </param>
            /// <param name="timer">
            /// The actual C# timer object.
            /// </param>
            internal MamaTimerImpl(MamaTimerCallback callback, object closure, MamaTimer timer)
            {
                // Save arguments in member variables
                mCallback  = callback;
                mClosure   = closure;
                mTimer     = timer;
            }
Example #26
0
            public void onTimer(MamaTimer mamaTimer, object closure)
            {
                DateTime saveNow = DateTime.Now;

                Console.WriteLine(saveNow.ToLongTimeString() + "     {0, -6} {1, -6} {2, -6} {3, -6} {4, -6}",
                                    mCreateMsgCount, mInitialMsgCount, mOtherMsgCount, mErrorCount, mRecreates);

                mCreateMsgCount = 0;
                mInitialMsgCount = 0;
                mOtherMsgCount = 0;
                mErrorCount = 0;
                mRecreates = 0;
            }
Example #27
0
            /* ************************************************************** */
            #region Internal Operations

            /// <summary>
            /// This function creates a new impl and returns an IntPtr that can then be passed to
            /// the native layer.
            /// </summary>
            /// <param name="callback">
            /// The user callback implementation
            /// </param>
            /// <param name="closure">
            /// The closure supplied to the MamaTimer.create function.
            /// </param>
            /// <param name="timer">
            /// The actual C# timer object.
            /// </param>
            /// <returns>
            /// The IntPtr that can then be used for the closure.
            /// </returns>
            internal static IntPtr Create(MamaTimerCallback callback, object closure, MamaTimer timer)
            {
                // Allocate a new impl
                MamaTimerImpl impl = new MamaTimerImpl(callback, closure, timer);

                // Create a GC handle
                GCHandle handle = GCHandle.Alloc(impl);

                // Return the native pointer
                return (IntPtr)handle;
            }
Example #28
0
        private MamaChurnCS(string[] args)
        {
            try
            {
                if (parseCommandLine(args))
                {

                    // Start up the underlying API
                    initializeMama();
                    try
                    {
                        // Create all of the subscriptions
                        createSubscriptions();
                        try
                        {
                            // Create the autoreset event that will be used to shutdown
                            m_killEvent = new ManualResetEvent(false);

                            // Create a spearate thread to perform the churn
                            m_churnThread = new Thread(new ThreadStart(this.ChurnThreadProc));
                            m_churnThread.IsBackground = true;
                            m_churnThread.Name = "destroyerThread: ";
                            m_churnThread.Start();

                            stats = new StatsReport(mamaDefaultQueue);

                            // If the timeout has been supplied then create a new timer
                            if (m_killTimeout > 0)
                            {
                                MamaTimer killTimer = new MamaTimer();
                                killTimer.create(Mama.getDefaultEventQueue(mamaBridge), new KillTimerCallback(mamaBridge), m_killTimeout, null);
                            }

                            // Keep procssing messages until the kill timer elapses
                            Mama.start(mamaBridge);

                            // Destroy the stats timer
                            stats.destroy();

                            // Kill the churn thread by signaling the auto reset event
                            m_killEvent.Set();

                            // Wait until the thread terminates
                            m_churnThread.Join();
                        }

                        finally
                        {
                            // Stop processing all the queues
                            mamaQueueGroup.stop();

                            // Destroy all the subscriptions                            
                            for (int subIndex = 0; subIndex < mamaSubscriptions.Length; subIndex++)
                            {
                                mamaSubscriptions[subIndex].destroy();
                                mamaSubscriptions[subIndex] = null;
                            }
                        }
                    }

                    finally
                    {
                        // Uninitialise the api
                        unintializeMama();
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #29
0
 public void onTimer(MamaTimer timer, object closure)
 {
     printState("Timer");
 }
Example #30
0
 public void onDestroy(MamaTimer mamaTimer, object closure)
 {
 }
Example #31
0
 public void onTimer(MamaTimer mamaTimer, object closure)
 {
     Publish(null);
     if (messageCount_ > 0 && --messageCount_ == 0)
     {
         Mama.stop(bridge);
         return;
     }
 }