示例#1
0
            // the mCallback implementation
            private void onIterate(IntPtr sourceGroup, IntPtr source, uint weight, IntPtr closure)
            {
                MamaSource         ms = new MamaSource(source);
                MamaWeightedSource ws = new MamaWeightedSource(ms, weight);

                mItems.Add(ws);
                GC.KeepAlive(ms);
                GC.KeepAlive(ws);
            }
示例#2
0
        /// <summary>
        /// CLS compliant version of add(MamaSource, UInt32)
        /// </summary>
        public void add(
            MamaSource source,
            int weight)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (weight < 0)
            {
                throw new ArgumentOutOfRangeException("weight", weight);
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            add(source, (uint)weight);
        }
        /// <summary>
        /// Implements <see cref="ISourceManager.add(MamaSource)">ISourceManager.add(MamaSource)</see>
        /// </summary>
        public void add(MamaSource source)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            EnsurePeerCreated();

            int code = NativeMethods.mamaSourceManager_addSource(nativeHandle, source.NativeHandle);
            CheckResultCode(code);
            GC.KeepAlive(source);
        }
示例#4
0
        /// <summary>
        /// Add a mamaSource to the specified mGroup with the specified weighting and string name identifier.
        /// </summary>
        /// <param name="sourceName">The unique identifier for this source in this mGroup.</param>
        /// <param name="weight">The weighing to apply to the source being added.</param>
        /// <param name="source">The mamaSource being added to the mamaSourceGroup.</param>
        public void add(
            string sourceName,
            uint weight,
            MamaSource source)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (sourceName == null)
            {
                throw new ArgumentNullException("sourceName", sourceName);
            }
            if (source == null)
            {
                throw new ArgumentNullException("source", source);
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            EnsurePeerCreated();
            int code = NativeMethods.mamaSourceGroup_addSourceWithName(nativeHandle, source.NativeHandle, sourceName, weight);
            CheckResultCode(code);
            GC.KeepAlive(source);
        }
示例#5
0
	  /// <summary>
	  /// Create a data dictionary from a subscription
	  /// </summary>
		public void create(
			MamaQueue queue,
			MamaDictionaryCallback callback,
			MamaSource source,
			int retries,
			double timeout) 
		{
			mCallbackForwarder = new CallbackForwarder(this, callback);

			IntPtr queuePtr = queue != null ? queue.NativeHandle : IntPtr.Zero;
			IntPtr sourcePtr = source != null ? source.NativeHandle : IntPtr.Zero;

			mCallbacks = mCallbackForwarder.getMsgCallbacks();

			int code = NativeMethods.mama_createDictionary(ref nativeHandle, queuePtr, mCallbacks, sourcePtr, timeout, retries, nativeHandle);
			CheckResultCode(code);

			GC.KeepAlive(source);
			GC.KeepAlive(queue);
		}
示例#6
0
        /// <summary>
        /// Create a data dictionary from a subscription
        /// </summary>
        public void create(
            MamaQueue queue,
            MamaDictionaryCallback callback,
            MamaSource source,
            int retries,
            double timeout)
        {
            mCallbackForwarder = new CallbackForwarder(this, callback);

            IntPtr queuePtr  = queue != null ? queue.NativeHandle : IntPtr.Zero;
            IntPtr sourcePtr = source != null ? source.NativeHandle : IntPtr.Zero;

            mCallbacks = mCallbackForwarder.getMsgCallbacks();

            int code = NativeMethods.mama_createDictionary(ref nativeHandle, queuePtr, mCallbacks, sourcePtr, timeout, retries, nativeHandle);

            CheckResultCode(code);

            GC.KeepAlive(source);
            GC.KeepAlive(queue);
        }
        /// <summary>
        /// Set the parameters for a subscription that may be actually activated later.
        /// Activate the subscription using MamaSubscription.activate().
        /// </summary>
        /// <param name="queue">
        /// The mama queue.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <param name="source">
        /// The MamaSource identifying the publisher for this symbol.
        /// </param>
        /// <param name="symbol">
        /// The symbol for the listener.
        /// </param>
        /// <param name="closure">
        /// The caller supplied closure.
        /// </param>
        public void setup(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol, object closure)
        {
            // Verify that the subscription has been created
            EnsurePeerCreated();

            // Save arguments in member variables
            base.mClosure   = closure;
            base.mQueue     = queue;
            base.mTransport = source.transport;

            // Create the impl
            IntPtr impl = MamaSubscriptionImpl.Create(callback, closure, this);

            // Call into the native layer to setup the subscription
            CheckResultCode(SubscriptionNativeMethods.mamaSubscription_setup(
                                NativeHandle,
                                queue.NativeHandle,
                                ref MamaBasicSubscription.mCallbackDelegates,
                                source.NativeHandle,
                                symbol,
                                impl));
        }
 internal MamaWeightedSource(MamaSource source, uint weight)
 {
     mSource = source;
     mWeight = weight;
 }
