Esempio n. 1
0
        private void createSubscriptions()
        {
            mamaSource = new MamaSource();
            mamaSource.symbolNamespace = mamaSourceName;
            mamaSource.transport       = mamaTransport;

            for (int i = 0; i < mamaNumSymbols; i++)
            {
                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]);
            }
        }
Esempio n. 2
0
        private static void subscribeToSubjects()
        {
            int howMany = 0;

            queueGroup = new MamaQueueGroup(myBridge, numThreads);

            /* Subscribe to all symbols parsed from the symbol list */
            for (IEnumerator enumerator = subjectList.GetEnumerator(); enumerator.MoveNext();)
            {
                string symbol = (string)enumerator.Current;

                MamaSubscription subscription = new MamaSubscription();

                subscription.create(
                    queueGroup.getNextQueue(),
                    subscriptionCallback,
                    mySource,
                    symbol,
                    null);

                subscriptions.Add(subscription);
                if (++howMany % 1000 == 0)
                {
                    Console.WriteLine("Subscribed to " + howMany + " symbols.");
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This function will create subscriptions for all the symbols in the array list.
        /// </summary>
        private void createSubscriptions()
        {
            // There must be at least 1 symbol
            if (m_symbols.Count < 1)
            {
                throw new ApplicationException("There are no symbols to subscribe to.");
            }

            ListenerSubscriptionCallback subscriptionCallback = new ListenerSubscriptionCallback(m_dictionary, m_iterator, m_quietness, m_symbols.Count);

            // Enumerate all the symbol names and create a subscription for each one
            foreach (string symbol in m_symbols)
            {
                MamaSubscription subscription = new MamaSubscription();

                // Set the service level depending on whether we need a snapshot subscription or not
                if (m_snapshot)
                {
                    subscription.setServiceLevel(mamaServiceLevel.MAMA_SERVICE_LEVEL_SNAPSHOT);
                }

                else
                {
                    subscription.setServiceLevel(mamaServiceLevel.MAMA_SERVICE_LEVEL_REAL_TIME);
                }

                // Complete the remaining properties
                subscription.setSubscriptionType(mamaSubscriptionType.MAMA_SUBSC_TYPE_NORMAL);
                subscription.setTimeout(10);
                subscription.setRetries(3);
                subscription.setRequiresInitial(true);

                /* Determine the queue to use, if there are multiple threads running then the next queue in the
                 * group will be acquired.
                 */
                MamaQueue queue = m_defaultQueue;
                if (m_queueGroup != null)
                {
                    queue = m_queueGroup.getNextQueue();
                }

                subscription.create(queue, subscriptionCallback, m_source, symbol);

                // Add the subscription to the array list so that they can all be destroyed later on
                m_subscriptions.Add(subscription);
            }
        }
Esempio n. 4
0
        private void createQueues()
        {
            mamaDefaultQueue = Mama.getDefaultEventQueue(mamaBridge);

            mamaQueueGroup = new MamaQueueGroup(mamaBridge, mamaThreads);

            if (mamaThreads > 0)
            {
                // Has queue monitoring been enabled?
                if (mamaHighWaterMark > 0 || mamaLowWaterMark > 0)
                {
                    for (int index = 0; index < mamaThreads; index++)
                    {
                        MamaQueue queue     = mamaQueueGroup.getNextQueue();
                        string    queueName = "QUEUE " + index;
                        Console.WriteLine("Setting monitor for " + queueName);
                        queue.setQueueMonitorCallbacks(this, queueName);
                        if (mamaHighWaterMark > 0)
                        {
                            queue.setHighWatermark(mamaHighWaterMark);
                        }

                        if (mamaLowWaterMark > 0)
                        {
                            try
                            {
                                // Not supported on all middlewares.
                                queue.setLowWatermark(mamaLowWaterMark);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Could not set " + queueName + " queue low water mark MamaStatus: " + e);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Queues will be created if the user has specified a number of threads to be
        /// used, otherwise the default queue will be used.
        /// </summary>
        private void createQueues()
        {
            // Only continue if the number of threads required is greater than 0
            if (m_numberThreads > 0)
            {
                m_queueGroup = new MamaQueueGroup(m_bridge, m_numberThreads);

                if ((m_highWaterMark > 0) || (m_lowWaterMark > 0))
                {
                    ListenerQueueCallback queueCallback = new ListenerQueueCallback();

                    // Install the callback on each queue
                    for (int index = 0; index < m_numberThreads; index++)
                    {
                        MamaQueue queue = m_queueGroup.getNextQueue();

                        string queueName = ("QUEUE " + index);
                        Console.WriteLine("Setting monitor for " + queueName);

                        // Install the callbacks
                        queue.setQueueMonitorCallbacks(queueCallback, queueName);

                        // Set the watermarks at which the callbacks are invoked
                        if (m_highWaterMark > 0)
                        {
                            queue.setHighWatermark(m_highWaterMark);
                        }

                        if (m_lowWaterMark > 0)
                        {
                            // Not supported on all middlewares.
                            queue.setLowWatermark(m_lowWaterMark);
                        }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            MamaTransport        transport    = null;
            MamaQueue            defaultQueue = null;
            MamaDictionary       dictionary   = null;
            CommandLineProcessor options      = new CommandLineProcessor(args);

            myQuietModeLevel = options.getQuietModeLevel();


            if (options.hasLogLevel())
            {
                myLogLevel = options.getLogLevel();
                Mama.enableLogging(myLogLevel);
            }

            try
            {
                //Initialize MAMA API
                myBridge = new MamaBridge(options.getMiddleware());
                Mama.open();
                transport = new MamaTransport();
                transport.create(options.getTransport(), myBridge);
                defaultQueue = Mama.getDefaultEventQueue(myBridge);
                myMamaSource = new MamaSource();
                //Get the Data dictionary.....
                MamaSource dictionarySource = new MamaSource();
                dictionarySource.symbolNamespace = "WOMBAT";
                dictionarySource.transport       = transport;
                dictionary = buildDataDictionary(transport, defaultQueue, dictionarySource);

                MamdaQuoteFields.setDictionary(dictionary, null);
                MamdaTradeFields.setDictionary(dictionary, null);
                MamdaCommonFields.setDictionary(dictionary, null);
                MamdaOrderBookFields.setDictionary(dictionary, null);

                myQueueGroup = new MamaQueueGroup(myBridge, options.getNumThreads());

                foreach (string symbol in options.getSymbolList())
                {
                    MamdaSubscription aSubscription = new MamdaSubscription();

                    MamdaBookAtomicListener aBookListener = new MamdaBookAtomicListener();
                    AtomicBookTicker        aTicker       = new AtomicBookTicker();

                    aBookListener.addBookHandler(aTicker);
                    aBookListener.addLevelHandler(aTicker);

                    if (options.getPrintEntries())
                    {   // Entries
                        aBookListener.addLevelEntryHandler(aTicker);
                    }

                    aSubscription.addMsgListener(aBookListener);
                    aSubscription.addStaleListener(aTicker);
                    aSubscription.addErrorListener(aTicker);
                    aSubscription.setType(mamaSubscriptionType.MAMA_SUBSC_TYPE_BOOK);

                    aSubscription.create(transport,
                                         myQueueGroup.getNextQueue(),
                                         options.getSource(),
                                         symbol,
                                         null);

                    mamdaSubscriptions.Add(aSubscription);
                }

                //Start dispatching on the default MAMA event queue
                Console.WriteLine("Hit Enter or Ctrl-C to exit.");
                Mama.start(myBridge);
                GC.KeepAlive(dictionary);
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Environment.Exit(1);
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            MamaTransport        transport = null;
            MamaQueue            defaultQueue = null;
            MamaDictionary       dictionary = null;
            CommandLineProcessor options = new CommandLineProcessor (args);
            myQuietModeLevel = options.getQuietModeLevel ();

            if (options.hasLogLevel ())
            {
                myLogLevel = options.getLogLevel ();
                Mama.enableLogging (myLogLevel);
            }

            try
            {
                //Initialize MAMA API
                myBridge = new MamaBridge (options.getMiddleware());
                Mama.open();
                transport = new MamaTransport();
                transport.create(options.getTransport(), myBridge);
                defaultQueue = Mama.getDefaultEventQueue(myBridge);
                myMamaSource = new MamaSource ();
                //Get the Data dictionary.....
                MamaSource dictionarySource = new MamaSource ();
                dictionarySource.symbolNamespace = "WOMBAT";
                dictionarySource.transport = transport;
                dictionary = buildDataDictionary(transport, defaultQueue, dictionarySource);

                MamdaQuoteFields.setDictionary (dictionary, null);
                MamdaTradeFields.setDictionary (dictionary, null);
                MamdaCommonFields.setDictionary (dictionary, null);
                MamdaOrderBookFields.setDictionary (dictionary, null);

                myQueueGroup = new MamaQueueGroup (myBridge, options.getNumThreads());

                foreach (string symbol in options.getSymbolList())
                {
                    MamdaSubscription  aSubscription = new MamdaSubscription ();

                    MamdaBookAtomicListener aBookListener = new MamdaBookAtomicListener();
                    AtomicBookTicker        aTicker       = new AtomicBookTicker ();

                    aBookListener.addBookHandler (aTicker);
                    aBookListener.addLevelHandler (aTicker);

                    if (options.getPrintEntries())
                    {   // Entries
                        aBookListener.addLevelEntryHandler (aTicker);
                    }

                    aSubscription.addMsgListener (aBookListener);
                    aSubscription.addStaleListener (aTicker);
                    aSubscription.addErrorListener (aTicker);
                    aSubscription.setType(mamaSubscriptionType.MAMA_SUBSC_TYPE_BOOK);

                    aSubscription.create (transport,
                                          myQueueGroup.getNextQueue(),
                                          options.getSource (),
                                          symbol,
                                          null);

                    mamdaSubscriptions.Add(aSubscription);
                }

                //Start dispatching on the default MAMA event queue
                Console.WriteLine("Hit Enter or Ctrl-C to exit.");
                Mama.start (myBridge);
                GC.KeepAlive(dictionary);
                Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Environment.Exit(1);
                }
        }