#include <NameServer.h>
Membri pubblici statici | |
CORBA::Boolean | bindObjectToName (const char *context, const char* name, const char* kind, const CORBA::ORB_ptr orb, const CORBA::Object_ptr obj) |
Registra un oggetto CORBA presso un NameServer. Continua... | |
CORBA::Boolean | unbindObject (const char *context, const char* name, const char* kind, const CORBA::ORB_ptr orb) |
Deregistra un oggetto CORBA predecentemente registrato presso un NameServer. Continua... | |
CORBA::Object_ptr | get_object ( const CORBA::ORB_ptr orb, const utils::URI &uri ) throw (Exception) |
Restituisce un riferimento ad un oggetto CORBA datone il suo URI. Continua... |
Questa classe fornisce una collezione di routine adatte all'espletamento di compiti ricorrenti riguardanti l'uso di un NameServer CORBA. In particolare sono forniti metodi per:
Definizione alla linea 50 del file NameServer.h.
|
Registra un oggetto CORBA presso un NameServer. Consente di registrare un oggetto CORBA presso il nameserver associato all'ORB orb, permettendo di specificare il tipo del servizio da registrare, il nome con cui si potrà riferire il server in questione e il contesto di NameServer presso cui è registrato il servizio.
Definizione alla linea 125 del file NameServer.cc. Referenziato da main(). 00126 { 00127 CosNaming::NamingContext_var rootContext; 00128 try { 00129 // Obtain a reference to the root context of the Name service: 00130 CORBA::Object_var obj; 00131 obj = orb->resolve_initial_references("NameService"); 00132 00133 // Narrow the reference returned. 00134 rootContext = CosNaming::NamingContext::_narrow(obj); 00135 if( CORBA::is_nil(rootContext) ) { 00136 cerr << "Failed to narrow the root naming context." << endl; 00137 return false; 00138 } 00139 } 00140 catch(CORBA::ORB::InvalidName& ex) { 00141 // This should not happen! 00142 cerr << "Service required is invalid [does not exist]." << endl; 00143 return false; 00144 } 00145 00146 try { 00147 // Bind a context called "test" to the root context: 00148 CosNaming::Name contextName; 00149 contextName.length(1); 00150 contextName[0].id = (const char*) context; 00151 contextName[0].kind = (const char*) PROJECT_NAME; 00152 00153 CosNaming::NamingContext_var testContext; 00154 try { 00155 // Bind the context to root. 00156 testContext = rootContext->bind_new_context(contextName); 00157 } 00158 catch(CosNaming::NamingContext::AlreadyBound& ex) { 00159 // If the context already exists, this exception will be raised. 00160 // In this case, just resolve the name and assign testContext 00161 // to the object returned: 00162 CORBA::Object_var obj; 00163 obj = rootContext->resolve(contextName); 00164 testContext = CosNaming::NamingContext::_narrow(obj); 00165 if( CORBA::is_nil(testContext) ) { 00166 cerr << "Failed to narrow naming context." << endl; 00167 return false; 00168 } 00169 } 00170 00171 // Bind objref with name Echo to the testContext: 00172 CosNaming::Name objectName; 00173 objectName.length(1); 00174 objectName[0].id = (const char*) name; 00175 objectName[0].kind = (const char*) kind; 00176 00177 try { 00178 testContext->bind(objectName, objref); 00179 } 00180 catch(CosNaming::NamingContext::AlreadyBound& ex) { 00181 testContext->rebind(objectName, objref); 00182 } 00183 // Note: Using rebind() will overwrite any Object previously bound 00184 // to /test/Echo with obj. 00185 // Alternatively, bind() can be used, which will raise a 00186 // CosNaming::NamingContext::AlreadyBound exception if the name 00187 // supplied is already bound to an object. 00188 00189 // Amendment: When using OrbixNames, it is necessary to first try bind 00190 // and then rebind, as rebind on it's own will throw a NotFoundexception if 00191 // the Name has not already been bound. [This is incorrect behaviour - 00192 // it should just bind]. 00193 } 00194 catch(CORBA::COMM_FAILURE& ex) { 00195 cerr << "Caught system exception COMM_FAILURE -- unable to contact the " 00196 << "naming service." << endl; 00197 return false; 00198 } 00199 catch(CORBA::SystemException&) { 00200 cerr << "Caught a CORBA::SystemException while using the naming service." << endl; 00201 return false; 00202 } 00203 return true; 00204 } |
|
Restituisce un riferimento ad un oggetto CORBA datone il suo URI. Restituisce un riferimento all'oggetto CORBA, demandandone la gestione ad un ORB desiderato.
Definizione alla linea 30 del file NameServer.cc. Referenziato da fbfs::Rule::eval(), fbfs::Proxy_i::get(), fbfs::Proxy_i::put(), fbfs::ObjectManager_i::put(), fbfs::Proxy_i::remove(), e fbfs::ObjectManager_i::remove(). 00030 { 00031 string str_contextname = uri.nameServerURL(); 00032 string str_servicename = uri.serviceName(); 00033 const char *contextname = str_contextname.c_str(); 00034 const char *servicename = str_servicename.c_str(); 00035 CosNaming::NamingContextExt_var nc; 00036 //cout << "Context:" << str_contextname << " Service:" << str_servicename << "\n"; 00037 try { 00038 CORBA::Object_var obj = orb->string_to_object( contextname ); 00039 nc = CosNaming::NamingContextExt::_narrow(obj); 00040 if( CORBA::is_nil(nc) ) { 00041 cerr << "Failed to narrow to naming context"; 00042 throw Exception(); 00043 }; 00044 CORBA::Object_ptr return_object = nc->resolve_str( servicename ); 00045 return return_object; 00046 } 00047 catch(CosNaming::NamingContext::InvalidName &) { 00048 cout << "invalid name\n"; 00049 throw InvalidNameException(); 00050 } 00051 catch(CosNaming::NamingContext::NotFound &) { 00052 cout << "not found\n"; 00053 throw NotFoundException(); 00054 } 00055 catch(...) { 00056 cout << "other\n"; 00057 throw Exception(); 00058 }; 00059 } |
|
Deregistra un oggetto CORBA predecentemente registrato presso un NameServer. Consente di rimuovere un'entry nel NameServer CORBA associato ad un particolare ORB.
Definizione alla linea 61 del file NameServer.cc. Referenziato da catch_sigterm(). 00061 { 00062 CosNaming::NamingContext_var rootContext; 00063 try { 00064 // Obtain a reference to the root context of the Name service: 00065 CORBA::Object_var obj; 00066 obj = orb->resolve_initial_references("NameService"); 00067 00068 // Narrow the reference returned. 00069 rootContext = CosNaming::NamingContext::_narrow(obj); 00070 if( CORBA::is_nil(rootContext) ) { 00071 cerr << "Failed to narrow the root naming context." << endl; 00072 return false; 00073 } 00074 } 00075 catch(CORBA::ORB::InvalidName& ex) { 00076 // This should not happen! 00077 cerr << "Service required is invalid [does not exist]." << endl; 00078 return false; 00079 } 00080 00081 try { 00082 // Open the required context 00083 CosNaming::Name contextName; 00084 contextName.length(1); 00085 contextName[0].id = (const char*) context; // string copied 00086 contextName[0].kind = (const char*) "utils"; // string copied 00087 00088 CORBA::Object_var obj = rootContext->resolve(contextName); 00089 CosNaming::NamingContext_var testContext = CosNaming::NamingContext::_narrow(obj); 00090 if( CORBA::is_nil(testContext) ) { 00091 cerr << "Failed to narrow naming context." << endl; 00092 return false; 00093 } 00094 00095 // Unbind the specified object 00096 CosNaming::Name objectName; 00097 objectName.length(1); 00098 objectName[0].id = (const char*) name; 00099 objectName[0].kind = (const char*) kind; 00100 00101 try { 00102 testContext->unbind(objectName); 00103 } 00104 catch(CosNaming::NamingContext::NotFound& ex) { 00105 cerr << "The object in not registered in the selected context." << endl; 00106 } 00107 // It appears to bring omniNames in an inconsistent state. 00108 // try { 00109 // testContext->destroy(); 00110 // } 00111 // catch(CosNaming::NamingContext::NotEmpty& ex) { } 00112 } 00113 catch(CORBA::COMM_FAILURE& ex) { 00114 cerr << "Caught system exception COMM_FAILURE -- unable to contact the " 00115 << "naming service." << endl; 00116 return false; 00117 } 00118 catch(CORBA::SystemException&) { 00119 cerr << "Caught a CORBA::SystemException while using the naming service." << endl; 00120 return false; 00121 } 00122 return true; 00123 } |