コード例 #1
0
ファイル: MessageHandlerI.cpp プロジェクト: bradenwu/oce
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)));
}
コード例 #2
0
ファイル: FeedTransfer.cpp プロジェクト: gunner14/old_rr_code
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));
}
コード例 #3
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);
		}
	}
}
コード例 #4
0
ファイル: RoomPool.cpp プロジェクト: bradenwu/oce
MucActiveUserSeq RoomPool::GetRoomActiveUserSeq(const MucRoomIdPtr& roomid){
  MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> ROOMNAME = " << roomid->roomname);
  RoomMemberListPtr rmlptr;
  MucActiveUserSeq ans;

  MyUtil::IntSeq userids;
  rmlptr = GetMemberList(roomid);
  if(rmlptr){
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
		userids = rmlptr->GetAllMembersSeq();
  }
  if(userids.empty()){
		MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> userids is empty so return");
    return ans;
  }
	JidSeqMap jseqmap;
	try{
	  MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> call OnlineCenterAdapter.getUsersJids userids.size = " << userids.size());
  	jseqmap = OnlineCenterAdapter::instance().getUsersJids(userids);
	}
	catch(Ice::Exception& e){
		MCE_WARN("RoomPool::GetRoomActiveUserSeq-->OnlineCenter::getUserJids-->line:"<<__LINE__<<" err:"<<e);
	}
	catch(std::exception& e){
		MCE_WARN("RoomPool::GetRoomActiveUserSeq--> call OnlineCenter.getUserJids ERR  line:"<<__LINE__<<" err:"<<e.what());
	}
  if(jseqmap.empty()){
    return ans;
  }
	TalkUserMap uinfoPtr;
	try{
		uinfoPtr = TalkCacheClient::instance().GetUserBySeqWithLoad(0, userids);
	}catch(Ice::Exception& e){
		MCE_WARN("RoomPool::GetRoomActiveUserSeq-->TalkCacheClient::GetUserBySeqWithLoad-->error:" << e);
	}
  MyUtil::IntSeq::iterator uidit = userids.begin();
  for(; uidit != userids.end(); ++uidit){
    int userid = (*uidit);
    JidSeqMap::const_iterator jit = jseqmap.find(userid);
    if(jit == jseqmap.end()){
      continue;
    }

    Permisions permision = PMember;
		try{
		  MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> CALL MucUserRoomAdapter.GetMemberPermision(" << userid << ", " << roomid->roomname << ")");
			MucMemberPtr m = MucUserRoomAdapter::instance().GetMemberPermision(userid, roomid);
			if(m){
				permision = m->permision;
			}
			else{
				MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> CALL MucUserRoomAdapter.GetMemberPermision's return is NULL, it means the user is not in the room so continue!");
				continue;
			}
		}
		catch(Ice::Exception& e){
			MCE_WARN("RoomPool::GetRoomActiveUserSeq-->MucUserRoom::GetMemberPermision-->line:"<<__LINE__<<" err:"<<e);
		}
		catch(std::exception& e){
			MCE_WARN("RoomPool::GetRoomActiveUserSeq--> call MucUserRoom.GetMemberPermision ERR  line:"<<__LINE__<<" err:"<<e.what());
		}

    string nickname = "";
    TalkUserMap::iterator infoit = uinfoPtr.find(userid);
    if(infoit == uinfoPtr.end()){
      //取不到用户的名称,默认用id 
      try{
        nickname = boost::lexical_cast<string>(userid);
      }
      catch (exception& e){
        MCE_WARN("RoomPool::GetRoomActiveUserSeq-->boost::lexical_cast to string exception  val = " << userid);
      }
    }
    else{
      TalkUserPtr u = infoit->second;
      nickname = u->name;
    }


    for (size_t index = 0; index < jit->second.size(); ++index) {
      char endpoint = jit->second.at(index)->endpoint[0];
      if(endpoint != 'T' && endpoint != 'W'){
        continue;
      }
      MucRoomIdPtr roomid = new MucRoomId();
      roomid->roomname = rmlptr->_roomname;
      roomid->domain = MUCDOMAIN;
      MucUserIdentityPtr identity = new MucUserIdentity();
      identity->roomid = roomid;
      identity->nickname = makeMucNickname(jit->second.at(index), nickname);
      identity->userid = userid;
      MucActiveUserPtr activeuserptr = new MucActiveUser();
      activeuserptr->jid = jit->second.at(index);
      activeuserptr->identity = identity;
      activeuserptr->permision = permision;
      ans.push_back(activeuserptr);
    }
  }
  MCE_DEBUG("RoomPool::GetRoomActiveUserSeq --> roomname = " << roomid->roomname << " ans.size = " << ans.size());
  return ans;
}
コード例 #5
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());
}
コード例 #6
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());
}
コード例 #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());
}