Product: OpenFusion TAO
Version: ALL
Description:
How to timeout a Corba request?
Resolution:
This can be done by using the RELATIVE_ROUND_TRIP_TIMEOUT policy, which is part of the
CORBA Messaging specification. This specifies how much time is allowed to deliver a request and its reply, starting from the request invocation. The units are 100ns,
so a value of 50000000 represents 5 seconds. The policy can be applied at one of three levels: the client ORB, the requesting thread, or the object reference on which the request is invoked.
This can be set as follows:
// Initialize the ORB. It serves as a factory for policies.
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// Set the timeout value as a TimeBase::TimeT (100 nanosecond units)
// and insert it into a CORBA::Any.
TimeBase::TimeT relative_rt_timeout = 1.0e-3 * 1.0e7;
CORBA::Any relative_rt_timeout_as_any;
relative_rt_timeout_as_any <<= relative_rt_timeout;
// Create the policy and put it in a policy list.
CORBA::PolicyList pols;
pols.length(1);
pols[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
relative_rt_timeout_as_any);
// Apply the policy at the ORB level using the ORBPolicyManager.
CORBA::Object_var obj = orb->resolve_initial_references ("ORBPolicyManager");
CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow (obj.in());
policy_manager->set_policy_overrides (pols, CORBA::SET_OVERRIDE);
CORBA::PolicyList policy_list (1);
policy_list.length (1);
policy_list[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
any_object ACE_ENV_ARG_PARAMETER);
When the timeout occurs the ORB will throw a CORBA::TIMEOUT exception which the client can catch and deal with as necessary.
#OpenFusion
#KnowledgeDocs