2 #include "StubFaultAnalyzer.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
5 // FUZZ: disable check_for_streams_include
6 #include "ace/streams.h"
7 #include "ace/OS_NS_stdio.h"
9 StubFaultAnalyzer::StubFaultAnalyzer ()
17 StubFaultAnalyzer::~StubFaultAnalyzer ()
22 int StubFaultAnalyzer::parse_args (int argc
, ACE_TCHAR
* argv
[])
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:r:d:n:"));
27 while ((c
= get_opts ()) != -1)
33 this->replicaIORs
.push_back (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
38 this->detector_ior_
= get_opts
.opt_arg ();
43 this->notifier_ior_
= get_opts
.opt_arg ();
48 this->readyFile_
= get_opts
.opt_arg ();
63 if (0 == replicaIORs
.size())
66 "at least one -r option is required.\n"
71 if (0 == this->detector_ior_
)
74 "-d option is required.\n"
78 if (0 == this->notifier_ior_
)
81 "-n option is required.\n"
91 " -r <replica.ior[,replica.ior]>"
93 " -o <ready.file>" // note: not an IOR file. just an "I'm alive" indicator."
103 * Register this object as necessary
105 int StubFaultAnalyzer::init (CORBA::ORB_ptr orb
)
108 this->orb_
= CORBA::ORB::_duplicate (orb
);
109 //////////////////////////////////////////
110 // resolve reference to detector factory
111 CORBA::Object_var detector_obj
= this->orb_
->string_to_object(this->detector_ior_
);
112 this->factory_
= ::FT::FaultDetectorFactory::_narrow(detector_obj
.in ());
113 if (CORBA::is_nil(this->factory_
.in ()))
115 ACE_OS::fprintf (stderr
, "Can't resolve Detector Factory IOR %s\n",
116 ACE_TEXT_ALWAYS_CHAR (this->detector_ior_
));
120 //////////////////////////////////////////
121 // resolve references to notifier
122 CORBA::Object_var not_obj
= this->orb_
->string_to_object(this->notifier_ior_
);
123 this->notifier_
= ::FT::FaultNotifier::_narrow(not_obj
.in ());
124 if (CORBA::is_nil(this->notifier_
.in ()))
126 ACE_OS::fprintf (stderr
, "Can't resolve Notifier IOR %s\n",
127 ACE_TEXT_ALWAYS_CHAR (this->notifier_ior_
));
132 //////////////////////////////////
133 // register fault consumers
136 result
= this->faultConsumer_
.init (orb
, this->notifier_
);
141 result
= this->batchConsumer_
.init (orb
, this->notifier_
);
144 /////////////////////////
145 // Set up fault detectors
148 ////////////////////////////////////
149 // resolve references to replicas
150 // create a fault detector for each replica
151 size_t replicaCount
= this->replicaIORs
.size();
152 for(size_t nRep
= 0; result
== 0 && nRep
< replicaCount
; ++nRep
)
154 const char * iorName
= this->replicaIORs
[nRep
];
155 CORBA::Object_var rep_obj
= this->orb_
->string_to_object(iorName
);
156 FT::PullMonitorable_var replica
= FT::PullMonitorable::_narrow(rep_obj
.in ());
157 if (CORBA::is_nil(replica
.in ()))
159 ACE_OS::fprintf (stderr
, "Can't resolve Replica IOR %s\n", iorName
);
164 this->replicas_
.push_back(replica
);
166 CORBA::String_var type_id
= CORBA::string_dup("FaultDetector");
168 TAO_PG::Properties_Encoder encoder
;
170 PortableGroup::Value value
;
171 value
<<= this->notifier_
.in ();
172 encoder
.add(::FT::FT_NOTIFIER
, value
);
174 value
<<= replica
.in ();
175 encoder
.add(::FT::FT_MONITORABLE
, value
);
177 FT::FTDomainId domain_id
= 0;
179 encoder
.add(::FT::FT_DOMAIN_ID
, value
);
181 PortableGroup::Location object_location
;
182 object_location
.length(1);
183 object_location
[0].id
= CORBA::string_dup("Test location");
184 value
<<= object_location
;
185 encoder
.add(::FT::FT_LOCATION
, value
);
187 PortableGroup::TypeId object_type
= CORBA::string_dup("dummy_type");
188 value
<<= object_type
;
189 encoder
.add(::FT::FT_TYPE_ID
, value
);
191 FT::ObjectGroupId group_id
= 0;
193 encoder
.add(::FT::FT_GROUP_ID
, value
);
195 // allocate and populate the criteria
196 PortableGroup::Criteria_var criteria
;
197 ACE_NEW_NORETURN (criteria
,
198 PortableGroup::Criteria
);
199 if (criteria
.ptr() == 0)
202 "Error cannot allocate criteria.\n"
208 encoder
.encode(criteria
);
209 PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id
;
212 "Call create_object with type: %s\n", type_id
.in()
214 this->factory_
->create_object (
217 factory_creation_id
);
222 if (result
== 0 && this->readyFile_
!= 0)
224 FILE *ready
= ACE_OS::fopen (this->readyFile_
, "w");
227 ACE_OS::fprintf (ready
, "ready\n");
228 ACE_OS::fclose (ready
);
237 * Return a string to identify this object for logging/console message purposes.
239 const char * StubFaultAnalyzer::identity () const
241 return this->identity_
.c_str();
245 * Clean house for process shut down.
247 int StubFaultAnalyzer::fini (void)
249 this->faultConsumer_
.fini();
250 this->batchConsumer_
.fini();
255 int StubFaultAnalyzer::idle(int & result
)
257 ACE_UNUSED_ARG(result
);
260 if (this->replicas_
.size() == this->faultConsumer_
.notifications())