Exemple #1
0
        private void createSubscriber(MamaBridge bridge)
        {
            MamaSubscription mamaSubscription = new MamaSubscription();
            MamaTransport    mamaTransport    = new MamaTransport();
            MamaQueue        mamaDefaultQueue = Mama.getDefaultEventQueue(bridge);
            Dispatcher       dispatcher       = new Dispatcher(bridge);

            mamaTransport = new MamaTransport();
            mamaTransport.setTransportCallback(this);
            mamaTransport.create(transportName, bridge);

            mamaSubscription = new MamaSubscription();
            mamaSubscription.createBasic(
                mamaTransport,
                mamaDefaultQueue,
                this,                   // callback
                topicName);

            Console.WriteLine("Starting mama...");

            mamaSubscriptions.Add(mamaSubscription);
            mamaTransports.Add(mamaTransport);

            Thread startThread = new Thread(new ThreadStart(dispatcher.dispatch));

            startThread.Start();
        }
        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);
        }
        private MamaSubscriberCS(string[] args)
        {
            try
            {
                if (parseCommandLine(args))
                {
                    mamaBridge = Mama.loadBridge(middlewareName);

                    Mama.open();

                    mamaTransport = new MamaTransport();
                    mamaTransport.setTransportCallback(this);
                    mamaTransport.create(transportName, mamaBridge);

                    mamaDefaultQueue = Mama.getDefaultEventQueue(mamaBridge);

                    mamaSubscription = new MamaSubscription();
                    mamaSubscription.createBasic(
                        mamaTransport,
                        mamaDefaultQueue,
                        this,   // callback
                        topicName);

                    Console.WriteLine("Starting mama...");
                    Mama.start(mamaBridge);

                    // Prevent over-enthusiastic GC from reclaiming transport object
                    GC.KeepAlive(mamaTransport);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #4
0
 public void Enqueue(MamaQueue mamaQueue, object closure)
 {
     lock (queue)
     {
         Monitor.Pulse(queue);
     }
 }
Exemple #5
0
        /// <summary>
        /// Set a queue for transport callbacks (transport and topic).
        /// If this is not set the default queue will be used.
        /// </summary>
        public void setTransportCallbackQueue(MamaQueue queue)
        {
            int code = NativeMethods.mamaTransport_setTransportCallbackQueue(nativeHandle, queue.NativeHandle);

            CheckResultCode(code);
            GC.KeepAlive(queue);
        }
Exemple #6
0
        /// <summary>
        /// Create an IO handler.
        /// </summary>
        /// <remarks>
        /// If the underlying infrastructure does not support the requested mamaIoType,
        /// create throws MamaException(MAMA_STATUS_UNSUPPORTED_IO_TYPE). For example,
        /// RV only supports READ, WRITE, and EXCEPT. LBM supports all types except ERROR
        /// </remarks>
        /// <param name="queue">The event queue for the io events. null specifies the
        /// Mama default queue</param>
        /// <param name="action">The callback to be invoked when an event occurs.</param>
        /// <param name="descriptor">Wait for IO on this descriptor.</param>
        /// <param name="ioType">Wait for occurences of this type.</param>
        /// <param name="closure">The closure that is passed to the callback.</param>
        public void create(
            MamaQueue queue,
            MamaIoCallback action,
            uint descriptor,
            mamaIoType ioType,
            object closure)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            this.callback      = action;
            this.closureObject = closure;

            IntPtr queueHandle = queue != null ? queue.NativeHandle : IntPtr.Zero;
            int    code        = NativeMethods.mamaIo_create(
                ref nativeHandle,
                queueHandle,
                descriptor,
                mIoDelegate,
                (int)ioType,
                IntPtr.Zero);
            CheckResultCode(code);

            GC.KeepAlive(queue);
        }
        private MamaSubscriberCS(string[] args)
        {
            try
            {
                if (parseCommandLine(args))
                {
                    mamaBridge = Mama.loadBridge(middlewareName);

                    Mama.open();

                    mamaTransport = new MamaTransport();
                    mamaTransport.setTransportCallback(this);
                    mamaTransport.create(transportName, mamaBridge);

                    mamaDefaultQueue = Mama.getDefaultEventQueue(mamaBridge);

                    mamaSubscription = new MamaSubscription();
                    mamaSubscription.createBasic(
                        mamaTransport,
                        mamaDefaultQueue,
                        this,   // callback
                        topicName);

                    Console.WriteLine("Starting mama...");
                    Mama.start(mamaBridge);

                    // Prevent over-enthusiastic GC from reclaiming transport object
                    GC.KeepAlive(mamaTransport);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Create a repeating timer. Since the MamaTimer relies on the timer mechanism of the
        /// underlying middleware, the resolution of the timer is also dependent on the
        /// middleware. Consult your middleware documentation for details.
        /// The callback is invoked repeatedly at the specified interval until the timer
        /// is destroyed.
        /// A null value for the queue uses the default mama queue.
        /// </summary>
        /// <param name="queue">
        /// The queue from which the timer event will be dispatched.
        /// </param>
        /// <param name="action">
        /// The callback to be invoked after the interval
        /// </param>
        /// <param name="interval">
        /// The interval in seconds.
        /// </param>
        /// <param name="closure">
        /// Closure data for timer.
        /// </param>
        public void create(MamaQueue queue, MamaTimerCallback action, double interval, object closure)
        {
            // Check the arguments
            if (null == queue)
            {
                throw new ArgumentNullException("queue");
            }

            if (null == action)
            {
                throw new ArgumentNullException("action");
            }

            // Create the impl
            IntPtr impl = MamaTimerImpl.Create(action, closure, this);

            /* Create the timer, register for the destroy callback regardless if the client wants it or not,
             * this is to allow clean-up to be done whenever the timer has been fully destroyed.
             */
            IntPtr nativeTimer = IntPtr.Zero;

            CheckResultCode(NativeMethods.mamaTimer_create2(ref nativeTimer, queue.NativeHandle, mTickDelegate, mDestroyDelegate, interval, impl));

            // Save the native timer in the member variable
            NativeHandle = nativeTimer;
        }
Exemple #9
0
 public void init()
 {
     myDefaultQueue = Mama.getDefaultEventQueue (myBridge);
     myTimer.create (myDefaultQueue, this, 2.0, null);  // two seconds
     myFtMember.create();
     myFtMember.setup (myDefaultQueue, this, myTransport, myGroup, myWeight, 1.0, 6.0, null);
     myFtMember.activate();
 }
Exemple #10
0
 /// <summary>
 /// CLS compliant version of create
 /// <see cref="create(MamaQueue, MamaIoCallback, uint, mamaIoType, System.Object)"/>
 /// </summary>
 public void create(
     MamaQueue queue,
     MamaIoCallback action,
     long descriptor,
     mamaIoType ioType)
 {
     create(queue, action, descriptor, ioType, null);
 }
Exemple #11
0
            /* ************************************************************** */
            #region Construction and Finalization

            /// <summary>
            /// Construct initialises all member variables including createing the
            /// thread.
            /// </summary>
            /// <param name="bridge">
            /// The MAMA bridge.
            /// </param>
            public MamaQueueThread(MamaBridge bridge)
            {
                // Create the queue
                mQueue = new MamaQueue(bridge);

                // Start dispatching straight away
                start();
            }
Exemple #12
0
            /// <summary>
            /// Construct and start a thread for the given queue
            /// </summary>
            /// <param name="queue"></param>
            public MamaQueueThread(MamaQueue queue) 
            {
                this.queue = queue;
                
                queue.setEnqueueCallback(this);

                workerThread = new Thread(new ThreadStart(this.run));
                workerThread.Name = "MamaQueueManager:"+queue.GetHashCode();
                workerThread.Start();
            }
Exemple #13
0
            /// <summary>
            /// Construct and start a thread for the given queue
            /// </summary>
            /// <param name="queue"></param>
            public MamaQueueThread(MamaQueue queue)
            {
                this.queue = queue;

                queue.setEnqueueCallback(this);

                workerThread      = new Thread(new ThreadStart(this.run));
                workerThread.Name = "MamaQueueManager:" + queue.GetHashCode();
                workerThread.Start();
            }
Exemple #14
0
            /// <summary>
            /// Constructor initialises all member variables.
            /// </summary>
            /// <param name="callback">
            /// The callback object that will be invoked whenever an event is processed.
            /// </param>
            /// <param name="closure">
            /// Utility object.
            /// </param>
            /// <param name="sender">
            /// The queue.
            /// </param>
            public EnqueueEventForwarder(MamaQueueEventCallback callback, object closure, MamaQueue sender)
            {
                // Save arguments in member variables.
                mCallback = callback;
                mClosure  = closure;
                mSender   = sender;

                // Save a reference to this object in the static list
                mIndex = AddForwarder(this);
            }
        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);
        }
Exemple #16
0
            /* ************************************************************** */
            #region Internal Operations

            /// <summary>
            /// Destroy while waiting for the queue to shutdown complete, this is equivalent to disposing
            /// the class.
            /// </summary>
            internal void destroyWait()
            {
                // Stop dispatching the queue, this will not return until the thread has shut down
                stop();

                // Destroy the queue, but wait until it has shutdown
                mQueue.destroyWait();
                mQueue = null;

                // Supress the finalizer as we have effectively disposed the class
                GC.SuppressFinalize(this);
            }
Exemple #17
0
            /* ************************************************************** */
            #region Private Operations

            /// <summary>
            /// Dispose(bool disposing) executes in two distinct scenarios.
            /// If disposing equals true, the method has been called directly
            /// or indirectly by a user's code. Managed and unmanaged resources
            /// can be disposed.
            /// If disposing equals false, the method has been called by the
            /// runtime from inside the finalizer and you should not reference
            /// other objects. Only unmanaged resources can be disposed.
            /// </summary>
            /// <param name="disposing">
            /// True if managed resources can be disposed.
            /// </param>
            private void Dispose(bool disposing)
            {
                // Dispose managed objects
                if (disposing)
                {
                    // Stop dispatching the queue, this will not return until the thread has shut down
                    stop();

                    // Destroy the queue
                    mQueue.Dispose();
                    mQueue = null;
                }
            }
        /// <summary>
        /// Destroy the subscription.
        /// This function is another option to destroy the resources associated with the subscription
        /// It will schedule the destroy() of the subscription on the queue on which it dispatches.
        /// This function does not free the memory associated with the subscription.
        /// create() can be called again after this function has
        /// been called.
        /// After the Subscription is effectively destroyed, the OnDestroy callback will be triggered
        /// for it.
        ///
        /// This function can be called from any thread, as opposed to destroy().
        /// </summary>
        public void destroyEx()
        {
            // Verify that the native subscription has been created
            EnsurePeerCreated();

            // Clear the member variables
            mClosure   = null;
            mQueue     = null;
            mTransport = null;

            // Call the native function
            CheckResultCode(NativeMethods.mamaSubscription_destroyEx(NativeHandle));
        }
Exemple #19
0
 /// <summary>
 /// Create and activate a subscription.
 /// Any properties for the subscription should be set prior to
 /// calling this method.
 /// </summary>
 /// <param name="transport"></param>
 /// <param name="queue"></param>
 /// <param name="source"></param>
 /// <param name="symbol"></param>
 /// <param name="closure"></param>
 public void create(
     MamaTransport transport,
     MamaQueue queue,
     string source,
     string symbol,
     object closure)
 {
     setSource(source);
     setSymbol(symbol);
     setTransport(transport);
     setQueue(queue);
     setClosure(closure);
     activate();
 }
Exemple #20
0
		/// <summary>
		/// Create and activate a subscription.
		/// Any properties for the subscription should be set prior to
		/// calling this method.
		/// </summary>
		/// <param name="transport"></param>
		/// <param name="queue"></param>
		/// <param name="source"></param>
		/// <param name="symbol"></param>
		/// <param name="closure"></param>
		public void create(
			MamaTransport         transport,
			MamaQueue             queue,
			string                source,
			string                symbol,
			object                closure)
		{
			setSource(source);
			setSymbol(symbol);
			setTransport(transport);
			setQueue(queue);
			setClosure(closure);
			activate();
		}
Exemple #21
0
        /// <summary>
        /// CLS compliant version of create
        /// <see cref="create(MamaQueue, MamaIoCallback, uint, mamaIoType, System.Object)"/>
        /// </summary>
        public void create(
            MamaQueue queue,
            MamaIoCallback action,
            long descriptor,
            mamaIoType ioType,
            object closure)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (descriptor < 0 || descriptor > UInt32.MaxValue)
            {
                throw new ArgumentOutOfRangeException("descriptor", descriptor);
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            create(queue, action, (uint)descriptor, ioType, closure);
        }
Exemple #22
0
        /// <summary>
        /// Create a mama publisher for the corresponding transport. If the transport
        /// is a marketdata transport, as opposed to a "basic" transport, the topic
        /// corresponds to the symbol. For a basic transport, the source and root get
        /// ignored.
        /// </summary>
        /// <param name="transport">The transport.</param>
        /// <param name="topic">Symbol on which to publish.</param>
        /// <param name="source">The source for market data publishers. (e.g. source.symbol)</param>
        /// <param name="root">The root for market data publishers. Used internally.</param>
        public void createWithCallbacks(
            MamaTransport transport,
            MamaQueue queue,
            MamaPublisherCallback callback,
            Object closure,
            string topic,
            string source,
            string root)
        {
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (nativeHandle != IntPtr.Zero)
            {
                throw new InvalidOperationException("MamaPublisher already created");
            }
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            mCallback = callback;

            GCHandle handle = GCHandle.Alloc(this);

            int code = NativeMethods.mamaPublisher_createWithCallbacks(
                ref nativeHandle,
                transport.NativeHandle,
                queue.NativeHandle,
                topic, source, root,
                ref mCallbackDelegates,
                (IntPtr)handle);
            CheckResultCode(code);

            GC.KeepAlive(transport);
            GC.KeepAlive(queue);
            GC.KeepAlive(callback);
        }
Exemple #23
0
 /// <summary>
 /// </summary>
 /// <param name="transport"></param>
 /// <param name="queue"></param>
 /// <param name="handler"></param>
 /// <param name="source"></param>
 /// <param name="symbol"></param>
 /// <param name="intervalSeconds"></param>
 public MamdaOrderBookChecker(
     MamaTransport transport,
     MamaQueue queue,
     MamdaOrderBookCheckerHandler handler,
     string source,
     string symbol,
     double intervalSeconds)
 {
     mSnapShotmHandler = new SnapShotChecker(this);
     mRealTimeSubsc    = new MamdaSubscription();
     mRealTimeListener = new MamdaOrderBookListener();
     mHandler          = handler;
     mQueue            = queue;
     mIntervalSecs     = intervalSeconds;
     mRandomTimerFired = false;
     mRealTimeSubsc.setType(mamaSubscriptionType.MAMA_SUBSC_TYPE_BOOK);
     mRealTimeSubsc.create(transport, queue, source, symbol, null);
     mRealTimeSubsc.addMsgListener(mRealTimeListener);
     init();
 }
Exemple #24
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>
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="queue"></param>
        /// <param name="handler"></param>
        /// <param name="source"></param>
        /// <param name="symbol"></param>
        /// <param name="intervalSeconds"></param>
        public MamdaOrderBookChecker(
			MamaTransport transport,
			MamaQueue queue,
			MamdaOrderBookCheckerHandler handler,
			string source,
			string symbol,
			double intervalSeconds)
        {
            mSnapShotmHandler = new SnapShotChecker(this);
            mRealTimeSubsc = new MamdaSubscription();
            mRealTimeListener = new MamdaOrderBookListener();
            mHandler = handler;
            mQueue = queue;
            mIntervalSecs = intervalSeconds;
            mRandomTimerFired = false;
            mRealTimeSubsc.setType(mamaSubscriptionType.MAMA_SUBSC_TYPE_BOOK);
            mRealTimeSubsc.create(transport, queue, source, symbol, null);
            mRealTimeSubsc.addMsgListener(mRealTimeListener);
            init();
        }
Exemple #26
0
        /* ************************************************************** */
        #region Public Functions

        /// <summary>
        /// Creates an inbox and stores at the address specified by the calling client.
        /// </summary>
        /// <param name="transport">
        /// The mamaTransport being used.
        /// </param>
        /// <param name="queue">
        /// Optional mamaQueue. Will use default queue if null.
        /// </param>
        /// <param name="callback">
        /// A callback interface invoked in response to a p2p message being received or when an error is
        /// encountered during p2p messaging.
        /// </param>
        /// <param name="closure">
        /// User supplied data
        /// </param>
        public void create(MamaTransport transport, MamaQueue queue, MamaInboxCallback callback, object closure)
        {
            // Check the arguments
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            // Save the clousre in the member variable
            mClosure = closure;

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

            /* Create the inbox, register for the destroy callback regardless if the client wants it or not,
             * this is to allow clean-up to be done whenever the inbox has been fully destroyed.
             */
            IntPtr nativeInbox = IntPtr.Zero;

            CheckResultCode(NativeMethods.mamaInbox_create2(
                                ref nativeInbox,
                                transport.NativeHandle,
                                queue.NativeHandle,
                                mMsgDelegate,
                                mErrorDelegate,
                                mDestroyDelegate,
                                impl));

            // Save the native timer in the member variable
            NativeHandle = nativeInbox;
        }
 /// <summary>
 /// Set up the object. This is only an
 /// initialization function. In order to actually start the fault
 /// tolerance monitoring, use <see cref="MamaFtMember.activate"/>
 /// </summary>
 public new void setup(
     MamaQueue queue,
     MamaFtMemberCallback callback,
     MamaTransport transport,
     string groupName,
     uint weight,
     double heartbeatInterval,
     double timeoutInterval,
     object closure)
 {
     setupFtType(
         mamaFtType.MAMA_FT_TYPE_BRIDGE,
         queue,
         callback,
         transport,
         groupName,
         weight,
         heartbeatInterval,
         timeoutInterval,
         closure);
 }
Exemple #28
0
        public void Setup()
        {
            // Load the wmw bridge
            m_bridge = Mama.loadBridge("lbm");

            // Create the mama queue
            m_queue = new MamaQueue(m_bridge);

            // Create the auto reset event
            m_event = new AutoResetEvent(false);

            // Spin a thread to dispatch events
            m_dispatcher = new Thread(new ThreadStart(this.DispatcherThread));

            // Reset all other member variables
            m_closure = null;
            m_numberEvents = 0;

            // Start the thread
            m_dispatcher.Start();
        }
        /// <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));
        }
        protected void setupFtType(
            mamaFtType ftType,
            MamaQueue queue,
            MamaFtMemberCallback callback,
            MamaTransport transport,
            string groupName,
            uint weight,
            double heartbeatInterval,
            double timeoutInterval,
            object closure)
        {
            EnsurePeerCreated();
            if (callback == null)
            {
                mCallbackForwarder = null;
                mCallback          = null;
            }
            else
            {
                mCallbackForwarder = new CallbackForwarder(this, callback, closure);
                mCallback          = new CallbackForwarder.FtMemberCallbackDelegate(mCallbackForwarder.OnFtStateChange);
            }
            IntPtr queueHandle     = queue != null ? queue.NativeHandle : IntPtr.Zero;
            IntPtr transportHandle = transport != null ? transport.NativeHandle : IntPtr.Zero;
            int    code            = NativeMethods.mamaFtMember_setup(
                nativeHandle,
                mamaFtType.MAMA_FT_TYPE_MULTICAST,
                queueHandle,
                mCallback,
                transportHandle,
                groupName,
                weight,
                heartbeatInterval,
                timeoutInterval,
                null);

            CheckResultCode(code);
        }
Exemple #32
0
            /// <summary>
            /// Destroy this object
            /// </summary>
            public void destroy()
            {
                lock (this)
                {
                    if (queue != null)
                    {
                        RequestToStop = true;
                        lock (queue)
                        {
                            Monitor.Pulse(queue);
                        }

                        if (!Monitor.Wait(this, shutdownTimeout))
                        {
                            workerThread.Abort();
                            workerThread.Join();
                        }
                    }

                    queue.destroy();
                    queue = null;
                }
            }
Exemple #33
0
        /// <summary>
        /// This function will return the next queue since it was called last or the first queue in
        /// the group if this is the first time that it has been called.
        /// Note that when all queues have been returned it will go back to the start of the array.
        /// </summary>
        public MamaQueue getNextQueue()
        {
            // Returns
            MamaQueue ret = null;

            lock (this)
            {
                // Only continue if the array of threads is valid
                if (mQueueThreads != null)
                {
                    // If the queue index has reached the end of the array then go back to the start
                    if (mNextQueueIndex >= mQueueThreads.Length)
                    {
                        mNextQueueIndex = 0;
                    }

                    // Get the queue at this index and increment.
                    ret = mQueueThreads[mNextQueueIndex++].Queue;
                }
            }

            return(ret);
        }
Exemple #34
0
		protected void setupFtType(
			mamaFtType ftType,
			MamaQueue queue,
			MamaFtMemberCallback callback,
			MamaTransport transport,
			string groupName,
			uint weight,
			double heartbeatInterval,
			double timeoutInterval,
			object closure)
		{
			EnsurePeerCreated();
			if (callback == null)
			{
				mCallbackForwarder = null;
				mCallback = null;
			}
			else
			{
				mCallbackForwarder = new CallbackForwarder(this, callback, closure);
				mCallback = new CallbackForwarder.FtMemberCallbackDelegate(mCallbackForwarder.OnFtStateChange);
			}
			IntPtr queueHandle = queue != null ? queue.NativeHandle : IntPtr.Zero;
			IntPtr transportHandle = transport != null ? transport.NativeHandle : IntPtr.Zero;
			int code = NativeMethods.mamaFtMember_setup(
				nativeHandle,
				mamaFtType.MAMA_FT_TYPE_MULTICAST,
				queueHandle,
				mCallback,
				transportHandle,
				groupName,
				weight,
				heartbeatInterval,
				timeoutInterval,
				null);
			CheckResultCode(code);
		}
        /// <summary>
        /// This function will create the basic subscription without marketdata semantics.
        /// </summary>
        /// <param name="transport">
        /// The MamaTransport.
        /// </param>
        /// <param name="queue">
        /// The MamaQueue.
        /// </param>
        /// <param name="callback">
        /// Provide callback function implementations to be informed of events on the subscription.
        /// </param>
        /// <param name="symbol">
        /// The symbol to subscribe to.
        /// </param>
        /// <param name="closure">
        /// The closure that will be passed back with the callback functions.
        /// </param>
        public void createBasic(MamaTransport transport, MamaQueue queue, MamaBasicSubscriptionCallback callback, string symbol, object closure)
        {
            // Ensure that the native subscription has been allocated
            EnsurePeerCreated();

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

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

            /* Create the subscription, register for the destroy callback regardless if the client wants it or not,
             * this is to allow clean-up to be done whenever the timer has been fully destroyed.
             */
            CheckResultCode(NativeMethods.mamaSubscription_createBasic(
                                NativeHandle,
                                transport.NativeHandle,
                                queue.NativeHandle,
                                ref mCallbackDelegates,
                                symbol,
                                impl));
        }
Exemple #36
0
			public WatermarkCallbackForwarder(MamaQueue sender, MamaQueueMonitorCallback callback, object closure)
			{
				mSender = sender;
				mCallback = callback;
				mClosure = closure;
			}
Exemple #37
0
            /* ************************************************************** */
            #region Private Operations

            /// <summary>
            /// Dispose(bool disposing) executes in two distinct scenarios.
            /// If disposing equals true, the method has been called directly
            /// or indirectly by a user's code. Managed and unmanaged resources
            /// can be disposed.
            /// If disposing equals false, the method has been called by the
            /// runtime from inside the finalizer and you should not reference
            /// other objects. Only unmanaged resources can be disposed.
            /// </summary>
            /// <param name="disposing">
            /// True if managed resources can be disposed.
            /// </param>
            private void Dispose(bool disposing)
            {
                // Dispose managed objects
                if (disposing)
                {
                    // Stop dispatching the queue, this will not return until the thread has shut down
                    stop();

                    // Destroy the queue
                    mQueue.Dispose();
                    mQueue = null;
                }
            }
Exemple #38
0
        /* ************************************************************** */
        #region Public Functions

        /// <summary>
        /// Create a repeating timer. Since the MamaTimer relies on the timer mechanism of the
        /// underlying middleware, the resolution of the timer is also dependent on the
        /// middleware. Consult your middleware documentation for details.
        /// The callback is invoked repeatedly at the specified interval until the timer
        /// is destroyed.
        /// A null value for the queue uses the default mama queue.
        /// </summary>
        /// <param name="queue">
        /// The queue from which the timer event will be dispatched.
        /// </param>
        /// <param name="action">
        /// The callback to be invoked after the interval
        /// </param>
        /// <param name="interval">
        /// The interval in seconds.
        /// </param>
        public void create(MamaQueue queue, MamaTimerCallback action, double interval)
        {
            // Call the overload with a NULL closure
            this.create(queue, action, interval, null);
        }
Exemple #39
0
			public EnqueueCallbackForwarder(MamaQueue sender, MamaQueueEnqueueCallback callback) 
			{
				mSender = sender;
				mCallback = callback;
			}
Exemple #40
0
 public void LowWatermark(
     MamaQueue mamaQueue,
     int size,
     object closure)
 {
     Console.WriteLine(closure + "queue low water mark exceeded. Size " + size);
 }
Exemple #41
0
 /// <summary>
 /// Set the MAMA queue.  Do this before calling activate().
 /// </summary>
 /// <param name="queue"></param>
 public void setQueue(MamaQueue queue)
 {
     mQueue = queue;
 }
Exemple #42
0
        /// <summary>
        /// Create a repeating timer. Since the MamaTimer relies on the timer mechanism of the
        /// underlying middleware, the resolution of the timer is also dependent on the
        /// middleware. Consult your middleware documentation for details.
        /// The callback is invoked repeatedly at the specified interval until the timer
        /// is destroyed.
        /// A null value for the queue uses the default mama queue.
        /// </summary>
        /// <param name="queue">
        /// The queue from which the timer event will be dispatched.
        /// </param>
        /// <param name="action">
        /// The callback to be invoked after the interval
        /// </param>
        /// <param name="interval">
        /// The interval in seconds.
        /// </param>
        /// <param name="closure">
        /// Closure data for timer.
        /// </param>
        public void create(MamaQueue queue, MamaTimerCallback action, double interval, object closure)
        {
            // Check the arguments
            if (null == queue)
            {
                throw new ArgumentNullException("queue");
            }

            if (null == action)
            {
                throw new ArgumentNullException("action");
            }

            // Create the impl
            IntPtr impl = MamaTimerImpl.Create(action, closure, this);

            /* Create the timer, register for the destroy callback regardless if the client wants it or not,
             * this is to allow clean-up to be done whenever the timer has been fully destroyed.
             */
            IntPtr nativeTimer = IntPtr.Zero;
            CheckResultCode(NativeMethods.mamaTimer_create2(ref nativeTimer, queue.NativeHandle, mTickDelegate, mDestroyDelegate, interval, impl));			

            // Save the native timer in the member variable
            NativeHandle = nativeTimer;
        }
Exemple #43
0
		/// <summary>
		/// CLS compliant version of create
		/// <see cref="create(MamaQueue, MamaIoCallback, uint, mamaIoType, System.Object)"/>
		/// </summary>
		public void create(
			MamaQueue queue,
			MamaIoCallback action, 
			long descriptor,
			mamaIoType ioType,
			object closure)
		{
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
			if (descriptor < 0 || descriptor > UInt32.MaxValue)
			{
				throw new ArgumentOutOfRangeException("descriptor", descriptor);
			}
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
			create(queue, action, (uint)descriptor, ioType, closure);
		}
        /// <summary>
        /// Will process an enqueued event, it will simply increment the count of
        /// the number of events.
        /// </summary>
        /// <param name="mamaQueue">
        /// The queue.
        /// </param>
        /// <param name="closure">
        /// Closure object.
        /// </param>
        void MamaQueueEventCallback.onEvent(MamaQueue mamaQueue, object closure)
        {
            // Increment the event count
            Interlocked.Increment(ref m_numberEvents);

            // Save the closure
            Interlocked.Exchange(ref m_closure, closure);

            // Fire the event to indicate a queue event has been processed
            m_event.Set();
        }
Exemple #45
0
		/// <summary>
		/// Set the MAMA queue.  Do this before calling activate().
		/// </summary>
		/// <param name="queue"></param>
		public void setQueue(MamaQueue  queue)
		{
			mQueue = queue;
		}
Exemple #46
0
 /// <summary>
 /// Creates an inbox and stores at the address specified by the calling client.
 /// </summary>
 /// <param name="transport">
 /// The mamaTransport being used.
 /// </param>
 /// <param name="queue">
 /// Optional mamaQueue. Will use default queue if null.
 /// </param>
 /// <param name="callback">
 /// A callback interface invoked in response to a p2p message being received or when an error is
 /// encountered during p2p messaging.
 /// </param>
 public void create(MamaTransport transport, MamaQueue queue, MamaInboxCallback callback)
 {
     create(transport, queue, callback, null);
 }
Exemple #47
0
		/// <summary>
		/// Create an IO handler.
		/// </summary>
		/// <remarks>
		/// If the underlying infrastructure does not support the requested mamaIoType,
		/// create throws MamaException(MAMA_STATUS_UNSUPPORTED_IO_TYPE). For example,
		/// RV only supports READ, WRITE, and EXCEPT. LBM supports all types except ERROR
		/// </remarks>
		/// <param name="queue">The event queue for the io events. null specifies the
		/// Mama default queue</param>
		/// <param name="action">The callback to be invoked when an event occurs.</param>
		/// <param name="descriptor">Wait for IO on this descriptor.</param>
		/// <param name="ioType">Wait for occurences of this type.</param>
		/// <param name="closure">The closure that is passed to the callback.</param>
		public void create(
			MamaQueue queue,
			MamaIoCallback action, 
			uint descriptor,
			mamaIoType ioType,
			object closure)
		{
#if MAMA_WRAPPERS_CHECK_ARGUMENTS
			if (action == null)
			{
				throw new ArgumentNullException("action");
			}
#endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
			this.callback = action;
			this.closureObject = closure;

			IntPtr queueHandle = queue != null ? queue.NativeHandle : IntPtr.Zero;
			int code = NativeMethods.mamaIo_create(
				ref nativeHandle, 
				queueHandle, 
				descriptor, 
				mIoDelegate,
				(int)ioType,
				IntPtr.Zero);
			CheckResultCode(code);
			
			GC.KeepAlive(queue);
		}
Exemple #48
0
		/// <summary>
		/// CLS compliant version of create
		/// <see cref="create(MamaQueue, MamaIoCallback, uint, mamaIoType, System.Object)"/>
		/// </summary>
		public void create(
			MamaQueue queue,
			MamaIoCallback action, 
			long descriptor,
			mamaIoType ioType)
		{
			create(queue, action, descriptor, ioType, null);
		}
Exemple #49
0
            /* ************************************************************** */
            #region Internal Operations

            /// <summary>
            /// Destroy while waiting for the queue to shutdown complete, this is equivalent to disposing
            /// the class.
            /// </summary>
            internal void destroyWait()
            {
                // Stop dispatching the queue, this will not return until the thread has shut down
                stop();

                // Destroy the queue, but wait until it has shutdown
                mQueue.destroyWait();
                mQueue = null;

                // Supress the finalizer as we have effectively disposed the class
                GC.SuppressFinalize(this);
            }
Exemple #50
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);
                            }
                        }
                    }
                }
            }
        }
