2 #include "ReplicationManagerFaultConsumerAdapter.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
5 #include "orbsvcs/FT_ReplicationManager/FT_DefaultFaultAnalyzer.h"
6 // FUZZ: disable check_for_streams_include
7 #include "ace/streams.h"
8 #include "ace/OS_NS_stdio.h"
10 ReplicationManagerFaultConsumerAdapter::ReplicationManagerFaultConsumerAdapter()
11 : orb_(CORBA::ORB::_nil())
15 , factory_(FT::FaultDetectorFactory::_nil())
17 , notifier_(FT::FaultNotifier::_nil())
18 , p_fault_consumer_(0)
19 , consumer_servant_(0)
24 ReplicationManagerFaultConsumerAdapter::~ReplicationManagerFaultConsumerAdapter()
28 size_t ReplicationManagerFaultConsumerAdapter::notifications () const
30 // Delegate to the FT_FaultConsumer.
31 return this->p_fault_consumer_
->notifications ();
35 int ReplicationManagerFaultConsumerAdapter::parse_args (int argc
, ACE_TCHAR
* argv
[])
38 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:r:d:n:"));
40 while ((c
= get_opts ()) != -1)
46 this->replica_iors_
.push_back (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
51 this->detector_ior_
= get_opts
.opt_arg ();
56 this->notifier_ior_
= get_opts
.opt_arg ();
61 this->readyFile_
= get_opts
.opt_arg ();
76 if (0 == this->replica_iors_
.size())
79 "-r option is required.\n"
83 if (0 == this->detector_ior_
)
86 "-d option is required.\n"
96 " -r <replica.ior[ -r replica.ior]>"
99 " -n <nameService name>"
108 * Register this object.
110 int ReplicationManagerFaultConsumerAdapter::init (
115 ACE_TEXT ("Entered ReplicationManagerFaultConsumerAdapter::init.\n")
119 this->orb_
= CORBA::ORB::_duplicate (orb
);
121 //////////////////////////////////////////
122 // resolve reference to detector factory
125 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
126 ACE_TEXT ("Getting ready to read iorDetectorFile.\n")
129 CORBA::Object_var detector_obj
= this->orb_
->string_to_object (
130 this->detector_ior_
);
131 this->factory_
= ::FT::FaultDetectorFactory::_narrow (
133 if (CORBA::is_nil (this->factory_
.in()))
137 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
138 ACE_TEXT ("FaultDetectorFactory IOR is nil: %s\n"),
139 this->detector_ior_
),
143 //////////////////////////////////////////
144 // resolve references to notifier
147 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
148 ACE_TEXT ("Getting ready to read Notifier IOR file.\n")
151 CORBA::Object_var notifier_ior
= this->orb_
->string_to_object (
152 this->notifier_ior_
);
153 this->notifier_
= ::FT::FaultNotifier::_narrow (
155 if (CORBA::is_nil (this->notifier_
.in()))
159 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
160 ACE_TEXT ("FaultNotifier IOR is nil: %s\n"),
161 this->notifier_ior_
),
165 // Create the real FaultConsumer.
167 // Note: We have to hang onto the servant class pointer so we can
168 // invoke member functions on it, but we also give ownership of it
169 // to a PortableServer::ServantBase_var.
172 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
173 ACE_TEXT ("Getting ready to create the real FaultConsumer.\n")
176 ACE_NEW_RETURN (this->p_fault_consumer_
, TAO::FT_FaultConsumer (), -1);
177 if (this->p_fault_consumer_
!= 0)
179 this->consumer_servant_
= this->p_fault_consumer_
;
182 //////////////////////////
183 // Get ready to initialize the consumer. We need to provide it
184 // with the following:
185 // - The POA in which it is to be activated.
186 // - FT::FaultNotifier IOR.
187 // - FT::ReplicationManager IOR (fake it for now).
189 // Get the RootPOA from the ORB.
190 CORBA::Object_var poa_obj
= this->orb_
->resolve_initial_references (
192 PortableServer::POA_var poa
= PortableServer::POA::_narrow (
195 // Create a fault analyzer.
196 TAO::FT_FaultAnalyzer
* analyzer
= 0;
197 ACE_NEW_RETURN (analyzer
, TAO::FT_DefaultFaultAnalyzer (), -1);
199 // Initialize the FaultConsumer.
200 // It will activate itself in the POA we pass it and connect to the
201 // Fault Notifier we pass it.
204 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
205 ACE_TEXT ("Getting ready to initialize the real FaultConsumer.\n")
208 result
= this->p_fault_consumer_
->init (
210 this->notifier_
.in(),
216 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
217 ACE_TEXT ("Unable to initialize the real FaultConsumer.\n")),
221 this->identity_
= "ReplicationManagerFaultConsumerAdapter";
223 // Activate the RootPOA.
224 PortableServer::POAManager_var poa_manager
=
225 poa
->the_POAManager ();
226 poa_manager
->activate ();
228 /////////////////////////
229 // Set up fault detectors
232 ////////////////////////////////////
233 // resolve references to replicas
234 // create a fault detector for each replica
235 size_t replicaCount
= this->replica_iors_
.size();
236 ACE_DEBUG ((LM_DEBUG
,
237 ACE_TEXT ("Number of replicas being monitored: (%u)\n"),
238 static_cast<unsigned int> (replicaCount
)
240 for (size_t nRep
= 0; result
== 0 && nRep
< replicaCount
; ++nRep
)
242 const char * iorName
= this->replica_iors_
[nRep
];
243 CORBA::Object_var replica_obj
= this->orb_
->string_to_object (
245 FT::PullMonitorable_var replica
= FT::PullMonitorable::_narrow (
247 if (CORBA::is_nil(replica
.in()))
251 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
252 ACE_TEXT ("Can't resolve Replica IOR: %s\n"),
258 this->replicas_
.push_back(replica
);
260 CORBA::String_var type_id
= CORBA::string_dup("FaultDetector");
262 TAO_PG::Properties_Encoder encoder
;
264 PortableGroup::Value value
;
265 value
<<= notifier_
.in ();
266 encoder
.add(::FT::FT_NOTIFIER
, value
);
268 value
<<= replica
.in ();
269 encoder
.add(::FT::FT_MONITORABLE
, value
);
271 FT::FTDomainId domain_id
= 0;
273 encoder
.add(::FT::FT_DOMAIN_ID
, value
);
275 PortableGroup::Location object_location
;
276 object_location
.length(2);
277 object_location
[0].id
= CORBA::string_dup("test");
278 object_location
[1].id
= CORBA::string_dup("Location_A");
279 value
<<= object_location
;
280 encoder
.add(::FT::FT_LOCATION
, value
);
282 PortableGroup::TypeId_var object_type
= CORBA::string_dup (
283 "IDL:org.omg/CosNaming/NamingContextExt:1.0");
284 value
<<= object_type
.in ();
285 encoder
.add(::FT::FT_TYPE_ID
, value
);
287 PortableGroup::ObjectGroupId group_id
=
288 static_cast<PortableGroup::ObjectGroupId
> (6191982);
290 encoder
.add(::FT::FT_GROUP_ID
, value
);
292 // allocate and populate the criteria
293 PortableGroup::Criteria_var criteria
;
294 ACE_NEW_NORETURN (criteria
,
295 PortableGroup::Criteria
);
296 if (criteria
.ptr() == 0)
300 ACE_TEXT ("ReplicationManagerFaultConsumerAdapter::init: ")
301 ACE_TEXT ("Error cannot allocate criteria.\n")),
306 encoder
.encode(criteria
);
307 PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id
;
309 this->factory_
->create_object (
312 factory_creation_id
);
317 // Signal that we are ready to go.
318 if (result
== 0 && this->readyFile_
!= 0)
320 FILE* ready
= ACE_OS::fopen (this->readyFile_
, "w");
323 ACE_OS::fprintf (ready
, "ready\n");
324 ACE_OS::fclose (ready
);
333 * Return a string to identify this object for logging/console message purposes.
335 const char * ReplicationManagerFaultConsumerAdapter::identity () const
337 return this->identity_
.c_str();
341 * Clean house for process shut down.
343 int ReplicationManagerFaultConsumerAdapter::fini ()
345 // Delegate to the FT_FaultConsumer.
346 return this->p_fault_consumer_
->fini ();
350 int ReplicationManagerFaultConsumerAdapter::idle(int & result
)
352 ACE_UNUSED_ARG(result
);
355 if (this->replicas_
.size() == this->p_fault_consumer_
->notifications())