FeedContentPtr FeedMemcContentI::GetFeed(Ice::Long id, const Ice::Current&) { // for UserProfileClient test only vector<Ice::Long> feedids; feedids.push_back(8373921129); FeedContentDict dict = FeedMemcClient::instance().GetFeedDict(feedids); FeedContentPtr content; content = dict[8373921129]; content->data->xml = "<f v=\"1.0\" type=\"blogPublish\"><time>1300185966866</time><type>601</type><from><id>257876975</id><name>远非</name><tinyimg>0/0/men_tiny.gif</tinyimg></from><blog><id>716684593</id><title>ooxxxwwoo</title><digest>&#23002;&#23452;&#19996;&#20998;&#20139;&#26446;&#22025;&#27427;&#30340;&#26085;&#24535;&#36716;&#65306;&#20854;&#23454;&#22823;&#23478;&#37117;&#34987;&#26085;&#26412;&#22320;&#38663;&#21560;&#24341;&#20102;&#30524;&#29699; &#30495;&#27491;&#26368;&#21361;&#38505;&#30340;&#26159;&#21152;&#24030; &#65288;&#20197;&#19979;&#20026;&#36716;&#36733;&#65289;&#26085;&#26412;&#36825;&#27425;&#29378;&#26292;&#30340;&#22320;&#38663;&#30495;&#30340;&#21560;&#24341;&#20102;&#22823;&#23478;&#30340;&#30524;&#29699;&#65292;&#25105;&#22269;&#30005;&#35270;&#21488;&#26356;&#26159;&#36830;&#31687;&#32047;&#29261;&#30340;&#25253;&#36947;&#20197;&#26399;&#36716;&#31227;&#22823;&#23478;&#23545;&#22269;&#20869;&#29616;&#29366;&#30340;&#19981;&#28385;&#12290;&#20854;&#23454;&#65292;&#22823;&#23478;&#38590;&#36947;&#24536;&#35760;&#20102;&#32654;&#22269;&#21152;&#24030;&#37027;&#22855;&#24618;&#27515;&#20129;&#30340;500&#19975;&#26465;&#40060;&#20102;&#21527;&#65311;&#25105;&#35748;&#20026;&#19981;&#36229;&#36807;&#19968;&#20010;&#26376;&#65292;&#21152;&#24030;&#23558;&#21457;&#29983;&#24046;&#19981;&#22810;9&#32423;&#30340;&#22320;&#38663;&#12290;&#20026;&#37027;&#20123;&#21363;&#23558;&#32633;&#38590;&#30340;&#20154;&#31048;&#31095;&#21543;&#65281;&#65281;&#65281;&#65281; &#27425;&#22768;&#27874;&#12290;&#12290;&#12290;&#36807;&#24378;&#30340;&#27425;&#22768;&#27874;...</digest><url>http://blog.renren.com/GetEntry.do?id=716684593&owner=257876975</url></blog></f>"; content->reply->oldReply = "<f><reply><id>1692426042</id><type>0</type><time>2011-03-15 18:51</time><body>"test1"</body><im><body>test1</body></im><from><id>238489851</id><name>袁飞</name><tinyimg>http://hdn.xnimg.cn/photos/hdn221/20110220/1735/tiny_2kcu_195010p019116.jpg</tinyimg><icon></icon></from></reply></f>"; content->reply->newReply = "<f><reply><id>1692426042</id><type>0</type><time>2011-03-15 18:51</time><body>"test2"</body><im><body>test2</body></im><from><id>238489851</id><name>袁飞</name><tinyimg>http://hdn.xnimg.cn/photos/hdn221/20110220/1735/tiny_2kcu_195010p019116.jpg</tinyimg><icon></icon></from></reply></f>"; FeedMemcClient::instance().SetFeed(content); return NULL; UserProfile profile; MCE_INFO("get profile : " << id ); bool b = UserProfileClient::instance().Get(id, &profile); if (b) { MCE_INFO("profile fields : " << " id " << profile.id() << " stage " << profile.stage() << " gender " << profile.gender() << " age " << profile.age() << " school " << profile.school() << " major " << profile.major() << " grade " << profile.grade() << " home_area " << profile.home_area() << "@" << profile.home_area().size() << " current_area " << profile.current_area() << "@" << profile.current_area().size() << " ip " << profile.ip() << " ip_area " << profile.ip_area() << "@" << profile.ip_area().size() ); } else { MCE_INFO("profile not found. id=" << id); } return FeedMemcClient::instance().GetFeed(id); };
FeedContentPtr MemcFeedTestI::GetFeed(Ice::Long id, const Ice::Current&) { // for UserProfileClient test only UserProfile profile; MCE_INFO("get profile : " << id ); bool b = UserProfileClient::instance().Get(id, &profile); if (b) { MCE_INFO("profile fields : " << " id " << profile.id() << " stage " << profile.stage() << " gender " << profile.gender() << " age " << profile.age() << " school " << profile.school() << " major " << profile.major() << " grade " << profile.grade() << " home_area " << profile.home_area() << "@" << profile.home_area().size() << " current_area " << profile.current_area() << "@" << profile.current_area().size() << " ip " << profile.ip() << " ip_area " << profile.ip_area() << "@" << profile.ip_area().size() ); } else { MCE_INFO("profile not found. id=" << id); } return FeedMemcClient::instance().GetFeed(id); };
bool AdNewGetRequest::response() { timeval start; gettimeofday(&start, NULL); if (!_fcgi_out) { MCE_WARN("remove notify fcgi_out null"); return false; } _login_uid = 2; string uid = getProperty("uid"); if (_cookies.find("id") != _cookies.end()) { uid = _cookies["id"]; } if (!uid.empty()) { try { _login_uid = boost::lexical_cast<int>(uid); } catch (...) { MCE_WARN("lexical_cast cookie id error : " << uid); } } string serialized; if (_login_uid > 0) { bool b = false; try { StatFunc stat("memc GetSerialized"); b = UserProfileClient::instance().GetSerialized(_login_uid, &serialized); } catch (std::exception& e) { MCE_WARN("UserProfileClient error : " << e.what() << " uid=" << _login_uid); } if (!b) { MCE_INFO("profile not found in memcache. id=" << _login_uid); try { StatFunc stat("memc AdUserCacheLoader"); serialized = AdUserCacheLoaderAdapter::instance().GetById(_login_uid); } catch (Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e << " uid=" << _login_uid); } catch (std::exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e.what() << " uid=" << _login_uid); } } } // FCGX_PutS("Content-type: application/x-javascript; charset=utf-8\r\n\r\n{}", _fcgi_out); // return true; UserProfile profile; if (serialized.empty()) { profile.set_stage(4); profile.set_gender(0); profile.set_age(25); profile.set_school(0); profile.set_major(0); profile.set_grade(0); profile.set_home_area(""); profile.set_current_area(""); } else { profile.ParseFromString(serialized); } unsigned int ip = ntohl(inet_addr(GetRemoteAddr().c_str())); profile.set_id(_login_uid); profile.set_ip(ip); profile.set_ip_area(IpAreaCache::instance().GetIpArea(ip)); profile.SerializeToString(&serialized); int rotate_slot = GetCookieInt("an_slot", rand()); rotate_slot %= 10000; AdResultMap ads; AdZone2Creatives final_ads; string referer = getProperty("ref"); //MCE_DEBUG("[UrlMaping] ref = " << referer); if (referer.empty() || referer.find("http://") == string::npos) { referer = getProperty("r"); if (referer.empty() || referer.find("http://") == string::npos) { referer = GetParamFix("HTTP_REFERER"); //MCE_DEBUG("[UrlMaping] HTTP_REFERER = " << referer); } } bool err_flag = false; bool hide = false; string isvip = getProperty("isvip"); string hideads = getProperty("hideads"); if(isvip.compare("true")==0 && hideads.compare("true")==0) { hide = true; } stringstream log_url; try { char sep = '&'; if (referer.find_first_of('?') == string::npos) { sep = '?'; } int refresh_source = getPropertyInt("refresh_source", 0); int refresh_idx = getPropertyInt("refresh_idx", 0); log_url << referer << sep << "refresh_source=" << refresh_source << "&refresh_idx=" << refresh_idx; stringstream stat_desc; stat_desc << _login_uid << " GetAds"; StatFunc stat(stat_desc.str()); } catch (Ice::Exception& e) { MCE_WARN("AdGetRequest::response error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdGetRequest::response : " << e.what() << " uid=" << _login_uid); err_flag = true; } // string emtag = "M"; MCE_DEBUG("debug 001"); try { ads = AdEngineBAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, hide); MCE_DEBUG("EngineB size=" << ads.size()); AdGateI::instance().translate(ads,final_ads); MCE_DEBUG("EngineB size=" << final_ads.size()); // emtag = "M"; } catch (Ice::Exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } MCE_DEBUG("debug 002"); bool tw_flag = false; string tag, photo; map<long, EngineTypes> self_zones; // 需要中小自助广告广告位id for(AdResultMap::iterator it = ads.begin(); it != ads.end(); it++) { if(!it->second.empty() && (it->second.at(0).groupid == -1)) { //台湾分尾号流量切分 //MCE_INFO("Get Ads from AdEngine/AdTw"); MCE_DEBUG("debug 003"); if(_login_uid%10 < 2 || _login_uid == 287341024) { self_zones[it->first] = TW; tw_flag = true; } else { self_zones[it->first] = ENGINE; } } else if(!it->second.empty() && (it->second.at(0).groupid == -2)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_1"; } else if(!it->second.empty() && (it->second.at(0).groupid == -3)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_2"; photo = "true"; MCE_DEBUG("photo = true"); } } MCE_DEBUG("debug 004"); if (!self_zones.empty()) { try { AdResultMap e_ads_; AdZone2Creatives e_ads; MCE_DEBUG("debug 005"); //台湾分尾号流量切分 if((_login_uid%10 < 2 || _login_uid == 287341024) && tw_flag) { MCE_DEBUG("debug 006"); MCE_DEBUG("[TW_DEBUG] AdGetRequest::response --> enter to request Tw"); e_ads_ = AdTwAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); AdGateI::instance().translate(ads,final_ads); } else { MCE_DEBUG("debug 007"); MCE_DEBUG("AdGetRequest::response --> from AdEngine rotate_slot = " << rotate_slot); UserAndAction ua; ua.id = profile.id(); ua.stage = profile.stage(); ua.gender = profile.gender(); ua.age = profile.age(); ua.school = profile.school(); ua.userMajor = profile.major(); ua.grade = profile.grade(); ua.homeArea = profile.home_area(); ua.currentArea = profile.current_area(); ua.ip = profile.ip(); ua.ipArea = profile.ip_area(); ua.actionType = ActionType::PAGEVIEW; AdRequest ad_request; ad_request.userAndAction = ua; ad_request.referer = referer; //url_mapping // set<Ice::Long> zone_ids; for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { long z_key = (*zit).first; if( photo == "true" && z_key == 100000000072 ) { ad_request.zoneDict[z_key] = 2; }else{ ad_request.zoneDict[z_key] = 0; } ad_request.attributes[boost::lexical_cast<string>(z_key)]=tag; } // AdUrlMaping::instance().GetAdZone(referer, ua.stage, zone_ids); //AdCreativeCache::instance().GetZoneDict(zone_ids, ad_request.zoneDict); MCE_DEBUG("AdGetRequest::response --> enter to request JavaServer"); e_ads_=AdEngineJAdapter::instance().Request(ad_request); AdGateI::instance().translate(e_ads_,e_ads); //e_ads = AdEngineUAdapter::instance().GetAdsByZone(serialized, log_url.str(), rotate_slot, _login_uid, tag); //e_ads_ = AdEngineUAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, _login_uid, tag, photo); } if (e_ads.empty()) { MCE_DEBUG("AdGetRequest::response --> from AdEngineJ empty "); } else { for(AdZone2Creatives::iterator xxit = e_ads.begin(); xxit != e_ads.end(); xxit++) { MCE_DEBUG("AdGetRequest::response --> from AdEngineJ" << xxit->second.size()); } } for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { AdZone2Creatives::iterator eit = e_ads.find(zit->first); if (eit != e_ads.end()) { //eads[zit->first] = eit->second; //在相册页面,如果广告位wb1成功展示自助,则去掉wb2位置的广告 /*if(100000000072 == zit->first) { ads[100000000073] = AdInfoSeq(); }*/ } else { ads[zit->first] = AdInfoSeq(); } } for(AdZone2Creatives::const_iterator ad_x_it = e_ads.begin() ; ad_x_it != e_ads.end() ; ad_x_it ++ ){ final_ads[ad_x_it->first] = ad_x_it->second; MCE_DEBUG("AdGetRequest::response --> from AdEngineJ " << ad_x_it->first <<" " <<ad_x_it->second.size()); if( ad_x_it->second.size() > 0 ) { for( int vi =0 ; vi < ad_x_it->second.size() ;vi ++ ) { MCE_DEBUG("widgetis = " << ad_x_it->second[vi].widgetid); } } } } catch (Ice::Exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } if (err_flag) { stringstream stat_desc; stat_desc << _login_uid << " PushDefault"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().PushDefault(_login_uid, profile.stage(), GetRemoteAddr(), referer, &ads); AdGateI::instance().translate(ads,final_ads); } stringstream ad_header; string ad_body; if (render_ == RT_HTML) { ad_header << "Content-type: text/html; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; AdCreativeCache::instance().Get(final_ads, &ad_body); MCE_INFO("final ad size : "<< final_ads.size()); } else if (render_ == RT_JSON) { ad_header << "Content-type: application/x-javascript; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; stringstream stat_desc; stat_desc << _login_uid << " GetJson"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().GetJson(referer, getPropertyInt( "refresh_source", 0), getPropertyInt("refresh_idx", 0), self_zones, final_ads, &ad_body); MCE_INFO("final ad size(json) : "<< final_ads.size()); } FCGX_PutS(ad_header.str().c_str(), _fcgi_out); FCGX_PutS(ad_body.c_str(), _fcgi_out); timeval end; gettimeofday(&end, NULL); AdGateI::instance().ping_sender_.Send("GetAds", 1000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000); return true; }