示例#9
0
        private static MamaDictionary buildDataDictionary(
			MamaTransport transport,
			MamaQueue defaultQueue,
			MamaSource dictionarySource)
        {
            bool[] gotDict = new bool[] { false };
            MamaDictionaryCallback dictionaryCallback = new DictionaryCallback(gotDict);
            lock (dictionaryCallback)
            {
                MamaSubscription subscription = new MamaSubscription ();

                MamaDictionary dictionary = new MamaDictionary();
                dictionary.create(
                    defaultQueue,
                    dictionaryCallback,
                    dictionarySource,
                    3,
                    10);

                Mama.start(myBridge);
                if (!gotDict[0])
                {
                    if (!Monitor.TryEnter(dictionaryCallback, 30000))
                    {
                        Console.Error.WriteLine("Timed out waiting for dictionary.");
                        Environment.Exit(0);
                    }
                    Monitor.Exit(dictionaryCallback);
                }
                return dictionary;
            }
        }
示例#10
0
		/// <summary>
		/// Implements <see cref="ISourceManager.add(MamaSource)">ISourceManager.add(MamaSource)</see>
		/// </summary>
		public void add(MamaSource source)
		{
			Manager.add(source);
		}
示例#11
0
		/// <summary>
		/// Implements <see cref="ISourceManager.add(System.String, MamaSource)">ISourceManager.add(System.String, MamaSource)</see>
		/// </summary>
		public void add(string name, MamaSource source)
		{
			Manager.add(name, source);
		}
示例#12
0
 /// <summary>
 /// Set the parameters for a subscription that may be actually activated later.  
 /// Activate the subscription using MamaSubscription.activate().
 /// This overload passes a null value for the closure.
 /// </summary>
 /// <param name="queue">
 /// The mama queue.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="source">
 /// The MamaSource identifying the publisher for this symbol.</param>
 /// <param name="symbol">
 /// The symbol for the listener.
 /// </param>        
 public void setup(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol)
 {
     // Call the overload passing null for the closure
     setup(queue, callback, source, symbol, null);
 }
示例#13
0
		private static void initializeMama()
		{
			Mama.enableLogging(mamaLogLevel);

			try
			{
				myBridge = Mama.loadBridge (myMiddleware);
				/* Always the first API method called. Initialized internal API
				 * state*/
				Mama.open ();
				myDefaultQueue = Mama.getDefaultEventQueue (myBridge);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.ToString());
				Console.WriteLine("Failed to initialize MAMA");
				Environment.Exit (1);
			}

			transport = new MamaTransport ();
			/* The name specified here is the name identifying properties in the
			 * mama.properties file*/
			transport.create (transportName, myBridge);

			if (myDictTportName != null)
			{
				myDictTransport = new MamaTransport ();
				myDictTransport.create (myDictTportName, myBridge);
			}
			else 
			{
				myDictTransport = transport;
			}

			/*MamaSource for all subscriptions*/
			mySource     = new MamaSource ();
			mySource.transport = transport;
			mySource.symbolNamespace = mySymbolNamespace;

			/*MamaSource for dictionary subscription*/
			myDictSource = new MamaSource ();
			myDictSource.transport = myDictTransport;
			myDictSource.symbolNamespace = dictSource;
		}
示例#14
0
		/// <summary>
		/// Add a mamaSource to the specified mGroup with the specified weighting.
		/// </summary>
		/// <remarks>The source id will be used by the mGroup to uniquely identify the source.</remarks>
		/// <param name="source">The mamaSource being added to the mamaSourceGroup.</param>
		/// <param name="weight">The weighing to apply to the source being added.</param>
		public void add(
			MamaSource source, 
			uint weight)
		{
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
			if (source == null)
			{
				throw new ArgumentNullException("source", source);
			}
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
			EnsurePeerCreated();
			int code = NativeMethods.mamaSourceGroup_addSource(nativeHandle, source.NativeHandle, weight);
			CheckResultCode(code);
			GC.KeepAlive(source);
		}
示例#15
0
		internal MamaWeightedSource(MamaSource source, uint weight)
		{
			mSource = source;
			mWeight = weight;
		}
示例#16
0
        public static void Main(string[] args)
        {
            MamaTransport        transport    = null;
            MamaQueue            defaultQueue = null;
            MamaDictionary       dictionary   = null;
            CommandLineProcessor options      = new CommandLineProcessor(args);
            double               throttleRate = options.getThrottleRate();

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

            if ((throttleRate > 100.0) || (throttleRate <= 0.0))
            {
                throttleRate = 100.0;
            }

            try
            {
                // Initialize MAMDA
                myBridge = new MamaBridge(options.getMiddleware());
                Mama.open();

                transport = new MamaTransport();
                transport.create(options.getTransport(), myBridge);
                defaultQueue = Mama.getDefaultEventQueue(myBridge);
                //Get the Data dictionary.....
                MamaSource dictionarySource = new MamaSource();
                dictionarySource.symbolNamespace = options.getDictSource();
                dictionarySource.transport = transport;
                dictionary = buildDataDictionary(transport, defaultQueue, dictionarySource);

                //Initialise the dictionary and fields
                MamdaCommonFields.setDictionary(dictionary, null);
                MamdaQuoteFields.setDictionary(dictionary, null);
                MamdaTradeFields.setDictionary(dictionary, null);

                foreach (string symbol in options.getSymbolList())
                {
                    MamdaSubscription aSubscription = new MamdaSubscription();
                    aSubscription.setType(mamaSubscriptionType.MAMA_SUBSC_TYPE_GROUP);
                    aSubscription.create(
                        transport,
                        defaultQueue,
                        options.getSource(),
                        symbol,
                        null);

                    /* For each subscription a MamdaMultiParticipantManager is
                    * added as the message listener. The callbacks on the
                    * MamdaMultiPartHandler will be invokes as new group members
                    * become available.*/
                    MamdaMultiParticipantManager multiPartManager =
                        new MamdaMultiParticipantManager(symbol);
                    multiPartManager.addHandler(new MultiPartHandler());

                    aSubscription.addMsgListener(multiPartManager);

                    aSubscription.activate();

                   mamdaSubscriptions.Add(aSubscription);
                }

                Mama.start(myBridge);
                GC.KeepAlive(dictionary);
                Console.WriteLine("Press ENTER or Ctrl-C to quit...");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Environment.Exit(1);
            }
        }
示例#17
0
 /// <summary>
 /// Implements <see cref="ISourceManager.add(System.String, MamaSource)">ISourceManager.add(System.String, MamaSource)</see>
 /// </summary>
 public void add(string name, MamaSource source)
 {
     Manager.add(name, source);
 }
示例#18
0
        /// <summary>
        /// This function will clean up all the objects initialised before Mama.start is called.
        /// </summary>
        private void uninitializeMama()
        {
            if (m_source != null)
            {
                m_source.destroy();
                m_source = null;
            }

            if (m_dictionary != null)
            {
                m_dictionary.Dispose();
                m_dictionary = null;
            }

            if (m_queueGroup != null)
            {
                m_queueGroup.destroyWait();
                m_queueGroup = null;
            }

            if (m_transport != null)
            {
                m_transport.destroy();
                m_transport = null;
            }

            Mama.close();
        }
示例#19
0
        /// <summary>
        /// Creates the source required to establish market data subscriptions.
        /// </summary>
        private void createSource()
        {
            // Allocate a new source object
            m_source = new MamaSource();

            // Set the source name and main transport
            m_source.symbolNamespace = m_sourceName;
            m_source.transport       = m_transport;
        }
