Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2709_Regression / Client_Task.cpp
bloba1bab4f341a9e9fab403a0630fda2039cdaa2122
1 #include "TestC.h"
2 #include "Client_Task.h"
3 #include "orbsvcs/FaultTolerance/FT_ClientService_Activate.h"
5 //////////////////////////////////////////////////////////////////////////
7 ACE_TString file_prefix(ACE_TEXT("file://"));
9 /// Constructor
10 Client_Task::Client_Task (CORBA::ORB_ptr corb,
11 ACE_Thread_Manager *thr_mgr,
12 const ACE_TString& collocated_ior_file,
13 const ACE_TString& server_ior_file)
14 : ACE_Task_Base (thr_mgr)
15 , corb_ (CORBA::ORB::_duplicate (corb))
16 , collocated_ior_file_(collocated_ior_file)
17 , server_ior_file_(server_ior_file)
21 CORBA::Object_ptr
22 Client_Task::make_iogr (const char* domain_id, CORBA::ULongLong group_id, CORBA::ULong group_version)
24 CORBA::Object_var remote_server(
25 corb_->string_to_object (ACE_TString(file_prefix + this->server_ior_file_).c_str()));
27 if (CORBA::is_nil (remote_server.in ()))
29 ACE_ERROR ((LM_ERROR, "Error: Remote server is not started.\n"));
30 throw CORBA::INTERNAL ();
33 CORBA::Object_var collocated_server(
34 corb_->string_to_object (ACE_TString(file_prefix + this->collocated_ior_file_).c_str()));
36 if (CORBA::is_nil (collocated_server.in ()))
38 ACE_ERROR ((LM_ERROR, "Error: Collocated server is not started.\n"));
39 throw CORBA::INTERNAL ();
42 FT::TagFTGroupTaggedComponent ft_tag_component;
44 // Create the list
45 TAO_IOP::TAO_IOR_Manipulation::IORList iors (1);
46 iors.length (2);
47 iors [0] = CORBA::Object::_duplicate (remote_server.ptr());
48 iors [1] = CORBA::Object::_duplicate (collocated_server.ptr());
50 CORBA::Object_var new_ref =
51 this->iorm_->merge_iors (iors);
53 // Property values
55 // Major and Minor revision numbers
56 ft_tag_component.component_version.major = (CORBA::Octet) 1;
57 ft_tag_component.component_version.minor = (CORBA::Octet) 0;
59 // Domain id
60 ft_tag_component.group_domain_id = domain_id;
62 // Object group id
63 ft_tag_component.object_group_id = group_id;
65 // Version
66 ft_tag_component.object_group_ref_version = group_version;
68 // Construct the IOGR Property class
69 TAO_FT_IOGR_Property iogr_prop (ft_tag_component);
71 // Set the property
72 CORBA::Boolean retval = this->iorm_->set_property (&iogr_prop,
73 new_ref.in ());
75 // Set the primary
76 // See we are setting the second ior as the primary
77 retval = this->iorm_->set_primary (&iogr_prop,
78 remote_server.in (),
79 new_ref.in ());
81 ACE_UNUSED_ARG (retval);
83 return new_ref._retn ();
86 /// Thread entry point
87 int Client_Task::svc ()
89 try
91 // Get a ref to the IORManipulation object
92 CORBA::Object_var IORM =
93 corb_->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
94 0);
96 // Narrow
97 this->iorm_ =
98 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in());
100 CORBA::Object_var iogr = make_iogr ("Domain_1", 1, 1);
102 CORBA::String_var iorgr_string =
103 corb_->object_to_string (iogr.in ());
105 CORBA::Object_var object =
106 corb_->string_to_object (iorgr_string.in ());
108 Test_var server =
109 Test::_narrow (object.in ());
111 if (CORBA::is_nil (server.in ()))
113 ACE_ERROR_RETURN ((LM_ERROR,
114 "Object reference <%s> is nil\n", iorgr_string.in()), 1);
117 CORBA::Object_var remote_server(
118 corb_->string_to_object (ACE_TString(file_prefix + this->server_ior_file_).c_str()));
120 Test_var remote_server_as_test =
121 Test::_narrow (remote_server.in ());
123 CORBA::Object_var collocated_server(
124 corb_->string_to_object (ACE_TString(file_prefix + this->collocated_ior_file_).c_str()));
126 Test_var collocated_server_as_test =
127 Test::_narrow (collocated_server.in ());
129 if (!collocated_server->_is_collocated())
130 { // Collocation is disabled, just skip the test - it has no sense.
131 ACE_DEBUG ((LM_ERROR, "Test has no sense, because collocation is disabled.\n"));
133 else
137 // Following call will fail if the problem is not fixed.
139 // Because we are using TRANSIENT objects with the SYSTEM_ID policy
140 // the object keys won't match so the POA won't be able to dispatch locally.
141 // This wouldn't work with 'direct' collocation strategy but the default is 'through poa'.
142 server->myMethod ();
144 catch (const CORBA::Exception& ex)
146 ex._tao_print_exception ("Exception caught in client task:");
150 remote_server_as_test->shutdown();
152 collocated_server_as_test->shutdown();
154 catch (const CORBA::Exception& ex)
156 ex._tao_print_exception ("Exception caught in client task:");
157 return 1;
160 return 0;