/// <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); } } } }
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++; } }
public void onTimer(MamaTimer mamaTimer, object closure) { lock (myGuard) { onTimerImpl(); } }
public void onTimer(MamaTimer mamaTimer, object closure) { // Destroy the timer mamaTimer.destroy(); // Stop the bridge to unblock the main thread Mama.stop(m_bridge); }
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"); }
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; }
private static MamaTimer safeCreateTimer( MamaTimerCallback callback, double interval) { MamaTimer timer = null; try { timer = new MamaTimer(); timer.create(defaultQueue, callback, interval, null); } catch (Exception e) { Console.Error.WriteLine(e.ToString()); Console.Error.WriteLine("Error creating timer: {0}", e.Message); Environment.Exit(1); } return(timer); }
/// <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(); } } }
public void onDestroy(MamaTimer mamaTimer, object closure) { Mama.stop(m_bridge); }
public void destroy() { statstimer.destroy(); statstimer = null; }
public void onDestroy(MamaTimer mamaTimer, object closure) { }
public void onTimer(MamaTimer mamaTimer, object closure) { mamaTimer.destroy(); }
private static MamaTimer safeCreateTimer( MamaTimerCallback callback, double interval) { MamaTimer timer = null; try { timer = new MamaTimer(); timer.create(defaultQueue, callback, interval, null); } catch (Exception e) { Console.Error.WriteLine(e.ToString()); Console.Error.WriteLine("Error creating timer: {0}", e.Message); Environment.Exit(1); } return timer; }
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); } }
public static void Main(string[] args) { try { options = new CommandLineProcessor(args); //Getting the log File name myLogFileName = options.getLogFileName(); if (myLogFileName != null) { myOutFile = new FileStream(myLogFileName, FileMode.OpenOrCreate); myOut = new StreamWriter(myOutFile); myOut.WriteLine("Date/Time"+ "," + "ChurnStats" +"," + "UpdateStats" + "," + "PeakMsgCount" + "," + "RecapStats" + "," + "BookGapStats" + "," +"freeMemory" +"," +"Memory Used"); } else { myOut = Console.Out; } // Initialize MAMA bridge = new MamaBridge(options.getMiddleware()); Mama.open(); if (options.hasLogLevel()) { myLogLevel = options.getLogLevel(); Mama.enableLogging(myLogLevel); } transport = new MamaTransport(); transport.create(options.getTransport(), bridge); defaultQueue = Mama.getDefaultEventQueue(bridge); //Get the Data dictionary..... MamaSource dictionarySource = new MamaSource(); dictionarySource.symbolNamespace = options.getDictSource(); dictionarySource.transport = transport; dictionary = buildDataDictionary(transport, defaultQueue, dictionarySource); MamdaOrderBookFields.setDictionary(dictionary, null); foreach (string symbol in options.getSymbolList()) { subscribeToBooks(symbol); } myChurnRate = options.getChurnRate(); Thread.Sleep(10000); //Getting the TimerInterval from the cmd prompt myChurnInterval = options.getTimerInterval(); //Churn Timer if (myChurnRate > 0) { myChurnTimer = safeCreateTimer(new ChurnCallback(), myChurnInterval); } //Stats Timer myStatsTimer = safeCreateTimer(new StatsCallback(), 1.0); Console.WriteLine("Hit Enter or Ctrl-C to exit."); Mama.start(bridge); GC.KeepAlive(dictionary); Console.ReadLine(); if (myOutFile != null) { myOut.Close(); } } catch (Exception e) { Console.Error.WriteLine(e.ToString()); Environment.Exit(1); } }