added regular test of circle auto-subscribe from cache, and auto-subscribe when submitting a membership request

This commit is contained in:
csoler 2016-05-29 16:09:56 -04:00
parent 2bde81f210
commit cbef01451c
4 changed files with 63 additions and 40 deletions

View file

@ -188,7 +188,7 @@ void p3GxsCircles::service_tick()
time_t now = time(NULL);
if(now > mLastCacheMembershipUpdateTS + GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE)
{
p3GxsCircles::checkCircleCacheForMembershipUpdate();
checkCircleCache();
mLastCacheMembershipUpdateTS = now ;
}
return;
@ -1194,11 +1194,17 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
return true;
}
bool p3GxsCircles::checkCircleCacheForMembershipUpdate()
bool p3GxsCircles::checkCircleCache()
{
#warning TODO. Should go over existing cache entries and update/process the membership requests
std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl;
return false ;
#ifdef DEBUG_CIRCLES
std::cerr << "checkCircleCache(): calling auto-subscribe check and membership update check." << std::endl;
#endif
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.applyToAllCachedEntries(*this,&p3GxsCircles::locked_checkCircleCacheForAutoSubscribe) ;
// mCircleCache.applyToAllCachedEntries(*this,&p3GxsCircles::locked_checkCircleCacheForMembershipUpdate) ;
return true ;
}
bool p3GxsCircles::locked_checkCircleCacheForMembershipUpdate(RsGxsCircleCache& cache)
@ -1934,8 +1940,11 @@ bool p3GxsCircles::pushCircleMembershipRequest(const RsGxsId& own_gxsid,const Rs
std::cerr << " AuthorId : " << s->meta.mAuthorId << std::endl;
std::cerr << " ThreadId : " << s->meta.mThreadId << std::endl;
#endif
uint32_t token ;
if(request_type == RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_SUBSCRIBE)
RsGenExchange::subscribeToGroup(token, RsGxsGroupId(circle_id), true);
RsGenExchange::publishMsg(token, s);
// update the cache.

View file

@ -247,7 +247,7 @@ virtual RsServiceInfo getServiceInfo();
bool cache_load_for_token(uint32_t token);
bool cache_reloadids(const RsGxsCircleId &circleId);
bool checkCircleCacheForMembershipUpdate();
bool checkCircleCache();
bool locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache);
bool locked_processLoadingCacheEntry(RsGxsCircleCache &cache);

View file

@ -52,10 +52,10 @@
template<class Key, class Value> class RsMemCache
{
public:
public:
RsMemCache(uint32_t max_size = DEFAULT_MEM_CACHE_SIZE, std::string name = "UnknownMemCache")
:mDataCount(0), mMaxSize(max_size), mName(name)
:mDataCount(0), mMaxSize(max_size), mName(name)
{
clearStats();
return;
@ -69,7 +69,11 @@ template<class Key, class Value> class RsMemCache
bool resize(); // should be called periodically to cleanup old entries.
private:
// Apply a method of a given class ClientClass to all cached data. Can be useful...
template<class ClientClass> bool applyToAllCachedEntries(ClientClass& c,bool (ClientClass::*method)(Value&));
private:
bool update_lrumap(const Key &key, time_t old_ts, time_t new_ts);
bool discard_LRU(int count_to_clear);
@ -77,24 +81,24 @@ template<class Key, class Value> class RsMemCache
// internal class.
class cache_data
{
public:
public:
cache_data() { return; }
cache_data(Key in_key, Value in_data, time_t in_ts)
:key(in_key), data(in_data), ts(in_ts) { return; }
:key(in_key), data(in_data), ts(in_ts) { return; }
Key key;
Value data;
time_t ts;
};
std::map<Key, cache_data > mDataMap;
std::multimap<time_t, Key> mLruMap;
uint32_t mDataCount;
std::map<Key, cache_data > mDataMap;
std::multimap<time_t, Key> mLruMap;
uint32_t mDataCount;
uint32_t mMaxSize;
std::string mName;
// some statistics.
void printStats(std::ostream &out);
void printStats(std::ostream &out);
void clearStats();
mutable uint32_t mStats_inserted;
@ -129,6 +133,15 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
}
template<class Key, class Value> template<class ClientClass> bool RsMemCache<Key, Value>::applyToAllCachedEntries(ClientClass& c, bool (ClientClass::*method)(Value&))
{
bool res = true ;
for(typename std::map<Key,cache_data>::iterator it(mDataMap.begin());it!=mDataMap.end();++it)
res = res && ((c.*method)(it->second.data)) ;
return res ;
}
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value &data)
{