Commit 45bafea1 authored by Pavel Vainerman's avatar Pavel Vainerman

(UInterface): убрал использование "дорогого" timestamp в кэше, перешёл на подсчёт обращений.

parent b6bccc10
...@@ -256,12 +256,12 @@ class UInterface ...@@ -256,12 +256,12 @@ class UInterface
class CacheOfResolve class CacheOfResolve
{ {
public: public:
CacheOfResolve(unsigned int maxsize, int cleantime): CacheOfResolve( unsigned int maxsize, int cleancount=20 ):
MaxSize(maxsize), CleanTime(cleantime){}; MaxSize(maxsize), minCallCount(cleancount){};
~CacheOfResolve(){}; ~CacheOfResolve(){};
UniSetTypes::ObjectPtr resolve( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const throw(UniSetTypes::NameNotFound); UniSetTypes::ObjectPtr resolve( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const throw(UniSetTypes::NameNotFound);
void cache( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node, UniSetTypes::ObjectVar ptr )const; void cache( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node, UniSetTypes::ObjectVar ptr ) const;
void erase( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const; void erase( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const;
inline void setMaxSize( unsigned int ms ) inline void setMaxSize( unsigned int ms )
...@@ -269,66 +269,37 @@ class UInterface ...@@ -269,66 +269,37 @@ class UInterface
MaxSize = ms; MaxSize = ms;
}; };
// void setCleanTime();
protected: protected:
CacheOfResolve(){}; CacheOfResolve(){};
private: private:
bool clean(); /*!< функция очистки кэш-а от старых ссылок */ bool clean(); /*!< функция очистки кэш-а от старых ссылок */
inline void clear() /*!< удаление всей информации */ inline void clear() /*!< удаление всей информации */
{ {
UniSetTypes::uniset_rwmutex_wrlock l(cmutex); UniSetTypes::uniset_rwmutex_wrlock l(cmutex);
mcache.clear(); mcache.clear();
}; };
/*!
\todo можно добавить поле CleanTime для каждой ссылки отдельно...
*/
struct Info struct Info
{ {
Info( UniSetTypes::ObjectVar ptr, time_t tm=0 ): Info( UniSetTypes::ObjectVar ptr ):ptr(ptr),ncall(0){}
ptr(ptr) Info():ptr(NULL),ncall(0){}
{
if(!tm)
timestamp = time(NULL);
}
Info():
ptr(NULL), timestamp(0){};
UniSetTypes::ObjectVar ptr; UniSetTypes::ObjectVar ptr;
time_t timestamp; // время последнего обращения unsigned long ncall; // счётчик обращений
bool operator<( const CacheOfResolve::Info& rhs ) const bool operator<( const CacheOfResolve::Info& rhs ) const
{ {
return this->timestamp < rhs.timestamp; return this->ncall > rhs.ncall;
} }
}; };
typedef std::map<int, Info> CacheMap; typedef std::map<int, Info> CacheMap;
mutable CacheMap mcache; mutable CacheMap mcache;
mutable UniSetTypes::uniset_rwmutex cmutex; mutable UniSetTypes::uniset_rwmutex cmutex;
unsigned int MaxSize; /*!< максимальный размер кэша */ unsigned int MaxSize; /*!< максимальный размер кэша */
unsigned int CleanTime; /*!< период устаревания ссылок [мин] */ unsigned int minCallCount; /*!< минимальное количество вызовов, меньше которого ссылка считается устаревшей */
/*
// В последствии написать функцию для использования
// remove_if
typedef std::pair<int, Info> CacheItem;
// функция-объект для поиска устаревших(по времени) ссылок
struct OldRef_eq: public unary_function<CacheItem, bool>
{
OldRef_eq(time_t tm):tm(tm){}
bool operator()( const CacheItem& inf ) const
{
return inf.timestamp < tm;
}
time_t tm;
};
*/
}; };
void initBackId( UniSetTypes::ObjectId backid ); void initBackId( UniSetTypes::ObjectId backid );
......
...@@ -44,7 +44,7 @@ UInterface::UInterface( const UniSetTypes::Configuration* _uconf ): ...@@ -44,7 +44,7 @@ UInterface::UInterface( const UniSetTypes::Configuration* _uconf ):
rep(_uconf), rep(_uconf),
myid(UniSetTypes::DefaultObjectId), myid(UniSetTypes::DefaultObjectId),
orb(CORBA::ORB::_nil()), orb(CORBA::ORB::_nil()),
rcache(100,5), rcache(100,20),
oind(_uconf->oind), oind(_uconf->oind),
uconf(_uconf) uconf(_uconf)
{ {
...@@ -55,7 +55,7 @@ UInterface::UInterface( const ObjectId backid, CORBA::ORB_var orb, ObjectIndex* ...@@ -55,7 +55,7 @@ UInterface::UInterface( const ObjectId backid, CORBA::ORB_var orb, ObjectIndex*
rep(UniSetTypes::conf), rep(UniSetTypes::conf),
myid(backid), myid(backid),
orb(orb), orb(orb),
rcache(200,120), rcache(200,40),
oind(_oind), oind(_oind),
uconf(UniSetTypes::conf) uconf(UniSetTypes::conf)
{ {
...@@ -470,7 +470,7 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c ...@@ -470,7 +470,7 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c
{ {
if( backid==UniSetTypes::DefaultObjectId ) if( backid==UniSetTypes::DefaultObjectId )
backid = myid; backid = myid;
if( backid==UniSetTypes::DefaultObjectId ) if( backid==UniSetTypes::DefaultObjectId )
throw UniSetTypes::IOBadParam("UI(askRemoteSensor): unknown back ID"); throw UniSetTypes::IOBadParam("UI(askRemoteSensor): unknown back ID");
...@@ -485,14 +485,14 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c ...@@ -485,14 +485,14 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c
oref = rcache.resolve(name, node); oref = rcache.resolve(name, node);
} }
catch( NameNotFound ){} catch( NameNotFound ){}
for (unsigned int i=0; i<uconf->getRepeatCount(); i++) for (unsigned int i=0; i<uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( name, node ); oref = resolve( name, node );
IONotifyController_i_var inc = IONotifyController_i::_narrow(oref); IONotifyController_i_var inc = IONotifyController_i::_narrow(oref);
IOController_i::SensorInfo_var si; IOController_i::SensorInfo_var si;
si->id = name; si->id = name;
...@@ -507,8 +507,8 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c ...@@ -507,8 +507,8 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c
catch(CORBA::TRANSIENT){} catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){} catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){} catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch(UniSetTypes::TimeOut){} catch(UniSetTypes::TimeOut){}
...@@ -524,30 +524,30 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c ...@@ -524,30 +524,30 @@ void UInterface::askRemoteSensor( const ObjectId name, UniversalIO::UIOCommand c
} }
catch(ORepFailed) catch(ORepFailed)
{ {
rcache.erase(name, node); rcache.erase(name, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw UniSetTypes::IOBadParam(set_err("UI(askSensor): resolve failed ",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(askSensor): resolve failed ",name,node));
} }
catch(CORBA::NO_IMPLEMENT) catch(CORBA::NO_IMPLEMENT)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(askSensor): method no implement",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(askSensor): method no implement",name,node));
} }
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(askSensor): object not exist",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(askSensor): object not exist",name,node));
} }
catch(CORBA::COMM_FAILURE& ex) catch(CORBA::COMM_FAILURE& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(askSensor): ошибка системы коммуникации" << endl; // uwarn << "UI(askSensor): ошибка системы коммуникации" << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(askSensor): CORBA::SystemException" << endl; // uwarn << "UI(askSensor): CORBA::SystemException" << endl;
} }
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::TimeOut(set_err("UI(askSensor): Timeout",name,node)); throw UniSetTypes::TimeOut(set_err("UI(askSensor): Timeout",name,node));
...@@ -582,7 +582,7 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const ...@@ -582,7 +582,7 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve(name, node); oref = resolve(name, node);
IOController_i_var inc = IOController_i::_narrow(oref); IOController_i_var inc = IOController_i::_narrow(oref);
...@@ -594,13 +594,13 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const ...@@ -594,13 +594,13 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const
catch(CORBA::TRANSIENT){} catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){} catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){} catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch(IOController_i::NameNotFound& ex) catch(IOController_i::NameNotFound& ex)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::NameNotFound("UI(getIOType): "+string(ex.err)); throw UniSetTypes::NameNotFound("UI(getIOType): "+string(ex.err));
} }
catch(IOController_i::IOBadParam& ex) catch(IOController_i::IOBadParam& ex)
...@@ -610,32 +610,32 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const ...@@ -610,32 +610,32 @@ IOType UInterface::getIOType( const ObjectId name, const ObjectId node ) const
} }
catch(ORepFailed) catch(ORepFailed)
{ {
rcache.erase(name, node); rcache.erase(name, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw UniSetTypes::IOBadParam(set_err("UI(getIOType): resolve failed ",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getIOType): resolve failed ",name,node));
} }
catch(CORBA::NO_IMPLEMENT) catch(CORBA::NO_IMPLEMENT)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(getIOType): method no implement",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getIOType): method no implement",name,node));
} }
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(getIOType): object not exist",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getIOType): object not exist",name,node));
} }
catch(CORBA::COMM_FAILURE& ex) catch(CORBA::COMM_FAILURE& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getIOType): ошибка системы коммуникации" << endl; // uwarn << "UI(getIOType): ошибка системы коммуникации" << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getIOType): CORBA::SystemException" << endl; // uwarn << "UI(getIOType): CORBA::SystemException" << endl;
} }
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::TimeOut(set_err("UI(getIOType): Timeout",name, node)); throw UniSetTypes::TimeOut(set_err("UI(getIOType): Timeout",name, node));
} }
...@@ -662,12 +662,12 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const ...@@ -662,12 +662,12 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const
oref = rcache.resolve(name, node); oref = rcache.resolve(name, node);
} }
catch( NameNotFound ){} catch( NameNotFound ){}
for (unsigned int i=0; i<uconf->getRepeatCount(); i++) for (unsigned int i=0; i<uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( name, node ); oref = resolve( name, node );
UniSetObject_i_var uo = UniSetObject_i::_narrow(oref); UniSetObject_i_var uo = UniSetObject_i::_narrow(oref);
...@@ -676,13 +676,13 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const ...@@ -676,13 +676,13 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const
catch(CORBA::TRANSIENT){} catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){} catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){} catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch(IOController_i::NameNotFound& ex) catch(IOController_i::NameNotFound& ex)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::NameNotFound("UI(getType): "+string(ex.err)); throw UniSetTypes::NameNotFound("UI(getType): "+string(ex.err));
} }
catch(IOController_i::IOBadParam& ex) catch(IOController_i::IOBadParam& ex)
...@@ -692,33 +692,33 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const ...@@ -692,33 +692,33 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const
} }
catch(ORepFailed) catch(ORepFailed)
{ {
rcache.erase(name, node); rcache.erase(name, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw UniSetTypes::IOBadParam(set_err("UI(getType): resolve failed ",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getType): resolve failed ",name,node));
} }
catch(CORBA::NO_IMPLEMENT) catch(CORBA::NO_IMPLEMENT)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(getType): method no implement",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getType): method no implement",name,node));
} }
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(getType): object not exist",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(getType): object not exist",name,node));
} }
catch(CORBA::COMM_FAILURE& ex) catch(CORBA::COMM_FAILURE& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getType): ошибка системы коммуникации" << endl; // uwarn << "UI(getType): ошибка системы коммуникации" << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getType): CORBA::SystemException" << endl; // uwarn << "UI(getType): CORBA::SystemException" << endl;
} }
catch(UniSetTypes::TimeOut){} catch(UniSetTypes::TimeOut){}
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::TimeOut(set_err("UI(getType): Timeout",name, node)); throw UniSetTypes::TimeOut(set_err("UI(getType): Timeout",name, node));
} }
...@@ -873,7 +873,7 @@ ObjectPtr UInterface::resolve( const ObjectId rid , const ObjectId node, int tim ...@@ -873,7 +873,7 @@ ObjectPtr UInterface::resolve( const ObjectId rid , const ObjectId node, int tim
CosNaming::Name_var oname = omniURI::stringToName( oind->getNameById(rid,node).c_str() ); CosNaming::Name_var oname = omniURI::stringToName( oind->getNameById(rid,node).c_str() );
for (unsigned int i=0; i<uconf->getRepeatCount(); i++) for (unsigned int i=0; i<uconf->getRepeatCount(); i++)
{ {
try try
{ {
CORBA::Object_var nso = ctx->resolve(oname); CORBA::Object_var nso = ctx->resolve(oname);
if( CORBA::is_nil(nso) ) if( CORBA::is_nil(nso) )
...@@ -897,17 +897,17 @@ ObjectPtr UInterface::resolve( const ObjectId rid , const ObjectId node, int tim ...@@ -897,17 +897,17 @@ ObjectPtr UInterface::resolve( const ObjectId rid , const ObjectId node, int tim
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
throw UniSetTypes::ResolveNameError("ObjectNOTExist"); throw UniSetTypes::ResolveNameError("ObjectNOTExist");
} }
catch(CORBA::COMM_FAILURE& ex) catch(CORBA::COMM_FAILURE& ex)
{ {
throw UniSetTypes::ResolveNameError("CORBA::CommFailure"); throw UniSetTypes::ResolveNameError("CORBA::CommFailure");
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(resolve): CORBA::SystemException" << endl; // uwarn << "UI(resolve): CORBA::SystemException" << endl;
throw UniSetTypes::TimeOut(); throw UniSetTypes::TimeOut();
} }
throw UniSetTypes::ResolveNameError(); throw UniSetTypes::ResolveNameError();
} }
...@@ -950,27 +950,27 @@ void UInterface::send( const ObjectId name, const TransportMessage& msg, const O ...@@ -950,27 +950,27 @@ void UInterface::send( const ObjectId name, const TransportMessage& msg, const O
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(send): resolve failed ",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(send): resolve failed ",name,node));
} }
catch(CORBA::NO_IMPLEMENT) catch(CORBA::NO_IMPLEMENT)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(send): method no implement",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(send): method no implement",name,node));
} }
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::IOBadParam(set_err("UI(send): object not exist",name,node)); throw UniSetTypes::IOBadParam(set_err("UI(send): object not exist",name,node));
} }
catch(CORBA::COMM_FAILURE& ex) catch(CORBA::COMM_FAILURE& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(send): ошибка системы коммуникации" << endl; // uwarn << "UI(send): ошибка системы коммуникации" << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(send): CORBA::SystemException" << endl; // uwarn << "UI(send): CORBA::SystemException" << endl;
} }
rcache.erase(name, node); rcache.erase(name, node);
throw UniSetTypes::TimeOut(set_err("UI(send): Timeout",name, node)); throw UniSetTypes::TimeOut(set_err("UI(send): Timeout",name, node));
...@@ -1032,22 +1032,22 @@ IOController_i::ShortIOInfo UInterface::getChangedTime( const ObjectId id, const ...@@ -1032,22 +1032,22 @@ IOController_i::ShortIOInfo UInterface::getChangedTime( const ObjectId id, const
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(getChangedTime): resolve failed ",si.id,si.node) << endl; uwarn << set_err("UI(getChangedTime): resolve failed ",si.id,si.node) << endl;
} }
catch(CORBA::NO_IMPLEMENT) catch(CORBA::NO_IMPLEMENT)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(getChangedTime): method no implement",si.id,si.node) << endl; uwarn << set_err("UI(getChangedTime): method no implement",si.id,si.node) << endl;
} }
catch(CORBA::OBJECT_NOT_EXIST) catch(CORBA::OBJECT_NOT_EXIST)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(getChangedTime): object not exist",si.id,si.node) << endl; uwarn << set_err("UI(getChangedTime): object not exist",si.id,si.node) << endl;
} }
catch(CORBA::COMM_FAILURE) catch(CORBA::COMM_FAILURE)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(saveState): CORBA::COMM_FAILURE " << endl; // uwarn << "UI(saveState): CORBA::COMM_FAILURE " << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
...@@ -1065,14 +1065,11 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId ...@@ -1065,14 +1065,11 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
{ {
UniSetTypes::uniset_rwmutex_rlock l(cmutex); UniSetTypes::uniset_rwmutex_rlock l(cmutex);
//#warning Временно отключён кэш
// throw UniSetTypes::NameNotFound();
CacheMap::iterator it = mcache.find( key(id,node) ); CacheMap::iterator it = mcache.find( key(id,node) );
if( it == mcache.end() ) if( it == mcache.end() )
throw UniSetTypes::NameNotFound(); throw UniSetTypes::NameNotFound();
it->second.timestamp = time(NULL); // фиксируем время последнего обращения it->second.ncall++;
// т.к. функция возвращает указатель // т.к. функция возвращает указатель
// и тот кто вызывает отвечает за освобождение памяти // и тот кто вызывает отвечает за освобождение памяти
...@@ -1087,15 +1084,16 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId ...@@ -1087,15 +1084,16 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
void UInterface::CacheOfResolve::cache( const ObjectId id, const ObjectId node, ObjectVar ptr ) const void UInterface::CacheOfResolve::cache( const ObjectId id, const ObjectId node, ObjectVar ptr ) const
{ {
UniSetTypes::uniset_rwmutex_wrlock l(cmutex); UniSetTypes::uniset_rwmutex_wrlock l(cmutex);
UniSetTypes::KeyType k(key(id,node));
UniSetTypes::KeyType k( key(id,node) );
CacheMap::iterator it = mcache.find(k); CacheMap::iterator it = mcache.find(k);
if( it==mcache.end() ) if( it == mcache.end() )
mcache.insert(CacheMap::value_type(k,Info(ptr))); mcache.insert(CacheMap::value_type(k,Info(ptr)));
else else
{ {
it->second.ptr = ptr; // CORBA::Object::_duplicate(ptr); it->second.ptr = ptr; // CORBA::Object::_duplicate(ptr);
it->second.timestamp = time(NULL); it->second.ncall++;
} }
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
...@@ -1105,11 +1103,9 @@ bool UInterface::CacheOfResolve::clean() ...@@ -1105,11 +1103,9 @@ bool UInterface::CacheOfResolve::clean()
uinfo << "UI: clean cache...."<< endl; uinfo << "UI: clean cache...."<< endl;
time_t tm = time(NULL)-CleanTime*60;
// remove_if(mcache.begin(), mcache.end(),OldRef_eq(tm));
for( CacheMap::iterator it=mcache.begin(); it!=mcache.end();) for( CacheMap::iterator it=mcache.begin(); it!=mcache.end();)
{ {
if( it->second.timestamp < tm ) if( it->second.ncall <= minCallCount )
mcache.erase(it++); mcache.erase(it++);
else else
++it; ++it;
...@@ -1125,9 +1121,6 @@ bool UInterface::CacheOfResolve::clean() ...@@ -1125,9 +1121,6 @@ bool UInterface::CacheOfResolve::clean()
void UInterface::CacheOfResolve::erase( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const void UInterface::CacheOfResolve::erase( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) const
{ {
UniSetTypes::uniset_rwmutex_wrlock l(cmutex); UniSetTypes::uniset_rwmutex_wrlock l(cmutex);
//#warning Временно отключён кэш
// return;
CacheMap::iterator it = mcache.find( key(id,node) ); CacheMap::iterator it = mcache.find( key(id,node) );
if( it != mcache.end() ) if( it != mcache.end() )
mcache.erase(it); mcache.erase(it);
...@@ -1149,14 +1142,14 @@ bool UInterface::isExist( const UniSetTypes::ObjectId id ) const ...@@ -1149,14 +1142,14 @@ bool UInterface::isExist( const UniSetTypes::ObjectId id ) const
CORBA::Object_var oref = orb->string_to_object(sior.c_str()); CORBA::Object_var oref = orb->string_to_object(sior.c_str());
return rep.isExist( oref ); return rep.isExist( oref );
} }
return false; return false;
} }
string nm = oind->getNameById(id); string nm = oind->getNameById(id);
return rep.isExist(nm); return rep.isExist(nm);
} }
catch(UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex )
{ {
// uwarn << "UI(isExist): " << ex << endl; // uwarn << "UI(isExist): " << ex << endl;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment