00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NAMING_HELPER_T_H
00025 #define NAMING_HELPER_T_H
00026
00027 #include "CosNamingC.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 template<class T>
00039 class NamingHelper
00040 {
00041 public:
00042
00043 static
00044 typename T::_ptr_type
00045 resolve_init(CORBA::ORB_ptr orb, const char *id,
00046 size_t tries = 1,
00047 ACE_Time_Value timeout = ACE_Time_Value::zero)
00048 throw ( CORBA::SystemException,
00049 CORBA::ORB::InvalidName
00050 );
00051
00052
00053 static
00054 typename T::_ptr_type
00055 resolve_name( CosNaming::NamingContext_ptr nc,
00056 const CosNaming::Name& name,
00057 size_t tries = 1,
00058 ACE_Time_Value timeout = ACE_Time_Value::zero)
00059 throw( CORBA::SystemException,
00060 CosNaming::NamingContext::NotFound,
00061 CosNaming::NamingContext::CannotProceed,
00062 CosNaming::NamingContext::InvalidName);
00063
00064
00065
00066
00067
00068 static
00069 void bind( CosNaming::NamingContext_ptr nc,
00070 const CosNaming::Name& n, CORBA::Object_ptr obj,
00071 size_t tries = 1,
00072 ACE_Time_Value timeout = ACE_Time_Value::zero)
00073 throw ( CORBA::SystemException,
00074 CosNaming::NamingContext::NotFound,
00075 CosNaming::NamingContext::CannotProceed,
00076 CosNaming::NamingContext::InvalidName,
00077 CosNaming::NamingContext::AlreadyBound );
00078
00079
00080
00081
00082
00083 static
00084 void rebind ( CosNaming::NamingContext_ptr nc,
00085 const CosNaming::Name & n, CORBA::Object_ptr obj,
00086 size_t tries = 1,
00087 ACE_Time_Value timeout = ACE_Time_Value::zero)
00088 throw (
00089 CORBA::SystemException,
00090 CosNaming::NamingContext::NotFound,
00091 CosNaming::NamingContext::CannotProceed,
00092 CosNaming::NamingContext::InvalidName
00093 );
00094
00095
00096 };
00097
00098
00099 template<class T>
00100 typename T::_ptr_type
00101 NamingHelper<T>::resolve_init(CORBA::ORB_ptr orb, const char *id,
00102 size_t tries,
00103 ACE_Time_Value timeout)
00104 throw ( CORBA::SystemException,
00105 CORBA::ORB::InvalidName
00106 )
00107 {
00108 size_t i;
00109 CORBA::Object_var obj;
00110 for(i=0; i < tries; i++ ){
00111 try{
00112 obj = orb->resolve_initial_references( id );
00113 break;
00114
00115 }
00116 catch( ... ){
00117 if( i < tries ){
00118 ACE_DEBUG((LM_DEBUG, "Retrying resolve() of %s ...%d\n", id, i));
00119
00120
00121
00122 ACE_OS::sleep(timeout);
00123 }else{
00124
00125 ACE_DEBUG((LM_DEBUG, "Rethrowing exception\n"));
00126 throw;
00127 }
00128 }
00129 }
00130
00131
00132 typename T::_var_type ref;
00133 try{
00134 ref = T::_narrow(obj.in() );
00135 }catch( const CORBA::SystemException& e){
00136 throw;
00137 }
00138
00139 return ref._retn();
00140 }
00141
00142
00143 template< class T>
00144 typename T::_ptr_type
00145 NamingHelper<T>::resolve_name( CosNaming::NamingContext_ptr nc,
00146 const CosNaming::Name& name,
00147 size_t tries,
00148 ACE_Time_Value timeout)
00149 throw( CORBA::SystemException,
00150 CosNaming::NamingContext::NotFound,
00151 CosNaming::NamingContext::CannotProceed,
00152 CosNaming::NamingContext::InvalidName
00153 )
00154 {
00155 CORBA::Object_var obj;
00156 size_t i;
00157
00158 for(i=0; i < tries; i++ ){
00159 try{
00160 obj = nc->resolve( name );
00161 break;
00162
00163 }
00164 catch( ... ){
00165 if( i < tries ){
00166 ACE_DEBUG((LM_DEBUG, "Retrying resolve() of %s ...%d\n", name[0].id.in(), i));
00167
00168
00169
00170 ACE_OS::sleep(timeout);
00171 }else{
00172
00173 ACE_DEBUG((LM_DEBUG, "Rethrowing exception\n"));
00174 throw;
00175 }
00176 }
00177 }
00178 if( CORBA::is_nil( obj.in() )){
00179
00180
00181 }
00182
00183 typename T::_var_type ref;
00184 try{
00185 ref = T::_narrow(obj.in() );
00186 }catch(const CORBA::SystemException& e){
00187 e._tao_print_exception("");
00188 throw;
00189 }
00190
00191 if( CORBA::is_nil(ref.in() )){
00192
00193
00194 }
00195
00196 return ref._retn();
00197 }
00198
00199 template< class T>
00200 void
00201 NamingHelper<T>::bind( CosNaming::NamingContext_ptr nc,
00202 const CosNaming::Name& n, CORBA::Object_ptr obj,
00203 size_t tries, ACE_Time_Value timeout)
00204 throw ( CORBA::SystemException,
00205 CosNaming::NamingContext::NotFound,
00206 CosNaming::NamingContext::CannotProceed,
00207 CosNaming::NamingContext::InvalidName,
00208 CosNaming::NamingContext::AlreadyBound )
00209 {
00210
00211 size_t i;
00212
00213 ACE_DEBUG((LM_DEBUG, "Calling bind() with %d tries\n", tries));
00214 for(i = 0; i < tries; i++)
00215 {
00216 try
00217 {
00218 nc->bind(n, obj);
00219
00220 break;
00221
00222 }catch(const CORBA::SystemException& e){
00223 ACE_DEBUG((LM_DEBUG, "bind() threw exception\n"));
00224 e._tao_print_exception("");
00225
00226 if(i < tries)
00227 {
00228
00229
00230
00231 ACE_OS::sleep(timeout);
00232 ACE_DEBUG((LM_DEBUG, "Retrying bind() of %s...%d\n",
00233 n[0].id.in(), i));
00234 }
00235 else{
00236
00237 ACE_DEBUG((LM_DEBUG, "Rethrowing bind() exception\n"));
00238 throw;
00239 }
00240 } catch (const CORBA::Exception& e) {
00241 ACE_DEBUG((LM_DEBUG, "bind() threw non-system exception\n"));
00242 e._tao_print_exception("");
00243 throw;
00244 }
00245 }
00246 }
00247
00248 template< class T>
00249 void
00250 NamingHelper<T>::rebind( CosNaming::NamingContext_ptr nc,
00251 const CosNaming::Name& n, CORBA::Object_ptr obj,
00252 size_t tries, ACE_Time_Value timeout)
00253 throw ( CORBA::SystemException,
00254 CosNaming::NamingContext::NotFound,
00255 CosNaming::NamingContext::CannotProceed,
00256 CosNaming::NamingContext::InvalidName)
00257 {
00258
00259 size_t i;
00260
00261 for(i = 0; i < tries; i++)
00262 {
00263 try
00264 {
00265 nc->rebind(n, obj);
00266
00267 break;
00268
00269 }catch(...){
00270
00271 if(i < tries)
00272 {
00273
00274
00275
00276 ACE_OS::sleep(timeout);
00277 ACE_DEBUG((LM_DEBUG, "Retrying...%d\n", i));
00278 }
00279 else{
00280
00281 ACE_DEBUG((LM_DEBUG, "Rethrowing rebind() exception\n"));
00282 throw;
00283 }
00284 }
00285 }
00286 }
00287
00288 #endif
00289