//------------------------------------------------------------------------------------- void GlobalDataClient::onDataChanged(std::string& key, std::string& value, bool isDelete) { Components::COMPONENTS& channels = Components::getSingleton().getComponents(serverComponentType_); Components::COMPONENTS::iterator iter1 = channels.begin(); uint8 dataType = dataType_; ArraySize slen = 0; for(; iter1 != channels.end(); iter1++) { Mercury::Channel* lpChannel = iter1->pChannel; KBE_ASSERT(lpChannel != NULL); Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(DbmgrInterface::onBroadcastGlobalDataChange); (*pBundle) << dataType; (*pBundle) << isDelete; slen = key.size(); (*pBundle) << slen; (*pBundle).assign(key.data(), slen); if(!isDelete) { slen = value.size(); (*pBundle) << slen; (*pBundle).assign(value.data(), slen); } (*pBundle) << g_componentType; (*pBundle).send(*lpChannel->endpoint()); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } }
//------------------------------------------------------------------------------------- void GlobalDataServer::broadcastDataChange(Mercury::Channel* pChannel, COMPONENT_TYPE componentType, const std::string& key, const std::string& value, bool isDelete) { INFO_MSG(boost::format("GlobalDataServer::broadcastDataChange: writer(%1%), key_size=%2%, val_size=%3%, isdelete=%4%.\n") % COMPONENT_NAME_EX(componentType) % key.size() % value.size() % (int)isDelete); std::vector<COMPONENT_TYPE>::iterator iter = concernComponentTypes_.begin(); for(; iter != concernComponentTypes_.end(); iter++) { COMPONENT_TYPE ct = (*iter); Components::COMPONENTS& channels = Components::getSingleton().getComponents(ct); Components::COMPONENTS::iterator iter1 = channels.begin(); for(; iter1 != channels.end(); iter1++) { Mercury::Channel* lpChannel = iter1->pChannel; KBE_ASSERT(lpChannel != NULL); if(pChannel == lpChannel) continue; Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); switch(dataType_) { case GLOBAL_DATA: if(componentType == CELLAPP_TYPE) { (*pBundle).newMessage(CellappInterface::onBroadcastGlobalDataChange); } else if(componentType == BASEAPP_TYPE) { (*pBundle).newMessage(BaseappInterface::onBroadcastGlobalDataChange); } else { KBE_ASSERT(false && "componentType is error!\n"); } break; case GLOBAL_BASES: (*pBundle).newMessage(BaseappInterface::onBroadcastGlobalBasesChange); break; case CELLAPP_DATA: (*pBundle).newMessage(CellappInterface::onBroadcastCellAppDataChange); break; default: KBE_ASSERT(false && "dataType is error!\n"); break; }; (*pBundle) << isDelete; ArraySize slen = key.size(); (*pBundle) << slen; (*pBundle).assign(key.data(), slen); if(!isDelete) { slen = value.size(); (*pBundle) << slen; (*pBundle).assign(value.data(), slen); } (*pBundle).send(*lpChannel->endpoint()); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } } }