void MessageHandlerI::deliverFeed(const string& msg, const string& type, const MyUtil::IntSeq& ids, const Ice::Current&) { StatFunc statF("MessageHandlerI::deliverFeed"); //MCE_DEBUG("call MessageHandlerI::deliverFeed"); ostringstream os; os<< "<message type='headline' from='"<<type<<"@news.talk.xiaonei.com'>" << msg << "</message>"; xml_document doc; if (!doc.load(os.str().c_str())) { MCE_WARN("Parser xml err !!!"); return; } //TargetHandlerSeq res; JidSeqMap jmap; try{ jmap = OnlineCenterAdapter::instance().getUsersJids(ids); }catch(Ice::Exception& e){ MCE_WARN("MessageHandlerI::deliverFeed-->OnlineCenterAdapter::getUsersJids-->" << e); } MessageSeq seq; for (JidSeqMap::iterator it = jmap.begin(); it != jmap.end(); ++it) { for (size_t i = 0; i < it->second.size(); ++i) { if (it->second.at(i)->index <= 1) { // this user is old im client or web client, ignore this feed continue; } MessagePtr mPtr = new Message(); mPtr->from = new Jid(); mPtr->from->userId = -1; mPtr->from->endpoint = type; mPtr->from->index = -1; mPtr->to = it->second.at(i); mPtr->type = SYSTEM_MESSAGE; doc.child("message").append_attribute("to") = jidToString(it->second.at(i),false).c_str(); mPtr->msg = doc.xml(); seq.push_back(mPtr); if (it->second.at(i)->userId == 128487631) { MCE_DEBUG("NEWS:"<<mPtr->msg); } } } if (!seq.empty()) { //NotifyTaskManager::instance().addTargetHandler(res); MCE_DEBUG("send news to Dispatch list"); try{ TalkDeliverAdapter::instance().deliver(seq); }catch(Ice::Exception& e){ MCE_WARN("MessageHandlerI::deliverFeed-->TalkDeliverAdapter::deliver-->" << e); } } //NotifyTaskManager::instance().addNotify(new Notify< std::pair<string,MyUtil::IntSeq>,FeedNotifyHandler>(std::make_pair(msg,ids))); }
void DeliverFeedTask::handle() { const string FuncName = "DeliverFeedTask::handle"; TimeStatN ts; MCE_INFO("PowerTransferI::deliverFeedWithFocusFriend-> feed actor:" << feed_->actor); if(!XmlParas()) return; JidSeqMap jmap; try { jmap = TalkFunStateAdapter::instance().getUsersJids(target_,22); } catch (Ice::Exception& e) { MCE_WARN(FuncName << "-->TalkFunStateAdapter::getUsersJids-->" << target_.size() << " " << e); return; } catch (...) { MCE_WARN(FuncName << "-->TalkFunStateAdapter::getUsersJids--> err: " << target_.size()); return; } DeliverFeedInit(); for(JidSeqMap::const_iterator it = jmap.begin(); it != jmap.end(); ++it) { for(size_t j = 0; j < it->second.size(); ++j) { if (it->second.at(j)->endpoint.empty()) continue; if(it->second.at(j)->endpoint[0] == 'T') { client_jids_.push_back(jidToString(it->second.at(j))); if(client_jids_.size() > 500) Send2Proto(client_jids_, msg2client_); } else if(it->second.at(j)->endpoint[0] == 'W') { if(focus_friends_.find(it->first) != focus_friends_.end()) { webpager_focus_jids_.push_back(jidToString(it->second.at(j))); if(webpager_focus_jids_.size() > 500) Send2Proto(webpager_focus_jids_, msg2webpager_focus_); } else { webpager_unfocus_jids_.push_back(jidToString(it->second.at(j))); if(webpager_unfocus_jids_.size() > 500) Send2Proto(webpager_unfocus_jids_, msg2webpager_unfocus_); } } else if(string::npos != it->second.at(j)->endpoint.find("PTalkProxy")) { if(PowerTransferI::instance().IsDeliver2PTalkproxy(feed_->type & 0xFFFF)) { phone_jids_.push_back(jidToString(it->second.at(j))); if(phone_jids_.size() > 500) Send2Proto(phone_jids_, msg2phone_); } } } } Send2Proto(client_jids_, msg2client_); Send2Proto(phone_jids_, msg2phone_); Send2Proto(webpager_focus_jids_, msg2webpager_focus_); Send2Proto(webpager_unfocus_jids_, msg2webpager_unfocus_); FunStatManager::instance().Stat(FuncName, ts.getTime(), (ts.getTime() > 500.0)); }
void deliverNotifyWebpagerTask::handle(){ TimeStatN ts; MessageSeq msgs; bool is_feed_actor = false; Ice::Long nid = 0; if(_content.find("ugc_content") != string::npos){ is_feed_actor = true; } size_t npos = _content.find("\"nid\":\""); if(npos != string::npos){ size_t ipos = _content.find_first_of("\"", npos + 7); if(ipos != string::npos){ string snid = _content.substr(npos+7, ipos - (npos+7)); try{ nid = boost::lexical_cast<Ice::Long>(snid); }catch(...){ MCE_WARN("PowerTransfer::deliverNotifyWebpager--> boost cast nid error nid = " << nid); } } } JidSeqMap jmap; try{ jmap = TalkFunStateAdapter::instance().getUsersJids(_toids,2); } catch(Ice::Exception& e) { MCE_WARN("PowerTransfer::deliverNotifyWebpager-->TalkFunStateAdapter::getUserJids-->" << e); PowerTransferI::instance().UpCount(200000,0); return ; } for(JidSeqMap::iterator jit = jmap.begin();jit != jmap.end();++jit) { JidSeq& jseq = (jit->second); for(int j=0; j<(int)jseq.size(); j++){ if(jseq.at(j)->endpoint[0] == 'W'){ MessagePtr msg = new Message(); JidPtr jfrom = new Jid(); jfrom->userId = 0; jfrom->endpoint = "feed.talk.xiaonei.com"; jfrom->index = -1; ostringstream os; os << "<message type='common' from='" << jidToString(jfrom) << "' to='" << jidToString(jseq.at(j)) << "'>" << "</message>"; xml_document doc; if(!doc.load(os.str().c_str())){ continue; } xml_node body = doc.child("message").append_child(); body.set_name("body"); body.append_child(node_pcdata).set_value(_content.c_str()); msg->from = jfrom; msg->to = jseq.at(j); msg->type = NOTIFY2_MESSAGE; msg->msg = doc.xml(); msgs.push_back(msg); } } } if(msgs.empty()){ PowerTransferI::instance().UpCount(200000,0); return; } ostringstream os; for(IntSeq::iterator idit = _toids.begin(); idit != _toids.end(); ++idit){ os << (*idit) << " "; } try{ MCE_INFO("PowerTransfer::deliverNotifyWebpager--> is_feed_actor = " << is_feed_actor << " nid : " << nid << " toids.size :" << _toids.size() << " toids : " << os.str()); TalkDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyWebpager-->TalkDeliverAdapter::deliver--> " << e); PowerTransferI::instance().UpCount(200000,0); return ; } FunStatManager::instance().Stat("PowerTransfer::deliverNotifyWebpager", ts.getTime(), false); PowerTransferI::instance().UpCount(200000,1,msgs.size()); }
void deliverNotifyPhoneTask::handle(){ TimeStatN ts; xml_document doc; if(!doc.load(_content.c_str())){ MCE_WARN("PowerTransfer::deliverNotifyPhone --> xml err, " <<_content); PowerTransferI::instance().UpCount(300000,0); return; } Ice::Long nid = 0; size_t npos = _content.find("\"nid\":\""); if(npos != string::npos){ size_t ipos = _content.find_first_of("\"", npos + 7); if(ipos != string::npos){ string snid = _content.substr(npos+7, ipos - (npos+7)); try{ nid = boost::lexical_cast<Ice::Long>(snid); }catch(...){ MCE_WARN("PowerTransfer::deliverNotifyClient--> boost cast nid error nid = " << nid); } } } MessageSeq msgs; JidSeqMap jmap; try{ jmap = TalkFunStateAdapter::instance().getUsersJids(_toids,16); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyPhone-->TalkFunStateAdapter::getUserJids--> " << e); PowerTransferI::instance().UpCount(300000,0); return ; } for(JidSeqMap::iterator jit = jmap.begin();jit != jmap.end();++jit) { JidSeq& jseq = (jit->second); for(int j=0; j<(int)jseq.size(); j++){ if(jseq.at(j)->endpoint[0] == 'P'){ MessagePtr msg = new Message(); JidPtr jfrom = new Jid(); jfrom->userId = 0; jfrom->endpoint = "feed.talk.xiaonei.com"; jfrom->index = -1; doc.child("message").append_attribute("to") = jidToString(jseq.at(j)).c_str(); msg->from = jfrom; msg->to = jseq.at(j); msg->type = PHONE_NOTIFY; msg->msg = doc.xml(); msgs.push_back(msg); } } } if(msgs.empty()){ PowerTransferI::instance().UpCount(300000,0); return; } try{ TalkDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyPhone-->TalkDeliverAdapter::deliver-->" << e); PowerTransferI::instance().UpCount(300000,0); } FunStatManager::instance().Stat("PowerTransfer::deliverNotifyPhone", ts.getTime(), false); PowerTransferI::instance().UpCount(300000,1,msgs.size()); }