示例#20
0
        /// <summary>
        /// This function will create the dictionary.
        /// </summary>
        private void createDictionary()
        {
            if (m_downloadDictionary)
            {
                using (MamaSource dictionarySource = new MamaSource())
                {
                    /* If a dictionary transport has been specified then a new one must be created otherwise
                     * the main transport will be re-used.
                     */
                    MamaTransport dictionaryTransport = null;
                    try
                    {
                        if((m_dictionaryTransportName == null) || (m_dictionaryTransportName == string.Empty))
                        {
                            dictionarySource.transport = m_transport;
                        }
                        else
                        {
                            dictionaryTransport = new MamaTransport();
                            dictionaryTransport.create(m_dictionaryTransportName, m_bridge);

                            dictionarySource.transport = dictionaryTransport;
                        }

                        // The symbol namespace must also be set
                        dictionarySource.symbolNamespace = m_dictionarySourceName;

                        // Instantiate a callback class
                        ListenerDictionaryCallback dictionaryCallback = new ListenerDictionaryCallback(m_bridge);

                        // Create the actual dictionary object using the default queue
                        m_dictionary = new MamaDictionary();
                        m_dictionary.create(m_defaultQueue, dictionaryCallback, dictionarySource, 3, 10.0);

                        // Start the bridge, this will block until the dictionary is downloaded or something goes wrong
                        Mama.start(m_bridge);

                        // If something went wrong then throw an exception
                        if (!dictionaryCallback.DictionaryComplete)
                        {
                            throw new ApplicationException("Can't create dictionary.");
                        }
                    }

                    finally
                    {
                        if (dictionaryTransport != null)
                        {
                            dictionaryTransport.destroy();
                        }
                    }
                }
            }
        }
示例#21
0
			// the mCallback implementation
			private void onIterate(IntPtr sourceGroup, IntPtr source, uint weight, IntPtr closure)
			{
				MamaSource ms = new MamaSource(source);
				MamaWeightedSource ws = new MamaWeightedSource(ms, weight);
				mItems.Add(ws);
				GC.KeepAlive(ms);
				GC.KeepAlive(ws);
			}
示例#22
0
		/// <summary>
		/// CLS compliant version of add(System.String, UInt32, MamaSource)
		/// </summary>
		public void add(
			string sourceName,
			int weight,
			MamaSource source)
		{
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
			if (weight < 0)
			{
				throw new ArgumentOutOfRangeException("weight", weight);
			}
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
			add(sourceName, (uint)weight, source);
		}
示例#23
0
 /// <summary>
 /// Implements <see cref="ISourceManager.add(MamaSource)">ISourceManager.add(MamaSource)</see>
 /// </summary>
 public void add(MamaSource source)
 {
     Manager.add(source);
 }
示例#24
0
 /// <summary>
 /// Set the parameters for a subscription that may be actually activated later.
 /// Activate the subscription using MamaSubscription.activate().
 /// This overload passes a null value for the closure.
 /// </summary>
 /// <param name="queue">
 /// The mama queue.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="source">
 /// The MamaSource identifying the publisher for this symbol.</param>
 /// <param name="symbol">
 /// The symbol for the listener.
 /// </param>
 public void setup(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol)
 {
     // Call the overload passing null for the closure
     setup(queue, callback, source, symbol, null);
 }
示例#25
0
 /// <summary>
 /// Set up and activate a subscriber using the throttle queue. This
 /// method is equivalent to calling setup() followed by activate().
 /// </summary>
 /// <param name="queue">
 /// The mama queue.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="source">
 /// The MamaSource identifying the publisher for this symbol.
 /// </param>
 /// <param name="symbol">
 /// The symbol for the listener.
 /// </param>
 public void create(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol)
 {
     // Call the overload with a null closure
     create(queue, callback, source, symbol, null);
 }
示例#26
0
        private void initializeMama()
        {
            mamaBridge = Mama.loadBridge(mamaMiddlewareName);

            Console.WriteLine(Mama.getVersion(mamaBridge));

            Mama.open();

            if (mamaHighWaterMark > 0 || mamaLowWaterMark > 0)
            {
                if (mamaHighWaterMark > 0)
                {
                    Mama.setDefaultQueueHighWatermark(mamaHighWaterMark);
                }

                if (mamaLowWaterMark > 0)
                {
                    try
                    {
                        Mama.setDefaultQueueLowWatermark(mamaLowWaterMark);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Could not set default queue low water mark MamaStatus: " + e);
                    }
                }
            }

            // create the transport
            mamaTransport = new MamaTransport();

            mamaTransport.setTransportCallback(this);

            // the default throttle rate is 500 msg/sec
            if (mamaThrottle != -1)
            {
                mamaTransport.setOutboundThrottle(MamaTransport.MamaThrottleInstance.MAMA_THROTTLE_DEFAULT, mamaThrottle);
            }

            // the default recap throttle rate is 250 msg/sec
            if (mamaRecapThrottle != -1)
            {
                mamaTransport.setOutboundThrottle(MamaTransport.MamaThrottleInstance.MAMA_THROTTLE_RECAP, mamaRecapThrottle);
            }

            mamaTransport.create(mamaTransportName, mamaBridge);

            // create default queue and, if required, queue group
            createQueues();

            mamaDictionarySource = new MamaSource();
            mamaDictionarySource.symbolNamespace = mamaDictionarySourceName;
            mamaDictionarySource.transport = mamaTransport;

            // download dictionary
            mamaDictionary = new MamaDictionary();

            mamaDictionary.create(
                mamaDefaultQueue,
                this,
                mamaDictionarySource,
                3,
                10.0f);

            loadSymbolMap();

            Mama.start(mamaBridge);

            if (!dictionaryComplete)
            {
                throw new Exception("Can't create dictionary.");
            }

        }
