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); } }
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; }