Exemplo n.º 1
0
int LocalNodeInfo::subscribe (uint16 ui16ClientId, const char *pszGroupName, Subscription *pSubscription)
{
    _m.lock (300);
    if (pszGroupName == NULL || pSubscription == NULL) {
        delete pSubscription;
        _m.unlock (300);
        return -1;
    }

    char *pszOnDemandDataGroupName = getOnDemandDataGroupName (pszGroupName);
    if (pszOnDemandDataGroupName == NULL) {
        // The on-demand subscription group name could not be generated
        delete pSubscription;
        _m.unlock (300);
        return -2;
    }

    Subscription *pOnDemandSubscription = pSubscription->getOnDemandSubscription();
    if (pOnDemandSubscription == NULL) {
        free (pszOnDemandDataGroupName);
        delete pSubscription;
        _m.unlock (300);
        return -3;
    }

    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        pSL = new SubscriptionList();
        _localSubscriptions.put (ui16ClientId, pSL);
    }

    if (pSL->addGroup (pszGroupName, pSubscription) != 0) {
        // The subscription could not be added
        free (pszOnDemandDataGroupName);
        delete pSubscription;
        delete pOnDemandSubscription;
        _m.unlock (300);
        return -4;
    }

    if (pSL->addGroup (pszOnDemandDataGroupName, pOnDemandSubscription) != 0) {
        // The on-demand subscription could not be added
        free (pszOnDemandDataGroupName);
        delete pOnDemandSubscription;
        pSL->removeGroup (pszGroupName, pSubscription);    // Should delete pSubscription
        _m.unlock (300);
        return -5;
    }

    // The subscription was added, check if the ConsolidateList needs to be modified too.
    updateConsolidateSubsciptionList (pszGroupName, pSubscription);

    // The subscription was added, check if the ConsolidateList needs to be modified too.
    updateConsolidateSubsciptionList (pszOnDemandDataGroupName, pOnDemandSubscription);
    free (pszOnDemandDataGroupName);

    _m.unlock (300);
    return 0;
}
Exemplo n.º 2
0
Subscription * LocalNodeInfo::getSubscriptionForClient (uint16 ui16ClientId, const char *pszGroupName)
{
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        return NULL;
    }
    return pSL->getSubscription (pszGroupName);
}
Exemplo n.º 3
0
void LocalNodeInfo::recomputeConsolidateSubsciptionList (void)
{
    // TODO CHECK: I don't think the includes applies anymore, so I commented it
    // In fact, even if the includes returns true,
    // I still need to merge subscriptions in terms of priority, reliability, sequenced, etc

    CRC * pCRC = new CRC();
    pCRC->init();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *)iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 oldCRC = pCRC->getChecksum();

    // Delete the current Consolidate Subscription List and compute a new one
    _consolidatedSubscriptions.clear();

    // For each client
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        if (pSL != NULL) {
            // Get all its subscriptions
            PtrLList<String> *pSubgroups = pSL->getAllSubscribedGroups();
            for (String *pSubGroupName = pSubgroups->getFirst(); pSubGroupName != NULL; pSubGroupName = pSubgroups->getNext()) {
                // For each group, get the subscription the client has
                const char *pszGroupName = pSubGroupName->c_str();
                Subscription *pClientSub = pSL->getSubscription (pszGroupName);
                // And the subscription in the consolidate subscription list if any
                Subscription *pSubInConsolidateList = _consolidatedSubscriptions.getSubscription (pszGroupName);
                if (pSubInConsolidateList == NULL) {
                    _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                }
                else {
                    /*if (pClientSub->includes (pSubInConsolidateList)) {
                        _consolidatedSubscriptions.removeGroup (pszGroupName);
                        _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                    }
                    else {*/
                        pClientSub->merge (pSubInConsolidateList);
                    /*}*/
                }
            }
        }
    }

    pCRC->reset();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *) iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 newCRC = pCRC->getChecksum();
    if (oldCRC != newCRC) {
        ui32SubscriptionStateSeqID++;
        GroupSubscription *pSubscription = new GroupSubscription(); // Void subscription to respect method interface
        _notifier.modifiedSubscriptionForPeer (_pszId, pSubscription);
    }
}
Exemplo n.º 4
0
int TopologyWorldState::updateSubscriptionState (StringHashtable<SubscriptionList> *pSubscriptionsTable, StringHashtable<uint32> *pNodesTable)
{
    // Updates the remote subscriptions with the pSubscriptionsTable and pNodesTable info
    _m.lock (131);
    for (StringHashtable<uint32>::Iterator iterator = pNodesTable->getAllElements(); !iterator.end(); iterator.nextElement()) {
        if (0 != stricmp (_pDisService->getNodeId(), iterator.getKey())) {
            RemoteNodeInfo * pRNI = (RemoteNodeInfo*) retrieveNodeInfo (iterator.getKey());
            if (pRNI) {
                uint32 *pui32RemoteSeqId = iterator.getValue();
                uint32 *pui32LocalSeqId = _subscriptionStateTable.get (iterator.getKey());
                if (!pui32LocalSeqId) {
                    pui32LocalSeqId = new uint32();
                }
                if ((*pui32RemoteSeqId) > (*pui32LocalSeqId)) {
                    pRNI->unsubscribeAll();
                    (*pui32LocalSeqId) = (*pui32RemoteSeqId);
                    _subscriptionStateTable.put (iterator.getKey(), pui32LocalSeqId);
                    continue;
                }
            }
        }
        pNodesTable->remove (iterator.getKey());
    }
    // Update _ui16SubscriptionStateCRC
    _crc.reset();
    for (StringHashtable<uint32>::Iterator iterator = _subscriptionStateTable.getAllElements(); !iterator.end(); iterator.nextElement()) {
        _crc.update ((const char *) iterator.getKey());
        _crc.update32 (iterator.getValue());
    }
    _ui16SubscriptionStateCRC = _crc.getChecksum();
    for (StringHashtable<SubscriptionList>::Iterator subIterator = pSubscriptionsTable->getAllElements(); !subIterator.end(); subIterator.nextElement()) {
        const char * nodeId = subIterator.getKey();
        if (pNodesTable->get (nodeId) != NULL) {
            SubscriptionList *pSubs = subIterator.getValue();
            RemoteNodeInfo * pRNI = (RemoteNodeInfo*) retrieveNodeInfo (nodeId);
            if (pRNI == NULL) {
                _m.unlock (131);
                return 0;
            }
            // Add subscriptions to pRNI
            for (StringHashtable<Subscription>::Iterator i = pSubs->getIterator(); !i.end(); i.nextElement()) {
                Subscription *pSub = i.getValue();
                Subscription *pSubAux = pSub->clone();
                pRNI->subscribe(i.getKey(), pSubAux);
            }
            SubscriptionList *pSubscriptions =  pRNI->getRemoteSubscriptionsCopy();
            sendSubscriptionStateMsg (pSubscriptions, nodeId, pNodesTable->get (nodeId));
        }
    }
    delete pSubscriptionsTable;
    pSubscriptionsTable = NULL;
    delete pNodesTable;
    pNodesTable = NULL;
    _m.unlock (131);
    return 0;
}
Exemplo n.º 5
0
SubscriptionList * LocalNodeInfo::getConsolidatedSubscriptionsCopy (void)
{
    SubscriptionList *pConsolidatedSubscriptionsCopy = new SubscriptionList();
    if (pConsolidatedSubscriptionsCopy != NULL) {
        for (StringHashtable<Subscription>::Iterator i = _consolidatedSubscriptions.getIterator(); !i.end(); i.nextElement()) {
            pConsolidatedSubscriptionsCopy->addSubscription (i.getKey(), (i.getValue())->clone()); // Clone subscription before adding it
        }
    }
    return pConsolidatedSubscriptionsCopy;
}
/*
 * Unsubscribe from all specified symbols.
 */
