Commit 23520fb8 authored by Pavel Vainerman's avatar Pavel Vainerman

(UObject): добавлены попытки регистрации и активации объекта

parent f66ca1fe
......@@ -16,7 +16,7 @@
Name: libuniset2
Version: 2.6
Release: alt8
Release: alt9
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
......@@ -507,6 +507,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# history of current unpublished changes
%changelog
* Fri Dec 16 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt9
- UObject: added attempts to activate the object
* Wed Dec 14 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt8
- SM: terminate if read dump (configuration) failed
......
......@@ -221,9 +221,9 @@ namespace uniset
//! Непосредственная активизация объекта
bool activate();
/* регистрация в репозитории объектов */
void registered();
void registration();
/* удаление ссылки из репозитория объектов */
void unregister();
void unregistration();
void initObject();
......
......@@ -851,7 +851,7 @@ namespace uniset
string nodeName(s.str());
string bname(nodeName); // сохраняем базовое название
for(unsigned int curNet = 1; curNet <= uconf->getCountOfNet(); curNet++)
for( size_t curNet = 1; curNet <= uconf->getCountOfNet(); curNet++)
{
try
{
......
......@@ -224,13 +224,13 @@ namespace uniset
return receiveMessage();
}
// ------------------------------------------------------------------------------------------
void UniSetObject::registered()
void UniSetObject::registration()
{
ulogrep << myname << ": registration..." << endl;
if( myid == uniset::DefaultObjectId )
{
ulogrep << myname << "(registered): Don`t registration. myid=DefaultObjectId \n";
ulogrep << myname << "(registration): Don`t registration. myid=DefaultObjectId \n";
return;
}
......@@ -238,7 +238,7 @@ namespace uniset
if( !m )
{
uwarn << myname << "(registered): unknown my manager" << endl;
uwarn << myname << "(registration): unknown my manager" << endl;
string err(myname + ": unknown my manager");
throw ORepFailed(err);
}
......@@ -248,18 +248,20 @@ namespace uniset
if( !oref )
{
ucrit << myname << "(registered): oref is NULL!..." << endl;
uwarn << myname << "(registration): oref is NULL!..." << endl;
return;
}
}
try
{
for( unsigned int i = 0; i < 2; i++ )
auto conf = uniset_conf();
regOK = false;
for( size_t i = 0; i < conf->getRepeatCount(); i++ )
{
try
{
ui->registered(myid, getRef(), true);
regOK = true;
break;
}
catch( ObjectNameAlready& al )
......@@ -274,29 +276,30 @@ namespace uniset
если заменяемый объект "жив" и завершит свою работу, то он может почистить за собой ссылку и это тогда наш(новый)
объект станет недоступен другим, а знать об этом не будет!!!
*/
ucrit << myname << "(registered): replace object (ObjectNameAlready)" << endl;
regOK = true;
unregister();
}
uwarn << myname << "(registration): replace object (ObjectNameAlready)" << endl;
unregistration();
}
}
catch( ORepFailed )
catch( uniset::ORepFailed )
{
string err(myname + ": don`t registration in object reposotory");
uwarn << myname << "(registered): " << err << endl;
throw ORepFailed(err);
uwarn << myname << "(registration): don`t registration in object reposotory " << endl;
}
catch( const uniset::Exception& ex )
{
uwarn << myname << "(registered): " << ex << endl;
string err(myname + ": don`t registration in object reposotory");
throw ORepFailed(err);
uwarn << myname << "(registration): " << ex << endl;
}
regOK = true;
msleep(conf->getRepeatTimeout());
}
if( !regOK )
{
string err(myname + "(registration): don`t registration in object reposotory");
ucrit << err << endl;
throw ORepFailed(err);
}
}
// ------------------------------------------------------------------------------------------
void UniSetObject::unregister()
void UniSetObject::unregistration()
{
if( myid < 0 ) // || !reg )
return;
......@@ -529,7 +532,7 @@ namespace uniset
uwarn << myname << "(deactivate): " << ex.what() << endl;
}
unregister();
unregistration();
PortableServer::ObjectId_var oid = poamngr->servant_to_id(static_cast<PortableServer::ServantBase*>(this));
poamngr->deactivate_object(oid);
uinfo << myname << "(disacivate): finished..." << endl;
......@@ -587,12 +590,18 @@ namespace uniset
throw ORepFailed(err);
}
bool actOK = false;
auto conf = uniset_conf();
for( size_t i = 0; i < conf->getRepeatCount(); i++ )
{
try
{
if( uniset_conf()->isTransientIOR() )
if( conf->isTransientIOR() )
{
// activate witch generate id
poa->activate_object(static_cast<PortableServer::ServantBase*>(this));
actOK = true;
break;
}
else
{
......@@ -600,7 +609,7 @@ namespace uniset
// то myname = noname. ВСЕГДА!
if( myid == uniset::DefaultObjectId )
{
ucrit << myname << "(activate): Не задан ID!!! activate failure..." << endl;
uwarn << myname << "(activate): Не задан ID!!! IGNORE ACTIVATE..." << endl;
// вызываем на случай если она переопределена в дочерних классах
// Например в UniSetManager, если здесь не вызвать, то не будут инициализированы подчинённые объекты.
// (см. UniSetManager::activateObject)
......@@ -609,13 +618,12 @@ namespace uniset
}
// Always use the same object id.
PortableServer::ObjectId_var oid =
PortableServer::string_to_ObjectId(myname.c_str());
// cerr << myname << "(activate): " << _refcount_value() << endl;
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(myname.c_str());
// Activate object...
poa->activate_object_with_id(oid, this);
actOK = true;
break;
}
}
catch( const CORBA::Exception& ex )
......@@ -631,12 +639,24 @@ namespace uniset
uwarn << myname << "(activate): IGNORE.. catch " << ex._name() << endl;
}
msleep( conf->getRepeatTimeout() );
}
if( !actOK )
{
ostringstream err;
err << myname << "(activate): DON`T ACTIVATE..";
ucrit << myname << "(activate): " << err.str() << endl;
throw uniset::SystemError(err.str());
}
{
uniset::uniset_rwmutex_wrlock lock(refmutex);
oref = poa->servant_to_reference(static_cast<PortableServer::ServantBase*>(this) );
}
registered();
registration();
// Запускаем поток обработки сообщений
setActive(true);
......
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