Go to the documentation of this file.00001
00002
00003
00004 #include "tao/Monitor/Monitor_Impl.h"
00005
00006 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
00007
00008 #include "ace/Monitor_Point_Registry.h"
00009 #include "ace/Monitor_Control_Action.h"
00010 #include "ace/Monitor_Control/Monitor_Control.h"
00011
00012 ACE_RCSID (Monitor,
00013 Monitor_Impl,
00014 "$Id: Monitor_Impl.cpp 87254 2009-10-29 02:14:18Z dai_y $")
00015
00016 class TAO_Control_Action : public Control_Action
00017 {
00018 public:
00019 TAO_Control_Action (::Monitor::Subscriber_ptr sub)
00020 : sub_ (::Monitor::Subscriber::_duplicate (sub))
00021 {
00022 }
00023
00024 virtual void execute (const char* )
00025 {
00026 try
00027 {
00028
00029 ::Monitor::DataList d;
00030 sub_->push (d);
00031 }
00032 catch (const ::CORBA::Exception&)
00033 {
00034 }
00035 }
00036
00037 private:
00038 ::Monitor::Subscriber_var sub_;
00039 };
00040
00041 Monitor_Impl::Monitor_Impl (CORBA::ORB_ptr orb)
00042 : orb_ (CORBA::ORB::_duplicate (orb))
00043 {
00044 }
00045
00046 ::Monitor::NameList *
00047 Monitor_Impl::get_statistic_names (const char * filter)
00048 {
00049 Monitor_Control_Types::NameList mc_names =
00050 Monitor_Point_Registry::instance ()->names ();
00051
00052 ::Monitor::NameList *namelist = 0;
00053 ACE_NEW_THROW_EX (namelist,
00054 ::Monitor::NameList (mc_names.size ()),
00055 CORBA::NO_MEMORY ());
00056
00057 CORBA::ULong index = 0;
00058
00059 for (Monitor_Control_Types::NameList::Iterator i (mc_names);
00060 !i.done ();
00061 i.advance (), ++index)
00062 {
00063 ACE_CString *item = 0;
00064 i.next (item);
00065
00066 if (ACE::wild_match (item->c_str (), filter, false))
00067 {
00068 CORBA::ULong const length = namelist->length ();
00069 namelist->length (length + 1);
00070 (*namelist)[length] = CORBA::string_dup (item->c_str ());
00071 }
00072 }
00073
00074 return namelist;
00075 }
00076
00077 ::Monitor::DataList *
00078 Monitor_Impl::get_statistics (const ::Monitor::NameList & names)
00079 {
00080 ::Monitor::DataList *datalist = 0;
00081 ACE_NEW_THROW_EX (datalist,
00082 ::Monitor::DataList (names.length ()),
00083 CORBA::NO_MEMORY ());
00084
00085
00086 MC_ADMINMANAGER* mgr =
00087 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
00088
00089
00090 for (CORBA::ULong index = 0; index < names.length (); ++index)
00091 {
00092
00093 ACE::Monitor_Control::Monitor_Base *monitor =
00094 mgr->admin ().monitor_point (names[index]);
00095
00096 if (monitor != 0)
00097 {
00098 Monitor_Control_Types::Data d (monitor->type ());
00099 CORBA::ULong const length = datalist->length();
00100 datalist->length (length + 1);
00101 ::Monitor::Data data;
00102 TAO_Monitor::get_monitor_data (monitor, data, false);
00103 (*datalist)[length] = data;
00104
00105 monitor->remove_ref ();
00106 }
00107 }
00108
00109 return datalist;
00110 }
00111
00112 ::Monitor::DataList *
00113 Monitor_Impl::get_and_clear_statistics (const ::Monitor::NameList & names)
00114 {
00115 ::Monitor::DataList *datalist = 0;
00116 ACE_NEW_THROW_EX (datalist,
00117 ::Monitor::DataList (names.length ()),
00118 CORBA::NO_MEMORY ());
00119
00120
00121 MC_ADMINMANAGER* mgr =
00122 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
00123
00124 for (CORBA::ULong index = 0; index < names.length (); ++index)
00125 {
00126
00127 ACE::Monitor_Control::Monitor_Base *monitor =
00128 mgr->admin ().monitor_point (names[index]);
00129
00130 if (monitor != 0)
00131 {
00132 CORBA::ULong const length = datalist->length();
00133 datalist->length (length + 1);
00134 ::Monitor::Data data;
00135 TAO_Monitor::get_monitor_data (monitor, data, true);
00136 (*datalist)[length] = data;
00137
00138 monitor->remove_ref ();
00139 }
00140 }
00141
00142 return datalist;
00143 }
00144
00145 void
00146 TAO_Monitor::get_monitor_data (
00147 ACE::Monitor_Control::Monitor_Base *monitor,
00148 Monitor::Data& data,
00149 bool clear)
00150 {
00151
00152
00153
00154 if (monitor->type () != Monitor_Control_Types::MC_COUNTER)
00155 {
00156 monitor->update ();
00157 }
00158
00159
00160 if (monitor->type () == Monitor_Control_Types::MC_LIST)
00161 {
00162 Monitor_Control_Types::NameList slist (monitor->get_list ());
00163 CORBA::ULong size = static_cast<CORBA::ULong> (slist.size ());
00164 Monitor::NameList list (size);
00165 list.length (size);
00166
00167 for (CORBA::ULong i = 0; i < size; ++i)
00168 {
00169 list[i] = CORBA::string_dup (slist[i].c_str ());
00170 }
00171
00172 data.data_union._d (::Monitor::DATA_TEXT);
00173 data.data_union.list (list);
00174 }
00175 else
00176 {
00177 Monitor::Numeric num;
00178 num.count = static_cast<CORBA::ULong> (monitor->count ());
00179 num.minimum = monitor->minimum_sample ();
00180 num.maximum = monitor->maximum_sample ();
00181 num.last = monitor->last_sample ();
00182 num.dlist.length (1);
00183 num.dlist[0].value = monitor->last_sample ();
00184 Monitor_Control_Types::Data d (monitor->type ());
00185 if (clear)
00186 {
00187 monitor->retrieve_and_clear (d);
00188 }
00189 else
00190 {
00191 monitor->retrieve (d);
00192 }
00193 ACE_UINT64 usecs;
00194 d.timestamp_.to_usec (usecs);
00195
00196 if (monitor->type() == Monitor_Control_Types::MC_COUNTER)
00197 {
00198 num.average = 0;
00199 num.sum_of_squares = 0;
00200 }
00201 else
00202 {
00203 num.average = monitor->average ();
00204 num.sum_of_squares = monitor->sum_of_squares ();
00205 }
00206
00207 data.data_union._d (::Monitor::DATA_NUMERIC);
00208 data.data_union.num (num);
00209 data.data_union.num ().dlist[0].value = d.value_;
00210 data.data_union.num ().dlist[0].timestamp = usecs;
00211 }
00212 }
00213
00214
00215 ::Monitor::NameList *
00216 Monitor_Impl::clear_statistics (const ::Monitor::NameList & names)
00217 {
00218 ::Monitor::NameList *namelist = 0;
00219 ACE_NEW_THROW_EX (namelist,
00220 ::Monitor::NameList (names.length ()),
00221 CORBA::NO_MEMORY ());
00222 namelist->length (0UL);
00223
00224
00225 MC_ADMINMANAGER* mgr =
00226 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
00227
00228 for (CORBA::ULong index = 0; index < names.length (); ++index)
00229 {
00230
00231 ACE::Monitor_Control::Monitor_Base *monitor =
00232 mgr->admin ().monitor_point (names[index]);
00233
00234 if (monitor != 0) {
00235 CORBA::ULong const length = namelist->length ();
00236 namelist->length (length + 1);
00237 (*namelist)[length] = CORBA::string_dup (names[index].in ());
00238 monitor->clear ();
00239
00240 monitor->remove_ref ();
00241 }
00242 }
00243
00244 return namelist;
00245 }
00246
00247 ::Monitor::ConstraintStructList *
00248 Monitor_Impl::register_constraint (
00249 const ::Monitor::NameList & names,
00250 const char * cs,
00251 ::Monitor::Subscriber_ptr sub)
00252 {
00253 ::Monitor::ConstraintStructList *constraintlist = 0;
00254 ACE_NEW_THROW_EX (constraintlist,
00255 ::Monitor::ConstraintStructList (names.length ()),
00256 CORBA::NO_MEMORY ());
00257 constraintlist->length (0UL);
00258
00259 MC_ADMINMANAGER* mgr =
00260 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
00261
00262 for (CORBA::ULong index = 0; index < names.length (); ++index)
00263 {
00264
00265 ACE::Monitor_Control::Monitor_Base *monitor =
00266 mgr->admin ().monitor_point (names[index]);
00267
00268 if (monitor != 0)
00269 {
00270 TAO_Control_Action* ca = new TAO_Control_Action (sub);
00271 long id = monitor->add_constraint (cs, ca);
00272 CORBA::ULong const length = constraintlist->length ();
00273 constraintlist->length (length + 1);
00274 (*constraintlist)[length].id = id;
00275 (*constraintlist)[length].itemname =
00276 CORBA::string_dup (names[index].in ());
00277
00278 monitor->remove_ref ();
00279 }
00280 }
00281
00282 return constraintlist;
00283 }
00284
00285 void
00286 Monitor_Impl::unregister_constraints (
00287 const ::Monitor::ConstraintStructList & constraint)
00288 {
00289 MC_ADMINMANAGER* mgr =
00290 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
00291
00292 for (CORBA::ULong index = 0; index < constraint.length (); ++index)
00293 {
00294
00295 ACE::Monitor_Control::Monitor_Base *monitor =
00296 mgr->admin ().monitor_point (constraint[index].itemname.in ());
00297
00298 if (monitor != 0)
00299 {
00300 ACE::Monitor_Control::Control_Action *action =
00301 monitor->remove_constraint (constraint[index].id);
00302
00303 if (action != 0)
00304 {
00305 action->remove_ref ();
00306 }
00307
00308 monitor->remove_ref ();
00309 }
00310 }
00311 }
00312
00313 #endif
00314