1 #include "ace/Log_Msg.h"
3 #include "tao/TimeBaseC.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "orbsvcs/CosNamingC.h"
7 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
13 CORBA::ORB_var Orb
= CORBA::ORB_init(argc
, argv
);
15 // Set round-trip timeout
16 const int timeout_secs
= 5;
18 CORBA::Object_var obj
= Orb
->resolve_initial_references ("ORBPolicyManager");
19 CORBA::PolicyManager_var policy_manager
=
20 CORBA::PolicyManager::_narrow (obj
.in());
22 CORBA::PolicyList policy_list
;
23 policy_list
.length(0);
24 policy_manager
->set_policy_overrides(policy_list
, CORBA::SET_OVERRIDE
);
26 TimeBase::TimeT timeout
= timeout_secs
* 10000000;
27 CORBA::Any orb_timeout
;
28 orb_timeout
<<= timeout
;
29 policy_list
.length(1);
30 policy_list
[0] = Orb
->create_policy(
31 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
, orb_timeout
);
33 policy_manager
->set_policy_overrides(policy_list
, CORBA::SET_OVERRIDE
);
35 // Now try to contact a server.
36 // Use a remote machine that is unreachable on the network.
37 const char * obj_ref
= "corbaloc:iiop:1.0@10.123.123.123:4567/NameService";
39 obj
= Orb
->string_to_object(obj_ref
);
41 CosNaming::NamingContext_var inc
;
42 if(!CORBA::is_nil(obj
.in ()))
44 ACE_DEBUG(( LM_INFO
, "Attempting to contact %C\n", obj_ref
));
47 inc
= CosNaming::NamingContext::_narrow(obj
.in());
48 ACE_DEBUG(( LM_INFO
, "OK\n" ));
50 catch(const CORBA::TRANSIENT
&)
52 ACE_ERROR ((LM_ERROR
, "Error, caught transient exception\n"));
55 catch(const CORBA::TIMEOUT
&)
57 ACE_DEBUG ((LM_DEBUG
, "Caught correct timeout\n"));
61 catch (const ::CORBA::Exception
&ex
)
63 ex
._tao_print_exception("ERROR : unexpected CORBA exception caugth :");