Пример #1
0
Subscription * LocalNodeInfo::getSubscriptionForClient (uint16 ui16ClientId, const char *pszGroupName)
{
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        return NULL;
    }
    return pSL->getSubscription (pszGroupName);
}
Пример #2
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);
    }
}
Пример #3
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);
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
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;
}