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); } }
private MamaMultiSubscriberCS(string[] args) { try { if (parseCommandLine(args)) { IEnumerator iterator = middlewareNames.GetEnumerator(); while (iterator.MoveNext()) { MamaBridge bridge = Mama.loadBridge((string)iterator.Current); mamaBridges.Add(bridge); } Mama.open(); iterator = mamaBridges.GetEnumerator(); while (iterator.MoveNext()) { createSubscriber((MamaBridge)iterator.Current); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
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 void SetUp() { try { //Intialise mama myBridge = new MamaBridge("lbm"); Mama.open(); mDictionary = new MamaDictionary(); mDictionary.create("dictionary.txt"); MamdaCommonFields.setDictionary(mDictionary, null); MamdaTradeFields.reset(); MamdaTradeFields.setDictionary(mDictionary, null); mSubscription = new MamdaSubscription(); mTradeListener = new MamdaTradeListener(); mSubscription.addMsgListener(mTradeListener); ticker = new tradetickerCB(); mTradeListener.addHandler(ticker); } catch (Exception e) { Console.Error.WriteLine(e.ToString()); Environment.Exit(1); } }
/* ************************************************************** */ #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(); }
/// <summary> /// </summary> public static MamaQueue getDefaultEventQueue(MamaBridge bridgeImpl) { IntPtr queuePtr = IntPtr.Zero; int code = NativeMethods.mama_getDefaultEventQueue(bridgeImpl.NativeHandle, ref queuePtr); MamaWrapper.CheckResultCode(code); return(new MamaQueue(queuePtr)); }
/// <summary> /// Start Mama in the background. This method invokes Mama.start() in a separate thread. /// </summary> /// <param name="bridgeImpl"> /// The bridge specific structure. /// </param> /// <param name="callback"> /// The callback for asynchronous status. /// </param> public static void startBackground(MamaBridge bridgeImpl, MamaStartBackgroundCallback callback) { // Allocate a fowarder object mStartBackgroundCallbackForwarder = new StartBackgroundCallbackForwarder(callback); mStartBackgroundShimCallback = new StartBackgroundCallbackForwarder.StartBackgroundCompleteDelegate(mStartBackgroundCallbackForwarder.onStartBackgroundCompleted); // Call the native function MamaWrapper.CheckResultCode(NativeMethods.mama_startBackground(bridgeImpl.NativeHandle, mStartBackgroundShimCallback)); }
/// <summary> /// Create a previously allocated transport. Platform specific parameters /// are read from the properties file mama.properties. The properties /// file is located in the WOMBAT_PATH directory. The parameters are dependent /// on the underlying messaging transport. /// TIBRV transports support the following: mama.tibrv.transport.name.service, /// mama.tibrv.transport.name.network, and mama.tibrv.transport.name.daemon. /// These correspond to the parameters for tibrvTransport_Create(). /// LBM: See the example mama.properties supplied with the release. /// </summary> /// <param name="name"></param> /// <param name="bridgeImpl"></param> public void create(string name, MamaBridge bridgeImpl) { #if MAMA_WRAPPERS_CHECK_ARGUMENTS if (name == null) { throw new ArgumentNullException("name"); } #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS EnsurePeerCreated(); int code = NativeMethods.mamaTransport_create(nativeHandle, name, bridgeImpl.NativeHandle); CheckResultCode(code); }
public void Setup() { mBridge = Mama.loadBridge ("lbm"); Mama.open (); // Create the message m_msg = new MamaMsg(); // Create the array of messages m_vectorMsg = InitialiseMessageArray(m_numberMessages, 69); m_vectorMsg2 = InitialiseMessageArray(m_numberMessages, 144); }
/// <summary> /// Construct a queue manager with given number of queues/threads /// </summary> /// <param name="queueCount"></param> /// <param name="bridgeImpl"></param> public MamaQueueManager(MamaBridge bridgeImpl, int queueCount) { if (queueCount < 1) { throw new Exception("Queue count should be > 0"); } threads = new MamaQueueThread[queueCount]; for (int i = 0; i < threads.Length; i++) { threads[i] = new MamaQueueThread(new MamaQueue(bridgeImpl)); } }
/* ************************************************************** */ #region Construction and Finalization /// <summary> /// Construct a queue manager with given number of queues/threads /// </summary> /// <param name="bridgeImpl"> /// The mama bridge. /// </param> /// <param name="queueCount"> /// The number of queues in the group. /// </param> public MamaQueueGroup(MamaBridge bridgeImpl, int queueCount) { // Check arguments if (queueCount < 1) { throw new ArgumentOutOfRangeException("queueCount", queueCount, "Queue count should be > 0"); } // Create the array of queue threads mQueueThreads = new MamaQueueThread[queueCount]; for (int nextQueue = 0; nextQueue < queueCount; nextQueue++) { mQueueThreads[nextQueue] = new MamaQueueThread(bridgeImpl); } }
private void InitializeMama() { try { Mama.logToFile(@"mama.log", MamaLogLevel.MAMA_LOG_LEVEL_FINEST); bridge = new MamaBridge(middlewareName); Mama.open(); transport = new MamaTransport(); transport.create(transportName, bridge); defaultQueue = Mama.getDefaultEventQueue(bridge); } catch (MamaException e) { Console.WriteLine("Error initializing mama or creating transport: {0}", e.ToString()); Exit(1); } }
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> /// Stop dispatching on the default event queue for the specified bridge. /// /// MAMA employs a reference count to track multiple calls to Mama.start() and /// Mama.stop(). The count is incremented every time Mama.start() is called and /// decremented when Mama.stop() is called. The first Mama.start() call does not /// unblock until the count reaches zero. /// /// This function is thread safe. /// </summary> /// <param name="bridgeImpl"> /// The bridge specific structure. /// </param> public static void stop(MamaBridge bridgeImpl) { MamaWrapper.CheckResultCode(NativeMethods.mama_stop(bridgeImpl.NativeHandle)); }
/// <summary> /// Return the version information for the library /// The version of Mama follows in parenthesis /// </summary> /// <returns>Version string</returns> public static string getVersion(MamaBridge bridgeImpl) { return(MamaVersion.MAMADOTNET_VERSION + " (" + Marshal.PtrToStringAnsi(NativeMethods.mama_getVersion(bridgeImpl.NativeHandle)) + ")"); }
/// <summary> /// </summary> public static MamaQueue getDefaultEventQueue(MamaBridge bridgeImpl) { IntPtr queuePtr = IntPtr.Zero; int code = NativeMethods.mama_getDefaultEventQueue (bridgeImpl.NativeHandle, ref queuePtr); MamaWrapper.CheckResultCode(code); return new MamaQueue (queuePtr); }
internal ListenerDictionaryCallback(MamaBridge bridge) { // Save arguments in member variables m_bridge = bridge; }
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."); } }
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); } }
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; }
/// <summary> /// Create a queue /// </summary> public MamaQueue(MamaBridge bridgeImpl) : base() { int code = NativeMethods.mamaQueue_create(ref nativeHandle, bridgeImpl.NativeHandle); CheckResultCode(code); }
public Dispatcher (MamaBridge bridge) { myBridge = bridge; }
internal KillTimerCallback(MamaBridge bridge) { // Save arguments in member variables m_bridge = bridge; }
private void parseCommandLine(string[] args) { string tport = null; uint ft_type = (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST; bool displayVersion = false; for (int i = 0; i < args.Length; ) { if ((args[i].CompareTo ("-h")) == 0 || (args[i].CompareTo ("-?")) == 0) { usage (0); } if ((args[i].CompareTo ("-g") == 0) || (args[i].CompareTo ("-group") == 0)) { myGroup = args[i+1]; i += 2; continue; } if ((args[i].CompareTo ("-w") == 0) || (args[i].CompareTo ("-weight") == 0)) { myWeight = Convert.ToUInt32 (args[i+1]); i += 2; continue; } if (args[i].CompareTo ("-m") == 0) { myMiddleware = args[i+1]; i += 2; continue; } if ((args[i].CompareTo ("-t") == 0) || (args[i].CompareTo ("-tport") == 0)) { tport = args[i+1]; i += 2; continue; } if (args[i].CompareTo ("-v") == 0) { if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_WARN) { mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_NORMAL; Mama.enableLogging (mamaLogLevel); } else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_NORMAL) { mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINE; Mama.enableLogging (mamaLogLevel); } else if (mamaLogLevel == MamaLogLevel.MAMA_LOG_LEVEL_FINE) { mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINER; Mama.enableLogging (mamaLogLevel); } else { mamaLogLevel = MamaLogLevel.MAMA_LOG_LEVEL_FINEST; Mama.enableLogging (mamaLogLevel); } i++; continue; } if (args[i].CompareTo ("-version") == 0) { displayVersion = true; break; } if (args[i].CompareTo ("-b") == 0) { ft_type = (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE; i++; continue; } i++; } myBridge = Mama.loadBridge(myMiddleware); Mama.open(); if (displayVersion) { Console.WriteLine (Mama.getVersion (myBridge)); Exit (0); } myTimer = new MamaTimer(); myTransport = new MamaTransport(); myTransport.create(tport, myBridge); if (myGroup == null) { Console.WriteLine ("No FT group name specified"); usage(1); } switch (ft_type) { case (uint)mamaFtType.MAMA_FT_TYPE_MULTICAST: myFtMember = new MamaMulticastFtMember (); break; case (uint)mamaFtType.MAMA_FT_TYPE_BRIDGE: myFtMember = new MamaBridgeFtMember (); break; default: Console.WriteLine ("No FT type specified"); usage(1); break; } }
/* ************************************************************** */ #region Construction and Finalization /// <summary> /// Construct a queue manager with given number of queues/threads /// </summary> /// <param name="bridgeImpl"> /// The mama bridge. /// </param> /// <param name="queueCount"> /// The number of queues in the group. /// </param> public MamaQueueGroup(MamaBridge bridgeImpl, int queueCount) { // Check arguments if (queueCount < 1) { throw new ArgumentOutOfRangeException("queueCount", queueCount, "Queue count should be > 0"); } // Create the array of queue threads mQueueThreads = new MamaQueueThread[queueCount]; for (int nextQueue = 0; nextQueue<queueCount; nextQueue++) { mQueueThreads[nextQueue] = new MamaQueueThread(bridgeImpl); } }
internal ListenShutdownTimerCallback(MamaBridge bridge) { m_bridge = bridge; }
public Dispatcher(MamaBridge bridge) { myBridge = bridge; }
/// <summary> /// Create a queue /// </summary> public MamaQueue (MamaBridge bridgeImpl) : base() { int code = NativeMethods.mamaQueue_create(ref nativeHandle, bridgeImpl.NativeHandle); CheckResultCode(code); }
/// <summary> /// Return the version information for the library /// The version of Mama follows in parenthesis /// </summary> /// <returns>Version string</returns> public static string getVersion(MamaBridge bridgeImpl) { return MamaVersion.MAMADOTNET_VERSION + " (" + Marshal.PtrToStringAnsi(NativeMethods.mama_getVersion (bridgeImpl.NativeHandle)) + ")"; }
public void createForBridgeFromBuffer(byte[] byteBuffer, int size, MamaBridge bridgeImpl) { EnsurePeerCreated(); if (buffer != IntPtr.Zero) { Marshal.FreeHGlobal(buffer); buffer = IntPtr.Zero; } Marshal.Copy(byteBuffer, 0, buffer, size); int code = NativeMethods.mamaMsg_createForBridgeFromByteBuffer(ref nativeHandle, buffer, size, bridgeImpl.NativeHandle); CheckResultCode(code); }
/// <summary> /// This function will initialise mama including loading the bridge and creating the queues and transports. /// </summary> private void initializeMama() { // Set the desired log level, (based on the number of 'v's passed on the command line) Mama.enableLogging(m_logLevel); m_bridge = Mama.loadBridge(m_middlewareName); Console.WriteLine(Mama.getVersion(m_bridge)); Mama.open(); m_defaultQueue = Mama.getDefaultEventQueue(m_bridge); // The transport must be created before the dictionary is downloaded createTransport(); createDictionary(); createQueues(); // Create the source needed to establish market data subscriptions createSource(); }
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(); }
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; }