Exemplo n.º 1
0
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)));
}
Exemplo n.º 2
0
void NoticePipe::handle(const ObjectSeq& objs){
	MessageSeq msgs;
	IntSeq ids;

	for (size_t i = 0; i < objs.size(); ++i) {
		MessagePtr m = MessagePtr::dynamicCast(objs.at(i));
		msgs.push_back(m);
		ids.push_back(m->to->userId);
	}
	JidSeqMap jmap;
	try{
		//jmap = OnlineCenterAdapter::instance().getUsersJids(ids);
		jmap = TalkFunStateAdapter::instance().getUsersJids(ids);
	}catch(Ice::Exception& e){
		//MCE_WARN("NoticePipe::handle --> call OnlineCenterAdapter.getUsersJids error : " << e);
		MCE_WARN("NoticePipe::handle --> call TalkFunStateAdapter.getUsersJids error : " << e);
	}
	MessageSeq res;
	for (size_t i = 0; i < msgs.size(); ++i) {
		JidSeqMap::iterator it = jmap.find(msgs.at(i)->to->userId);
		if (it == jmap.end()) {
			continue;
		}
		for (size_t j = 0; j < it->second.size(); ++j) {
			if (it->second.at(j)->endpoint.size() > 1
					&& it->second.at(j)->endpoint[0] == 'T') {
				MessagePtr m = new Message();
				m->from = new Jid();
				m->from->userId = -1;
				m->from->endpoint = "appnotice.talk.xiaonei.com";
				m->from->index = -1;
				m->to = it->second.at(j);
				m->type = msgs.at(i)->type;
				m->msg = msgs.at(i)->msg;

				res.push_back(m);
			}

		}
	}
	if (!res.empty()) {
		MCE_INFO("NoticePipe::handle --> Notice size:"<<res.size());
		try{
			TalkDeliverAdapter::instance().deliver(res);
		}catch(Ice::Exception& e){
			MCE_WARN("NoticePipe::handle --> call TalkDeliverAdapter.deliver error : " << e);
		}
	}
}
Exemplo n.º 3
0
void DeliverManagerI::deliver(const MessageSeq& seq, const Ice::Current& current) {
	//TaskManager::instance().execute(new MessageTask(seq));
	//MCE_DEBUG("DeliverManagerI::deliver --> seq.size="<<seq.size());
	if (!seq.empty()) {
		if (seq.at(0)->to->userId == 128487631 || seq.at(0)->to->userId == 200865373) {
			//MCE_DEBUG("DeliverManagerI::deliver --> msg:"<< seq.at(0)->msg);
		}
	}
	for(MessageSeq::const_iterator it = seq.begin(); it != seq.end(); ++it){
		MessagePtr m = (*it);
		if(m->type == MESSAGE){
			MCE_INFO("DeliverManagerI::deliver message-->from=" << jidToString(m->from) << " to=" << jidToString(m->to));
		}
		if(m->type == NOTIFY2_MESSAGE){
			MCE_INFO("DeliverManagerI::deliver notify2-->from=" << jidToString(m->from) << " to=" << jidToString(m->to));
		}
	}
	for (size_t i = 0; i < seq.size(); ++i) {
		PipePool::instance().push("TalkRight", abs(seq.at(i)->to->userId)%10, seq.at(i));
	}
}
Exemplo n.º 4
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());
}
Exemplo n.º 5
0
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());
}
Exemplo n.º 6
0
void MucDeliverAdapter::deliver(const MessageSeq& seq) {
    if(seq.empty()) {
        return;
    }
    getManagerOneway(seq.at(0)->to->userId)->deliver(seq);
}
Exemplo n.º 7
0
void FeedReplyPipe::handle(){
	FeedReplyToMessagConverter converter;
	TimeStat ts;
	float totalwait = 0.0;
	FeedReplyWithTargetSeq objs;
	WTransitManagerI::instance().SwapFeedReplySeq(objs);
	if(objs.empty()){
		return;
	}
	//for(size_t x = 0; x < objs.size(); ++x){
		//FeedReplyWithTargetPtr reply = FeedReplyWithTargetPtr::dynamicCast(objs.at(x));
		//FeedReplyWithTargetPtr reply = objs.at(x);
		//totalwait += reply->latets.getTime();
	//}
	MessageSeq msgs;
	for (size_t x = 0; x < objs.size(); ++x) {
		//FeedReplyWithTargetPtr reply = FeedReplyWithTargetPtr::dynamicCast(objs.at(x));
		FeedReplyWithTargetPtr reply = objs.at(x);
		converter.setData(reply->replyData);
		if(reply->replyData->actor == 257876975 || reply->replyData->actor == 238489851){
			//MCE_DEBUG(reply->replyData->actor << " " << reply->replyData->xml);
		}
//		MyUtil::IntSeq target = reply->getTarget();
		MCE_DEBUG(" FeedReplyPipe::handle --> feed->target.size = "<< reply->target.size());
		JidSeqMap jmap;
	
		try {
			//jmap = OnlineCenterAdapter::instance().getUsersJids(reply->target);
			jmap = TalkFunStateAdapter::instance().getUsersJids(reply->target, 22);
		} catch (Ice::Exception& e) {
			MCE_WARN("FeedReplyPipe::handle-->TalkFunStateAdapter::getUsersJids-->" << reply->replyData->actor << " " << reply->target.size() << " "<<e);
		} catch (std::exception& e) {
			MCE_WARN("FeedReplyPipe::handle --> online center err: " << reply->target.size() << " "<<e.what());
		}
		if (jmap.empty()) {
			MCE_DEBUG("FeedReplyPipe::handle --> no friend online  ");
			continue;
		}
		MCE_DEBUG("FeedReplyPipe::handle --> jmap.size = "<<jmap.size());
		
		for (size_t i = 0; i < reply->target.size(); ++i) {
			JidSeqMap::const_iterator it = jmap.find(reply->target.at(i));
			if (it == jmap.end()) {
				MCE_DEBUG("FeedReplyPipe::handle --> can not find jmap feed->target(i)="<<reply->target.at(i));
				continue;
			}
			for (size_t j = 0; j < it->second.size(); ++j) {
				MessagePtr msg;
				if ( (!it->second.at(j)->endpoint.empty()) ){
					if( it->second.at(j)->endpoint[0] == 'T' ){
					  //MCE_DEBUG("FeedReplyPipe::handle-->SEND REPLY source=" << reply->replyData->source << " actor=" << reply->replyData->actor << " replyid=" << reply->replyData->replyId << " to userid=" << it->second.at(j)->userId);
						msg = converter.getToTalkMessage(it->second.at(j));
					}
					if(msg){
						msgs.push_back(msg);
					}
				}
			}
		}
	}
	if (!msgs.empty()) {
		try{
			TalkDeliverAdapter::instance().deliver(msgs);
		}catch(Ice::Exception& e){
			MCE_WARN("FeedReplyPipe::handle --> TalkDeliverAdapter::deliver--> error : " << e);
		}
	}
	MONITOR("SignForTimeuse::WTransit::FeedReplyPipe::handle-->" << ts.getTime() << "|" << "count" << objs.size());
}