Go to the documentation of this file.00001
00002
00003 #include "orbsvcs/orbsvcs/Notify/MonitorControl/NotificationServiceMonitor_i.h"
00004
00005 #include "tao/Monitor/Monitor_Impl.h"
00006 #include "ace/Auto_Ptr.h"
00007 #include "ace/Monitor_Point_Registry.h"
00008 #include "ace/Monitor_Base.h"
00009
00010 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
00011
00012 #include "orbsvcs/orbsvcs/Notify/MonitorControl/Control_Registry.h"
00013
00014 using namespace ACE_VERSIONED_NAMESPACE_NAME::ACE::Monitor_Control;
00015
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 NotificationServiceMonitor_i::NotificationServiceMonitor_i (CORBA::ORB_ptr orb)
00019 : orb_ (CORBA::ORB::_duplicate (orb))
00020 {
00021 }
00022
00023 Monitor::NameList*
00024 NotificationServiceMonitor_i::get_statistic_names (void)
00025 {
00026 Monitor_Control_Types::NameList name_list =
00027 Monitor_Point_Registry::instance ()->names ();
00028 CORBA::ULong the_length = name_list.size ();
00029
00030 Monitor::NameList* the_names = 0;
00031 ACE_NEW_RETURN (the_names,
00032 Monitor::NameList (the_length),
00033 0);
00034 Monitor::NameList_var safe_names = the_names;
00035 the_names->length (the_length);
00036 CORBA::ULong i = 0;
00037
00038 for (Monitor_Control_Types::NameList::Iterator iter (name_list);
00039 !iter.done ();
00040 iter.advance (), ++i)
00041 {
00042 ACE_CString* tmp = 0;
00043 iter.next (tmp);
00044 safe_names[i] = tmp->c_str ();
00045 }
00046
00047 return safe_names._retn ();
00048 }
00049
00050 Monitor::Data*
00051 NotificationServiceMonitor_i::get_statistic (const char* name)
00052 {
00053 Monitor_Point_Registry* registry = Monitor_Point_Registry::instance ();
00054
00055 Monitor::NameList invalid;
00056 Monitor::NameList names (1);
00057 names.length (1);
00058 names[0] = name;
00059 this->get_invalid_names (registry, names, invalid);
00060
00061 if (invalid.length () > 0)
00062 {
00063 throw CosNotification::NotificationServiceMonitorControl::InvalidName (invalid);
00064 }
00065
00066 Monitor::Data* data = 0;
00067 ACE_NEW_THROW_EX (data,
00068 Monitor::Data,
00069 CORBA::NO_MEMORY ());
00070 this->get_data (registry, name, *data);
00071 return data;
00072 }
00073
00074 Monitor::DataList*
00075 NotificationServiceMonitor_i::get_statistics (const Monitor::NameList& names)
00076 {
00077 Monitor_Point_Registry* registry = Monitor_Point_Registry::instance ();
00078
00079 Monitor::NameList invalid;
00080 this->get_invalid_names (registry, names, invalid);
00081
00082 if (invalid.length () > 0)
00083 {
00084 throw CosNotification::NotificationServiceMonitorControl::InvalidName (invalid);
00085 }
00086
00087 CORBA::ULong const length = names.length ();
00088 Monitor::DataList* data = 0;
00089 ACE_NEW_RETURN (data,
00090 Monitor::DataList (
00091 length),
00092 0);
00093 ACE_Auto_Basic_Ptr<Monitor::DataList> safe_data (data);
00094
00095 data->length (length);
00096
00097 for (CORBA::ULong i = 0; i < length; ++i)
00098 {
00099 this->get_data (registry, names[i], (*data)[i]);
00100 }
00101
00102 return safe_data.release ();
00103 }
00104
00105 Monitor::DataList*
00106 NotificationServiceMonitor_i::get_and_clear_statistics (
00107 const Monitor::NameList& names)
00108 {
00109 Monitor::DataList* data =
00110 this->get_statistics (names);
00111
00112
00113
00114
00115
00116 CORBA::ULong length = names.length();
00117 Monitor_Point_Registry* registry = Monitor_Point_Registry::instance ();
00118
00119 for (CORBA::ULong i = 0; i < length; ++i)
00120 {
00121 Monitor_Base* statistic = registry->get (names[i].in ());
00122
00123 if (statistic != 0)
00124 {
00125 statistic->clear ();
00126 }
00127 }
00128
00129 return data;
00130 }
00131
00132 void
00133 NotificationServiceMonitor_i::clear_statistics (
00134 const Monitor::NameList& names)
00135 {
00136 Monitor_Point_Registry* registry = Monitor_Point_Registry::instance ();
00137
00138 Monitor::NameList invalid;
00139 this->get_invalid_names (registry, names, invalid);
00140
00141 if (invalid.length () > 0)
00142 {
00143 throw CosNotification::NotificationServiceMonitorControl::InvalidName (invalid);
00144 }
00145
00146 CORBA::ULong const length = names.length ();
00147
00148 for (CORBA::ULong i = 0; i < length; ++i)
00149 {
00150 Monitor_Base* statistic = registry->get (names[i].in ());
00151
00152 if (statistic != 0)
00153 {
00154 statistic->clear ();
00155 }
00156 }
00157 }
00158
00159 void
00160 NotificationServiceMonitor_i::shutdown_event_channel (const char* name)
00161 {
00162 this->send_control_command (name, TAO_NS_CONTROL_SHUTDOWN);
00163 }
00164
00165 void
00166 NotificationServiceMonitor_i::remove_consumer (const char* name)
00167 {
00168 this->send_control_command (name, TAO_NS_CONTROL_REMOVE_CONSUMER);
00169 }
00170
00171 void
00172 NotificationServiceMonitor_i::remove_supplier (const char* name)
00173 {
00174 this->send_control_command (name, TAO_NS_CONTROL_REMOVE_SUPPLIER);
00175 }
00176
00177 void
00178 NotificationServiceMonitor_i::remove_consumeradmin (const char* name)
00179 {
00180 this->send_control_command (name, TAO_NS_CONTROL_REMOVE_CONSUMERADMIN);
00181 }
00182
00183 void
00184 NotificationServiceMonitor_i::remove_supplieradmin (const char* name)
00185 {
00186 this->send_control_command (name, TAO_NS_CONTROL_REMOVE_SUPPLIERADMIN);
00187 }
00188
00189 void
00190 NotificationServiceMonitor_i::send_control_command (const char* name,
00191 const char* cmd)
00192 {
00193 TAO_Control_Registry* instance = TAO_Control_Registry::instance ();
00194 TAO_NS_Control* control = instance->get (name);
00195
00196
00197
00198
00199
00200
00201 if (control == 0 || !control->execute (cmd))
00202 {
00203 Monitor::NameList invalid (1);
00204 invalid.length (1);
00205 invalid[0] = name;
00206 throw CosNotification::NotificationServiceMonitorControl::InvalidName (invalid);
00207 }
00208 }
00209
00210 void
00211 NotificationServiceMonitor_i::shutdown (void)
00212 {
00213 if (!CORBA::is_nil (this->orb_.in ()))
00214 {
00215 this->orb_->shutdown ();
00216 }
00217 }
00218
00219 void
00220 NotificationServiceMonitor_i::get_data (
00221 Monitor_Point_Registry* registry,
00222 const char* name,
00223 Monitor::Data& data)
00224 {
00225
00226 Monitor_Base* monitor = registry->get (name);
00227
00228 if (monitor == 0)
00229 {
00230
00231
00232
00233
00234 Monitor::Numeric num;
00235 num.count = 0;
00236 num.average = 0;
00237 num.sum_of_squares = 0;
00238 num.minimum = 0;
00239 num.maximum = 0;
00240 num.last = 0;
00241 }
00242 else
00243 {
00244 TAO_Monitor::get_monitor_data (monitor, data, false);
00245 }
00246 }
00247
00248 void
00249 NotificationServiceMonitor_i::get_invalid_names (
00250 Monitor_Point_Registry* registry,
00251 const Monitor::NameList& names,
00252 Monitor::NameList& invalid)
00253 {
00254 invalid.length (0);
00255
00256 CORBA::ULong ilength = 0;
00257 CORBA::ULong const length = names.length ();
00258
00259 for (CORBA::ULong i = 0; i < length; ++i)
00260 {
00261 if (registry->get (names[i].in ()) == 0)
00262 {
00263 if (TAO_debug_level > 7)
00264 {
00265 ACE_DEBUG((LM_INFO,
00266 ACE_TEXT("(%P|%t) TAO_NotificationServiceMonitor: Client requested invalid statistic name: %s"),
00267 names[i].in ()));
00268 }
00269 invalid.length (ilength + 1);
00270 invalid[ilength++] = CORBA::string_dup (names[i]);
00271 }
00272 }
00273 }
00274
00275 TAO_END_VERSIONED_NAMESPACE_DECL
00276
00277 #endif