Ejemplo n.º 1
0
void deliverNotifyClientTask::handle(){
  TimeStatN ts;
  xml_document doc;
  if(!doc.load(_content.c_str())){
    MCE_WARN("PowerTransfer::deliverNotifyClient --> xml err, " <<_content);
    PowerTransferI::instance().UpCount(100000,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,4);
  } catch(Ice::Exception& e) {
    MCE_WARN("PowerTransfer::deliverNotifyClient-->TalkFunStateAdapter::getUserJids-->" << e);
    PowerTransferI::instance().UpCount(100000,0);
    return ;
  }
  MCE_INFO("PowerTransfer::deliverNotifyClient-->jmap:" << jmap.size());
  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] == 'T'){
        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 = NOTIFY2_MESSAGE;
        msg->msg = doc.xml();
        msgs.push_back(msg);
      }
    }
  }
  if(msgs.empty()){
    //MCE_INFO("PowerTransfer::deliverNotifyClient-->message is empty!");
    return;
  }
  try{
    TalkDeliverAdapter::instance().deliver(msgs);
  } catch(Ice::Exception& e) {
    MCE_WARN("PowerTransfer::deliverNotifyClient-->TalkDeliverAdapter::deliver-->" << e);
    PowerTransferI::instance().UpCount(100000,0);
    return ;
  }
  FunStatManager::instance().Stat("PowerTransfer::deliverNotifyClient", ts.getTime(), false);
  PowerTransferI::instance().UpCount(100000,1,msgs.size());
}
Ejemplo n.º 2
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());
}