00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ProxyManager.h"
00025 #include "PersistNode.h"
00026 #include "Orb.h"
00027 #include "omniEventsLog.h"
00028
00029 #include <string>
00030 #include <map>
00031 #include <assert.h>
00032 #include <memory>
00033
00034 namespace OmniEvents {
00035
00036
00037
00038
00039
00040 void
00041 ProxyManager::etherealize(
00042 const PortableServer::ObjectId& oid,
00043 PortableServer::POA_ptr adapter,
00044 PortableServer::Servant serv,
00045 CORBA::Boolean cleanup_in_progress,
00046 CORBA::Boolean remaining_activations
00047 )
00048 {
00049 auto_ptr<Proxy> narrowed( dynamic_cast<Proxy*>(serv) );
00050 assert(narrowed.get()!=NULL);
00051 set<Proxy*>::iterator pos =_servants.find(narrowed.get());
00052 if(pos!=_servants.end())
00053 _servants.erase(pos);
00054 else
00055 DB(1,"\t\teh? - POA attempted to etherealize unknown servant.");
00056
00057 }
00058
00059
00060 void ProxyManager::reincarnate(const PersistNode& node)
00061 {
00062
00063 for(map<string,PersistNode*>::const_iterator i=node._child.begin();
00064 i!=node._child.end();
00065 ++i)
00066 {
00067 assert(i->second!=NULL);
00068 PortableServer::Servant serv =
00069 this->incarnate(PortableServer::ObjectId(),_managedPoa);
00070 Proxy* proxy =dynamic_cast<Proxy*>(serv);
00071 assert(proxy!=NULL);
00072 try
00073 {
00074 proxy->reincarnate(i->first,*(i->second));
00075 }
00076 catch(CORBA::BAD_PARAM& ex)
00077 {
00078
00079 DB(5,"Failed to reincarnate proxy: "<<i->first.c_str());
00080 _servants.erase(proxy);
00081 delete proxy;
00082 }
00083 }
00084 }
00085
00086
00087 void ProxyManager::output(ostream& os)
00088 {
00089 for(set<Proxy*>::iterator i =_servants.begin(); i!=_servants.end(); ++i)
00090 {
00091 (*i)->output(os);
00092 }
00093 }
00094
00095
00096 ProxyManager::ProxyManager(PortableServer::POA_ptr p)
00097 : Servant(p),
00098 _servants(),
00099 _managedPoa(PortableServer::POA::_nil())
00100 {}
00101
00102
00103 void ProxyManager::activate(const char* name)
00104 {
00105 using namespace PortableServer;
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 CORBA::PolicyList policies;
00117 policies.length(5);
00118 policies[0]=_poa->create_lifespan_policy(PERSISTENT);
00119 policies[1]=_poa->create_id_assignment_policy(USER_ID);
00120 policies[2]=_poa->create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION);
00121 policies[3]=_poa->create_request_processing_policy(USE_SERVANT_MANAGER);
00122 policies[4]=_poa->create_thread_policy(SINGLE_THREAD_MODEL);
00123
00124 try
00125 {
00126
00127 CORBA::String_var parentName =_poa->the_name();
00128 string poaName =string(parentName.in())+"."+name;
00129 POAManager_var parentManager =_poa->the_POAManager();
00130 _managedPoa=_poa->create_POA(poaName.c_str(),parentManager.in(),policies);
00131 }
00132 catch(POA::AdapterAlreadyExists& ex)
00133 {
00134 DB(0,"ProxyManager::ProxyManager() - POA::AdapterAlreadyExists")
00135 }
00136 catch(POA::InvalidPolicy& ex)
00137 {
00138 DB(0,"ProxyManager::ProxyManager() - POA::InvalidPolicy: "<<ex.index)
00139 }
00140
00141
00142 for(CORBA::ULong i=0; i<policies.length(); ++i)
00143 policies[i]->destroy();
00144
00145 string oidStr =string(name)+"Manager";
00146 activateObjectWithId(oidStr.c_str());
00147 PortableServer::ServantManager_var manager(_this());
00148 _managedPoa->set_servant_manager(manager);
00149 }
00150
00151
00152 ProxyManager::~ProxyManager()
00153 {
00154
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 Proxy::~Proxy()
00164 {
00165 if(!CORBA::is_nil(_req))
00166 {
00167 Orb::inst().deferredRequest(_req._retn());
00168 _req=CORBA::Request::_nil();
00169 }
00170 }
00171
00172 Proxy::Proxy(PortableServer::POA_ptr poa)
00173 : Servant(poa),
00174 _req(CORBA::Request::_nil())
00175 {
00176
00177 }
00178
00179 void Proxy::keyOutput(ostream& os, const char* name)
00180 {
00181 PortableServer::POA_var parentPoa=_poa->the_parent();
00182 CORBA::String_var channelName=parentPoa->the_name();
00183
00184 PortableServer::ObjectId_var oid=_poa->servant_to_id(this);
00185 CORBA::String_var oidStr =PortableServer::ObjectId_to_string(oid.in());
00186 os<<"ecf/"<<channelName.in()<<"/"<<name<<"/"<<oidStr.in();
00187 }
00188
00189 void Proxy::eraseKey(const char* name)
00190 {
00191 if(omniEventsLog::exists())
00192 {
00193
00194 WriteLock log;
00195 log.os<<"-";
00196 keyOutput(log.os,name);
00197 log.os<<'\n';
00198 }
00199 }
00200
00201 void Proxy::basicOutput(
00202 ostream& os,
00203 const char* name,
00204 CORBA::Object_ptr target,
00205 const char* extraAttributes
00206 )
00207 {
00208 keyOutput(os,name);
00209 if(!CORBA::is_nil(target))
00210 {
00211 CORBA::String_var iorstr =Orb::inst()._orb->object_to_string(target);
00212 os<<" IOR="<<iorstr.in();
00213 if(extraAttributes)
00214 os<<extraAttributes;
00215 }
00216 os<<" ;;\n";
00217 }
00218
00219
00220 };