void MamaEntitle::unsubscribeFromSymbols (void)
{
    SubscriptionList::const_iterator i;

    for (i = mSubscriptionList.begin (); i != mSubscriptionList.end (); i++)
    {
        ((MamaSubscription*)*i)->destroy();
        delete *i;
    }
}
Exemplo n.º 7
0
void LocalNodeInfo::addAddFiltersToConsolidateList (const char *pszGroupName)
{
    _m.lock (328);
    // Get all the client subscribing the group
    DArray<uint16> *pSubClients = NULL;//getSubscribingClients (pszGroupName);
    Subscription *pSCons = _consolidatedSubscriptions.getSubscription (pszGroupName);
    if ((pSubClients == NULL) ||  (!((pSCons != NULL) && (pSCons->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION)))) {
        _m.unlock (328);
        return;
    }
    GroupSubscription *pGSCons = (GroupSubscription *) pSCons;

    // Look for the first subscribing client which subscribes by a GROUP_SUBSCRIPTION
    uint16 ui16ClientId;
    Subscription *pS = NULL;
    for (int i = 0; i <= pSubClients->getHighestIndex(); i++) {
        ui16ClientId = (*pSubClients)[i];
        SubscriptionList *pSL = NULL;
        if (((pSL = _localSubscriptions.get(ui16ClientId)) != NULL) && ((pS = pSL->getSubscription(pszGroupName)) != NULL)) {
            if (pS->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION) {
                break;
            }
            if (pS->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) {
                // I want every tag - remove them and return
                pGSCons->removeAllFilters();
                _m.unlock (328);
                return;
            }
        }
    }

    // match every filter against every other subscribing client's tag list.
    // Add it iff:
    // 1) Every other GROUP_SUBSCRIPTION has the same filter
    // 2) No one of the other GROUP_TAG_SUBSCRIPTION subscribe the tag
    // 3) There is not any GROUP_PREDICATE_SUBSCRIPTION for the group
    GroupSubscription *pGS = (GroupSubscription*) pS;
    DArray<uint16> *pTags = pGS->getAllFilters();

    for (int i = 0; i <= pTags->getHighestIndex(); i++) {
        bool bAddFilter = true;
        int16 ui16Tag = (*pTags)[i];
        for (int j = 0; j <= pSubClients->getHighestIndex(); j++) {
            Subscription *pS = NULL;
            if (pS->matches(ui16Tag)) {
                bAddFilter = false;
                break;
            }
        }
        if (bAddFilter) {
            pGSCons->addFilter((*pTags)[i]);
        }
    }
    _m.unlock (328);
}
Exemplo n.º 8
0
int TopologyWorldState::printWorldStateInfo (void) 
{
    // Prints information about local node, like subscriptions, alive neighbors, dead peers, etc
    _m.lock (141);
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     PRINT WORLD STATE INFO\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     Node id: %s\n", _pDisService->getNodeId());
    if ((_pLocalNodeInfo->getConsolidatedSubscriptions())->getCount() == 0) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     No subscribed groups\n");
    } else {
        _pLocalNodeInfo->printAllSubscribedGroups();
        // Print subscribing clients
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIBING CLIENTS:\n");
        DArray<uint16> *pSubClients = _pLocalNodeInfo->getAllSubscribingClients();
        for (int j = 0; j <= pSubClients->getHighestIndex(); j++) {
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUB CLIENT N.%d:\n", (*pSubClients)[j]);
            SubscriptionList *pSubsForClient = _pLocalNodeInfo->getSubscriptionListForClient ((*pSubClients)[j]);
            _pLocalNodeInfo->releaseLocalNodeInfo();
            if (pSubsForClient && pSubsForClient->getCount() != 0) {
                for (StringHashtable<Subscription>::Iterator i = pSubsForClient->getIterator(); !i.end(); i.nextElement()) {
                    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIPTION:\n");
                    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     groupname %s\n", i.getKey());
                    Subscription *pS = i.getValue();
                    pS->printInfo();                
                }
            }
        }
        // Print local consolidated subscriptions
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     LOCAL CONSOLIDATED SUBSCRIPTIONS:\n");
        SubscriptionList *pSubscriptions = _pLocalNodeInfo->getConsolidatedSubscriptions();
        for (StringHashtable<Subscription>::Iterator i = pSubscriptions->getIterator(); !i.end(); i.nextElement()) {
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIPTION:\n");
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     groupname %s\n", i.getKey());
            Subscription *pS = i.getValue();
            pS->printInfo();   
        }
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     %d ACTIVE NEIGHBORS\n", _pLocalNodeInfo->getCount());
    for (StringHashtable<Thing>::Iterator iNeighbors = _pLocalNodeInfo->getAllElements(); !iNeighbors.end(); iNeighbors.nextElement()) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
        RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iNeighbors.getValue();
        pRNI->printRemoteNodeInfo();
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     %d DEAD PEERS\n", _deadPeers.getCount());
    for (StringHashtable<RemoteNodeInfo>::Iterator iDead = _deadPeers.getAllElements(); !iDead.end(); iDead.nextElement()) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
        RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iDead.getValue();
        pRNI->printRemoteNodeInfo();
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n");
    _m.unlock (141);
    return 0;
}
Exemplo n.º 9
0
int LocalNodeInfo::removeAllFilters (uint16 ui16ClientId, const char *pszGroupName)
{
    _m.lock (304);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if ((pSL != NULL) && (pSL->removeAllFiltersFromGroup (pszGroupName) == 0)) {
        _consolidatedSubscriptions.removeAllFiltersFromGroup (pszGroupName);
        _m.unlock (304);
        return 0;
    }
    _m.unlock (304);
    return -1;
}
Exemplo n.º 10
0
int LocalNodeInfo::modifyGroupPriority (uint16 ui16ClientId, const char *pszGroupName, uint8 ui8NewPriority)
{
    _m.lock (302);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        _m.unlock (302);
        return -1;
    }
    int ret = pSL->modifyPriority (pszGroupName, 0,ui8NewPriority);
    _m.unlock (302);
    return ret;
}
Exemplo n.º 11
0
bool LocalNodeInfo::hasSubscription (uint16 ui16ClientId, Message *pMessage)
{
    _m.lock (318);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        _m.unlock (318);
        return false;
    }
    bool bRet = pSL->hasSubscriptionWild (pMessage);
    _m.unlock (318);
    return bRet;
}
Exemplo n.º 12
0
SubscriptionList * RemoteNodeInfo::getRemoteSubscriptionsCopy (void)
{
    // Returns a copy of _pRemoteSubscriptions
    SubscriptionList *pRemoteSubscriptionsCopy = NULL;
    if (_pRemoteSubscriptions) {
        pRemoteSubscriptionsCopy = new SubscriptionList();
        for (StringHashtable<Subscription>::Iterator i = _pRemoteSubscriptions->getIterator(); !i.end(); i.nextElement()) {
            pRemoteSubscriptionsCopy->addSubscription (i.getKey(), (i.getValue())->clone()); // Clone subscription before adding it
        }
    }
    return pRemoteSubscriptionsCopy;
}
Exemplo n.º 13
0
MamdaSubscription* BookPublisher::getMamdaSubscription (const char * symbol) 
{
    SubscriptionList::const_iterator i;
    
    for (i = mSubscriptionList.begin (); i != mSubscriptionList.end (); i++)
    {
        if  (strcmp(((MamdaSubscription*)*i)->getSymbol() , symbol)==0)
        {
            return (MamdaSubscription*)*i;
        }
    }
    return NULL; 
}   
Exemplo n.º 14
0
bool LocalNodeInfo::hasSubscription (Message *pMessage)
{
    _m.lock (317);
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        if (pSL->hasSubscriptionWild (pMessage)) {
            _m.unlock (317);
            return true;
        }
    }
    _m.unlock (317);
    return false;
}
Exemplo n.º 15
0
PtrLList<HistoryRequest> * LocalNodeInfo::getHistoryRequests (uint16 ui16ClientId)
{
    _m.lock (310);
    PtrLList<HistoryRequest> *pRet = new PtrLList<HistoryRequest>();
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL != NULL) {
        pSL->getHistoryRequests (*pRet);
    }
    if (!pRet->getFirst()) {
        delete pRet;
        pRet = NULL;
    }
    _m.unlock (310);
    return pRet;
}
Exemplo n.º 16
0
bool LocalNodeInfo::isInHistory (uint16 ui16ClientId, Message *pMsg, uint32 ui32LatestMsgRcvdPerSender)
{
    _m.lock (312);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL != NULL) {
        Subscription *pS = pSL->getSubscription (pMsg->getMessageInfo()->getGroupName());
        if (pS) {
            bool bRet = pS->isInHistory (pMsg, ui32LatestMsgRcvdPerSender);
            _m.unlock (312);
            return bRet;
        }
    }
    _m.unlock (312);
    return false;
}
Exemplo n.º 17
0
void BookPublisher::subscribeToSymbols () 
{ 

    for (vector<const char*>::const_iterator i = mSymbolList.begin ();
         i != mSymbolList.end ();
         ++i)
    {   
        const char* symbol = *i;
        mBook = new MamdaOrderBook();
        // Turn on delta generation
        mBook->generateDeltaMsgs(true);
        MamdaSubscription*      aSubscription = new MamdaSubscription;
        MamdaOrderBookListener* aBookListener = new MamdaOrderBookListener(mBook);
        aSubscription->addMsgListener (aBookListener);
        aBookListener->setProcessEntries (mProcessEntries);

        BookTicker* aTicker = new BookTicker;
        aBookListener->addHandler (aTicker);
       
        aSubscription->setType (MAMA_SUBSC_TYPE_BOOK);
        aSubscription->setMdDataType (MAMA_MD_DATA_TYPE_ORDER_BOOK);
        mSubscriptionList.push_back (aSubscription);

        aSubscription->create (Mama::getDefaultEventQueue (mBridge), mSubSource, symbol, NULL);

    }
}
Exemplo n.º 18
0
int LocalNodeInfo::addFilter (uint16 ui16ClientId, const char *pszGroupName, uint16 ui16Tag)
{
    _m.lock (301);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        _m.unlock (301);
        return -1;
    }
    if (pSL->addFilterToGroup (pszGroupName, ui16Tag) != 0) {
        _m.unlock (301);
        return -2;
    }
    bool bAddFilter = true;

    // I can add the filter to the ConsolidatedSubscriptions only if every client subscribing that group has the filter too
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        Subscription *pS = pSL->getSubscription(pszGroupName);
        switch (pS->getSubscriptionType()) {
            case Subscription::GROUP_SUBSCRIPTION: {
                if (!((GroupSubscription *)pS)->hasFilter(ui16Tag)) {
                    bAddFilter = false;
                    break;
                }
                break;
            }
            case Subscription::GROUP_TAG_SUBSCRIPTION: {
                if (((GroupTagSubscription *)pS)->hasTag(ui16Tag)) {
                    bAddFilter = false;
                    break;
                }
                break;
            }
            case Subscription::GROUP_PREDICATE_SUBSCRIPTION :
                 bAddFilter = false;
                 break;
        }
    }
    if (bAddFilter) {
        _consolidatedSubscriptions.addFilterToGroup (pszGroupName, ui16Tag);
    }

    _m.unlock (301);
    return 0;
}
Exemplo n.º 19
0
int LocalNodeInfo::unsubscribe (uint16 ui16ClientId, const char *pszGroupName)
{
    char *pszOnDemandDataGroupName = getOnDemandDataGroupName (pszGroupName);
    if (pszOnDemandDataGroupName == NULL) {
        // The on-demand subscription group name could not be generated
        return -1;
    }
    _m.lock (305);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL != NULL) {
        if ((pSL->removeGroup (pszGroupName) == 0) && (pSL->removeGroup (pszOnDemandDataGroupName) == 0)) {
            recomputeConsolidateSubsciptionList();
            free (pszOnDemandDataGroupName);
            _m.unlock (305);
            return 0;
        }
    }
    free (pszOnDemandDataGroupName);
    _m.unlock (305);
    return -2;
}
void MamaEntitle::shutdown ()
{
    if (mQueueGroup != NULL)
    {
        mQueueGroup->stopDispatch();
    }
    if (mDictionary != NULL)
    {
        delete mDictionary;
        mDictionary = NULL;
    }
        
    SubscriptionList::const_iterator i;
    
    for (i = mSubscriptionList.begin (); i != mSubscriptionList.end (); i++)
    {
        ((MamaSubscription*)*i)->destroy();
        delete *i;
    }
    
    if (mQueueGroup != NULL)
    {
        delete mQueueGroup;
        mQueueGroup = NULL;
    }
    
    if ((mDictTransport !=  NULL)  && (mDictTransport  != mTransport))                 
    {
        delete mDictTransport;
        mDictTransport = NULL;
    }
    
    if (mTransport != NULL)
    {
        delete mTransport;
        mTransport = NULL;
    }

    Mama::close ();
}
    bool parseCommandLine(int argc, char **argv)
    {
        int tokenCount = 0;
        for (int i = 1; i < argc; ++i) {
            if (!std::strcmp(argv[i],"-s") && i + 1 < argc) {
                d_securities.push_back(argv[++i]);
                continue;
            }

            if (!std::strcmp(argv[i],"-f") && i + 1 < argc) {
                d_field = std::string(argv[++i]);
                continue;
            }

            if (!std::strcmp(argv[i],"-t") && i + 1 < argc) {
                d_tokens.push_back(argv[++i]);
                ++tokenCount;
                std::cout << "User #" << tokenCount
                          << " token: " << argv[i]
                          << std::endl;
                continue;
            }
            if (!std::strcmp(argv[i],"-ip") && i + 1 < argc) {
                d_host = argv[++i];
                continue;
            }
            if (!std::strcmp(argv[i],"-p") &&  i + 1 < argc) {
                d_port = std::atoi(argv[++i]);
                continue;
            }
            printUsage();
            return false;
        }

        if (!d_tokens.size()) {
            std::cout << "No tokens were specified" << std::endl;
            printUsage();
            return false;
        }

        if (!d_securities.size()) {
            d_securities.push_back("MSFT US Equity");
        }

        for (size_t i = 0; i < d_securities.size(); ++i) {
            d_subscriptions.add(d_securities[i].c_str(), d_field.c_str(), "",
                CorrelationId(i));
        }
        return true;
    }