Exemple #51
0
 public WatermarkCallbackForwarder(MamaQueue sender, MamaQueueMonitorCallback callback, object closure)
 {
     mSender   = sender;
     mCallback = callback;
     mClosure  = closure;
 }
Exemple #52
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;
            }
        }
Exemple #53
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");
            }
Exemple #54
0
            /* ************************************************************** */
            #region Construction and Finalization

            /// <summary>
            /// Construct initialises all member variables including createing the
            /// thread.
            /// </summary>
            /// <param name="bridge">
            /// The MAMA bridge.
            /// </param>
            public MamaQueueThread(MamaBridge bridge) 
            {
                // Create the queue
                mQueue = new MamaQueue(bridge);
                
                // Start dispatching straight away
                start();
            }
Exemple #55
0
 /// <summary>
 /// MamaQueueMonitorCallback callbacks
 /// </summary>
 /////////////////////////////////////////////////////////////////////////////////////////////////
 public void HighWatermarkExceeded(
     MamaQueue mamaQueue,
     int size,
     object closure)
 {
     Console.WriteLine(closure + " queue high water mark exceeded. Size " + size);
 }
		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;
		}
Exemple #57
0
            /// <summary>
            /// Constructor initialises all member variables.
            /// </summary>
            /// <param name="callback">
            /// The callback object that will be invoked whenever an event is processed.
            /// </param>            
            /// <param name="closure">
            /// Utility object.
            /// </param>
            /// <param name="sender">
            /// The queue.
            /// </param>
            public EnqueueEventForwarder(MamaQueueEventCallback callback, object closure, MamaQueue sender) 
			{
                // Save arguments in member variables.
                mCallback  = callback;
                mClosure   = closure;                
				mSender    = sender;

                // Save a reference to this object in the static list
                mIndex = AddForwarder(this);
            }
