Esempio n. 1
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. 2
0
        public static void Main(string[] args)
        {
            parseCommandLine(args);

            try
            {
                initializeMama();
                buildDataDictionary();

                /* Subscribe to the symbol list */
                MamaSubscription symbolListSubscription = new MamaSubscription();
                symbolListSubscription.setSubscriptionType(mamaSubscriptionType.MAMA_SUBSC_TYPE_SYMBOL_LIST);
                symbolListSubscription.create(myDefaultQueue,
                                              symbolListSubscriptionCallback,
                                              mySource,
                                              "Symbol List",
                                              null);

                Console.WriteLine("Type CTRL-C to exit.");
                Mama.start(myBridge);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                Environment.Exit(1);
            }
        }
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
        static void Main(string[] args)
        {
            // Parse the command line options to override defaults
            String middlewareName     = "qpid";
            String transportName      = "sub";
            String sourceName         = "OM";
            String symbolName         = null;
            String dictionaryFile     = "/opt/openmama/data/dictionaries/data.dict";
            bool   requiresDictionary = true;
            bool   requiresInitial    = true;

            if (args.Length == 0)
            {
                usageAndExit();
            }

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-B":
                    requiresDictionary = false;
                    break;

                case "-d":
                    dictionaryFile = args[++i];
                    break;

                case "-I":
                    requiresInitial = false;
                    break;

                case "-m":
                    middlewareName = args[++i];
                    break;

                case "-s":
                    symbolName = args[++i];
                    break;

                case "-S":
                    sourceName = args[++i];
                    break;

                case "-t":
                    transportName = args[++i];
                    break;

                case "-v":
                    Mama.enableLogging(MamaLogLevel.MAMA_LOG_LEVEL_FINEST);
                    break;

                default:
                    usageAndExit();
                    break;
                }
            }

            // Symbol name is mandatory here, so error if it's null
            if (symbolName == null)
            {
                usageAndExit();
            }

            // Load the requested OpenMAMA middleware bridge (and default payload too)
            MamaBridge bridge = Mama.loadBridge(middlewareName);

            // Time to initialize OpenMAMA's underlying bridges with an "open"
            Mama.open();

            // Get default event queue from the bridge for testing
            MamaQueue queue = Mama.getDefaultEventQueue(bridge);

            // Set up the required transport on the specified bridge
            MamaTransport transport = new MamaTransport();

            transport.create(transportName, bridge);

            // Set up the data dictionary
            MamaDictionary dictionary = null;

            if (requiresDictionary)
            {
                dictionary = new MamaDictionary();
                dictionary.create(dictionaryFile);
            }

            // Set up the OpenMAMA source (symbol namespace)
            MamaSource source = new MamaSource();

            source.symbolNamespace = sourceName;
            source.transport       = transport;

            // Set up the event handlers for OpenMAMA
            SubscriptionEventHandler eventHandler = new SubscriptionEventHandler();

            eventHandler.mDictionary = dictionary;

            // Set up the OpenMAMA Subscription (interest in a topic)
            MamaSubscription subscription = new MamaSubscription();

            subscription.setRequiresInitial(requiresInitial);
            subscription.create(queue, eventHandler, source, symbolName);

            // Kick off OpenMAMA now (blocking call, non-blocking call also available)
            Mama.start(bridge);

            // Clean up connection on termination
            Mama.close();
        }