void MamaEntitle::subscribeToSymbol (const char* symbol)
{
    static int howMany = 0;

    if (!mDisplayCallback)
    {
        mDisplayCallback = new DisplayCallback (this);
    }
    
    MamaSubscription* sub = NULL;
    sub = new MamaSubscription;
    
    sub->setRetries (3);
    sub->setRequiresInitial (mRequireInitial);
        
    if (mSnapshot)
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_NORMAL);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_SNAPSHOT, 0);
    }
    else if (mGroupSubscription)
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_GROUP);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_REAL_TIME, 0);
    }
    else
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_NORMAL);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_REAL_TIME, 0);
    }
    
    sub->create (
        mTransport,
        mQueueGroup->getNextQueue (),
        (DisplayCallback*)mDisplayCallback,
        mSource,
        symbol,
        NULL);
    
    mSubscriptionList.push_back (sub);

    if (++howMany % 1000 == 0)
    {
        printf ("Subscribed to %d subjects.\n", howMany);
    }
}
Exemplo n.º 23
0
int LocalNodeInfo::unsubscribe (uint16 ui16ClientId, const char *pszGroupName, uint16 ui16Tag)
{
    char *pszOnDemandDataGroupName = getOnDemandDataGroupName (pszGroupName);
    if (pszOnDemandDataGroupName == NULL) {
        // The on-demand subscription group name could not be generated
        return -1;
    }
    _m.lock (306);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    int rc = 0;
    if (pSL == NULL) {
        rc = -2;
    }
    else {
        Subscription *pSub = pSL->getSubscription (pszGroupName);
        if (pSub == NULL) {
            rc = -3;
        }
        else {
            uint8 ui8SubscriptionType = pSub->getSubscriptionType();
            if ((ui8SubscriptionType == Subscription::GROUP_SUBSCRIPTION) && (ui16Tag == 0)) {
                if (pSL->removeGroup (pszGroupName)) {
                    rc = -4;
                }
                else {
                    if (pSL->removeGroup (pszOnDemandDataGroupName)) {
                        rc = -5;
                    }
                }
            }
            else if ((ui8SubscriptionType == Subscription::GROUP_TAG_SUBSCRIPTION) && (ui16Tag != 0)) {
                if (pSL->removeGroupTag (pszGroupName, ui16Tag)) {
                    rc = -6;
                }
                else {
                    if (pSL->removeGroupTag (pszOnDemandDataGroupName, ui16Tag)) {
                        rc = -7;
                    }
                }
            }
        }
    }
    if (rc == 0) {
        recomputeConsolidateSubsciptionList ();
    }
    free (pszOnDemandDataGroupName);
    _m.unlock (306);
    return rc;
}
Exemplo n.º 24
0
void MamaSymbolListSubscriber::subscribeToSymbols ()
{
    mQueueGroup           = new MamaQueueGroup (mThreads, mBridgeImpl);
    mSubscriptionCallback = new SubscriptionCallback (this);

    vector<string>::iterator i;
    for (i=mSubjectList.begin(); i != mSubjectList.end(); i++)
    {
        MamaSubscription* sub = NULL;
        sub = new MamaSubscription;
        string symbol = *(i);

        sub->create (mTransport,
                     mQueueGroup->getNextQueue (),
                     (SubscriptionCallback*)mSubscriptionCallback,
                     mSourceName,
                     symbol.c_str(),
                     NULL);

        mSubscriptionList.push_back (sub);
    }
}
Exemplo n.º 25
0
// [[Rcpp::export]]
SEXP subscribe_Impl(SEXP con_, std::vector<std::string> securities, std::vector<std::string> fields, Rcpp::Function fun,
                    SEXP options_, SEXP identity_) {

    // via Rcpp Attributes we get a try/catch block with error propagation to R "for free"
    Session* session =
        reinterpret_cast<Session*>(checkExternalPointer(con_, "blpapi::Session*"));

    const std::string mdsrv = "//blp/mktdata";
    if (!session->openService(mdsrv.c_str())) {
        Rcpp::stop("Failed to open " + mdsrv);
    }

    SubscriptionList subscriptions;

    // put fields into comma delimited format
    std::string fields_collapsed(vectorToCSVString(fields));
    std::string options_collapsed("");
    if(options_ != R_NilValue && Rf_length(options_)) {
        std::vector<std::string> options(Rcpp::as< std::vector<std::string> >(options_));
        options_collapsed = vectorToCSVString(options);
    }

    for(const std::string& security : securities) {
        CorrelationId cid(reinterpret_cast<void*>(const_cast<char *>(security.c_str())));
        subscriptions.add(security.c_str(),fields_collapsed.c_str(),options_collapsed.c_str(),cid);
    }

    // check if identity was passed, if so, use it
    if(identity_ != R_NilValue) {
        Identity* ip;
        ip = reinterpret_cast<Identity*>(checkExternalPointer(identity_,"blpapi::Identity*"));
        session->subscribe(subscriptions,*ip);
    } else {
        session->subscribe(subscriptions);
    }

    while (true) {
        Event event = session->nextEvent();
        Rcpp::checkUserInterrupt();
        MessageIterator msgIter(event);
        while (msgIter.next()) {
            Message msg = msgIter.message();
            const char *topic = (char *)msg.correlationId().asPointer();
            if (event.eventType() == Event::SUBSCRIPTION_STATUS ||
                    event.eventType() == Event::SUBSCRIPTION_DATA) {

                Rcpp::List ans;
                auto it = BlpapiEventToString.find(event.eventType());
                if(it==BlpapiEventToString.end()) {
                    throw Rcpp::exception("Unknown event type.");
                }
                ans["event.type"] = it->second;
                ans["topic"] = topic;
                ans["data"] = recursiveParse(msg.asElement());
                // call user function
                fun(ans);
            }
        }
    }
    return R_NilValue;
}
void MamaEntitle::removeSubscription (MamaSubscription* subscribed)
{
    mSubscriptionList.remove (subscribed);
}
bool MamaEntitle::hasSubscriptions ()
{
    return mSubscriptionList.empty ();
}