Exemple #58
0
            public static int ForwardEvent(MamaQueueEventCallback callback, object closure, IntPtr nativeHandle, MamaQueue sender)
            {
                // Create a new forwarder object to manage the .Net callback objects
                EnqueueEventForwarder forwarder = new EnqueueEventForwarder(callback, closure, sender);

                /* Invoke the native method, the index into the array will be passed as the clousure.
                 */
                return NativeMethods.mamaQueue_enqueueEvent(nativeHandle, forwarder.NativeCallback, new IntPtr(forwarder.mIndex));
            }
Exemple #59
0
 /// <summary>
 /// Set a queue for transport callbacks (transport and topic).
 /// If this is not set the default queue will be used.
 /// </summary>
 public void setTransportCallbackQueue(MamaQueue queue)
 {
     int code = NativeMethods.mamaTransport_setTransportCallbackQueue(nativeHandle, queue.NativeHandle);
       CheckResultCode(code);
       GC.KeepAlive(queue);
 }
Exemple #60
0
        /// <summary>
        /// Create a mama publisher for the corresponding transport. If the transport
        /// is a marketdata transport, as opposed to a "basic" transport, the topic
        /// corresponds to the symbol. For a basic transport, the source and root get 
        /// ignored.
        /// </summary>
        /// <param name="transport">The transport.</param>
        /// <param name="topic">Symbol on which to publish.</param>
        /// <param name="source">The source for market data publishers. (e.g. source.symbol)</param>
        /// <param name="root">The root for market data publishers. Used internally.</param>
        public void createWithCallbacks(
            MamaTransport transport,
            MamaQueue queue,
            MamaPublisherCallback callback,
            Object closure,
            string topic,
            string source,
            string root)
        {
            #if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (nativeHandle != IntPtr.Zero)
            {
                throw new InvalidOperationException("MamaPublisher already created");
            }
            #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            mCallback = callback;

            GCHandle handle = GCHandle.Alloc(this);

            int code = NativeMethods.mamaPublisher_createWithCallbacks(
                ref nativeHandle,
                transport.NativeHandle,
                queue.NativeHandle,
                topic, source, root,
                ref mCallbackDelegates,
                (IntPtr)handle);
            CheckResultCode(code);

            GC.KeepAlive(transport);
            GC.KeepAlive(queue);
            GC.KeepAlive(callback);
        }