void BookPublisher::publishMessage (MamaMsg* request, const char* symbol) { if (!mPublisher) { MamdaSubscription* mamdaSub = getMamdaSubscription(symbol); if (mamdaSub) { MamaSubscription* mSub = mamdaSub->getMamaSubscription(); mPublisher = mPubManager->createPublisher (symbol, managerCallback); } } try { if (request) { mPublisher->sendReply (*request, &mPublishMsg); } else { mPublisher->send (&mPublishMsg); } } catch (MamaStatus &status) { cerr << "Error publishing message: " << status.toString () << endl; exit (1); } }
void SubscriptionHandler::onNewRequest ( MamaDQPublisherManager* publisherManager, const char* symbol, short subType, short msgType, MamaMsg& msg) { MamaMsg* request = NULL; MamdaSubscription* mamdaSub = mBookPublisher->getMamdaSubscription(symbol); if (mamdaSub) { MamaSubscription* mSub = mamdaSub->getMamaSubscription(); MamaDQPublisher* mPub = publisherManager->createPublisher (symbol, mBookPublisher->getCb()); printf ("Received New request: %s\n", symbol); switch (msgType) { case MAMA_SUBSC_SUBSCRIBE: case MAMA_SUBSC_SNAPSHOT: request = msg.detach(); mBookPublisher->publishMessage (request, symbol); break; default: mBookPublisher->publishMessage (NULL, symbol); break; } } else printf ("Received request for unknown symbol: %s\n", symbol); flush (cout); }
int main (int argc, const char **argv) { try { CommonCommandLineParser cmdLine (argc, argv); // Initialise the MAMA API mamaBridge bridge = cmdLine.getBridge(); Mama::open (); const vector<const char*>& symbolList = cmdLine.getSymbolList (); MamaSource* source = cmdLine.getSource(); MamaSource* optionSource = cmdLine.getOptionSource(); int duration = cmdLine.getOptInt ("duration"); double timeout = cmdLine.getTimeout (); MamaLogLevel subscLogLevel = cmdLine.getSubscLogLevel(); MamaQueueGroup queues (cmdLine.getNumThreads(), bridge); double throttleRate = cmdLine.getThrottleRate (); if ((throttleRate > 100.0) || (throttleRate <= 0.0)) { // We don't really want to swamp the FHs with these types of // subscriptions. throttleRate = 100.0; } source->getTransport()->setOutboundThrottle (throttleRate, MAMA_THROTTLE_DEFAULT); DictRequester dictRequester (bridge); dictRequester.requestDictionary (cmdLine.getDictSource()); MamdaTradeFields::setDictionary (*dictRequester.getDictionary()); MamdaQuoteFields::setDictionary (*dictRequester.getDictionary()); MamdaFundamentalFields::setDictionary (*dictRequester.getDictionary()); MamdaOptionFields::setDictionary (*dictRequester.getDictionary()); const char* symbolMapFile = cmdLine.getSymbolMapFile (); if (symbolMapFile) { MamaSymbolMapFile* aMap = new MamaSymbolMapFile; if (MAMA_STATUS_OK == aMap->load (symbolMapFile)) { source->getTransport()->setSymbolMap (aMap); optionSource->getTransport()->setSymbolMap (aMap); } } for (vector<const char*>::const_iterator i = symbolList.begin (); i != symbolList.end (); ++i) { const char* symbol = *i; MamaQueue* queue = queues.getNextQueue(); // Create chain and listener objects. MamdaTradeListener* aBaseTradeListener = new MamdaTradeListener; MamdaQuoteListener* aBaseQuoteListener = new MamdaQuoteListener; MamdaFundamentalListener* aFundamentalListener = new MamdaFundamentalListener; MamdaOptionChain* anOptionChain = new MamdaOptionChain (symbol); anOptionChain->setUnderlyingQuoteListener (aBaseQuoteListener); anOptionChain->setUnderlyingTradeListener (aBaseTradeListener); MamdaOptionChainListener* anOptionListener = new MamdaOptionChainListener (anOptionChain); // By Default Expirate Date , Strike Price and PutCall fields // are considered manditory to the creation of an option contract // Clear monditory status of each of these fields if so directed // n the command line. anOptionListener->setManditoryFields ( !cmdLine.getOptBool ("noExpire"), !cmdLine.getOptBool ("noStrike"), !cmdLine.getOptBool ("noPutCall")); // Create our handlers (the UnderlyingTicker and // OptionChainDisplay could be a single class). UnderlyingTicker* aBaseTicker = new UnderlyingTicker (*anOptionChain); OptionChainDisplay* aDisplay = new OptionChainDisplay (*anOptionChain); // Create subscriptions for underlying and option chain: MamdaSubscription* anOptionSubscription = new MamdaSubscription; // Register for underlying quote and trade events. aBaseTradeListener->addHandler (aBaseTicker); aBaseQuoteListener->addHandler (aBaseTicker); aFundamentalListener->addHandler (aBaseTicker); // Register for underlying option events. anOptionListener->addHandler (aDisplay); // The timeout defaults to 1 for this example because we // currently use the timeout feature to determine when // to say that we have received all of the initials. anOptionSubscription->setTimeout (timeout); anOptionSubscription->addMsgListener (anOptionListener); anOptionSubscription->addQualityListener (aDisplay); anOptionSubscription->addErrorListener (aDisplay); anOptionSubscription->setType (MAMA_SUBSC_TYPE_GROUP); anOptionSubscription->create (queue, source, symbol); // logger... anOptionSubscription->getMamaSubscription ()-> setDebugLevel (subscLogLevel); } ShutdownTimer shutdownCallback (bridge); MamaTimer shutdownTimer; if (duration > 0) { shutdownTimer.create (Mama::getDefaultEventQueue (bridge), &shutdownCallback, duration, queues.getNextQueue()); } Mama::start(bridge); } catch (MamaStatus &e) { // This exception can be thrown from Mama::start (), // Mama::createTransport (transportName) and from // MamdaSubscription constructor when entitlements is enabled. cerr << "Exception in main (): " << e.toString () << endl; exit (1); } catch (exception &ex) { cerr << "Exception in main (): " << ex.what () << endl; exit (1); } catch (...) { cerr << "Unknown Exception in main ()." << endl; exit (1); } }