示例#27
0
 /// <summary>
 /// Set up and activate a subscriber using the throttle queue. This
 /// method is equivalent to calling setup() followed by activate().
 /// </summary>
 /// <param name="queue">
 /// The mama queue.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="source">
 /// The MamaSource identifying the publisher for this symbol.
 /// </param>
 /// <param name="symbol">
 /// The symbol for the listener.
 /// </param>
 public void create(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol)
 {
     // Call the overload with a null closure
     create(queue, callback, source, symbol, null);
 }
示例#28
0
        /// <summary>
		/// Set up and activate a subscriber using the throttle queue. This
		/// method is equivalent to calling setup() followed by activate().
		/// </summary>
		/// <param name="queue">
        /// The mama queue.
        /// </param>
		/// <param name="callback">
        /// The callback.
        /// </param>
		/// <param name="source">
        /// The MamaSource identifying the publisher for this symbol.
        /// </param>
		/// <param name="symbol">
        /// The symbol for the listener.
        /// </param>
		/// <param name="closure">
        /// The caller supplied closure.
        /// </param>
		public void create(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol, object closure)
		{
			// This is equivalent to calling setup then activate
            setup(queue, callback, source, symbol, closure);
            activate();
		}
示例#29
0
		/// <summary>
		/// Implements <see cref="ISourceManager.add(System.String, MamaSource)">ISourceManager.add(System.String, MamaSource)</see>
		/// </summary>
		public void add(string name, MamaSource source)
		{
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
			EnsurePeerCreated();

			int code = NativeMethods.mamaSourceManager_addSourceWithName(nativeHandle, source.NativeHandle, name);
			CheckResultCode(code);
			GC.KeepAlive(source);
		}
示例#30
0
 /// <summary>
 /// Set up and activate a subscriber using the throttle queue. This
 /// method is equivalent to calling setup() followed by activate().
 /// </summary>
 /// <param name="queue">
 /// The mama queue.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <param name="source">
 /// The MamaSource identifying the publisher for this symbol.
 /// </param>
 /// <param name="symbol">
 /// The symbol for the listener.
 /// </param>
 /// <param name="closure">
 /// The caller supplied closure.
 /// </param>
 public void create(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol, object closure)
 {
     // This is equivalent to calling setup then activate
     setup(queue, callback, source, symbol, closure);
     activate();
 }
示例#31
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]);
            }
        }
示例#32
0
		/// <summary>
        /// Set the parameters for a subscription that may be actually activated later.  
        /// Activate the subscription using MamaSubscription.activate().
        /// </summary>
        /// <param name="queue">
        /// The mama queue.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <param name="source">
        /// The MamaSource identifying the publisher for this symbol.
        /// </param>
        /// <param name="symbol">
        /// The symbol for the listener.
        /// </param>
        /// <param name="closure">
        /// The caller supplied closure.
        /// </param>
        public void setup(MamaQueue queue, MamaSubscriptionCallback callback, MamaSource source, string symbol, object closure)
        {
            // Verify that the subscription has been created
            EnsurePeerCreated();

            // Save arguments in member variables
            base.mClosure      = closure;
            base.mQueue        = queue;
            base.mTransport    = source.transport;

            // Create the impl
            IntPtr impl = MamaSubscriptionImpl.Create(callback, closure, this);

            // Call into the native layer to setup the subscription
            CheckResultCode(SubscriptionNativeMethods.mamaSubscription_setup(
                NativeHandle,
                queue.NativeHandle,
                ref MamaBasicSubscription.mCallbackDelegates,
                source.NativeHandle,
                symbol,
                impl));
        }