ACE/FAQ/APG/Naming
Материал из Wiki.crossplatform.ru
(Различия между версиями)
ViGOur (Обсуждение | вклад)
(Новая страница: «__TOC__ Категория:ACE FAQ == EMail.h == <source lang="cpp"> // $Id: EMail.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef EMAIL_H #define EMAIL_H #inclu…»)
(Новая страница: «__TOC__ Категория:ACE FAQ == EMail.h == <source lang="cpp"> // $Id: EMail.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef EMAIL_H #define EMAIL_H #inclu…»)
Текущая версия на 19:04, 6 февраля 2012
EMail.h
// $Id: EMail.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef EMAIL_H #define EMAIL_H #include "ace/Log_Msg.h" class EMail { public: EMail() { } int send (const char *to, const char *from, const char *subject, const char *message) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("To:\t%s\n"), to)); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("From:\t%s\n"), from)); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Subject:\t%s\n"), subject)); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("\n%s\n"), message)); return 0; } }; #endif /* EMAIL_H */
Graph.h
// $Id: Graph.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef GRAPH_H #define GRAPH_H #include "Graphable_Element.h" class Graph { public: Graph() { } void graph( char * filename, Graphable_Element_List & data ); }; #endif /* GRAPH_H */
Graph.cpp
// $Id: Graph.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "ace/Log_Msg.h" #include "Graph.h" void Graph::graph (char *filename, Graphable_Element_List &data) { data.sort (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Save graph to %C\n"), filename)); char h[10][10]; for (int n = 0 ; n < 10 ; ++n ) { for (int j = 0; j < 10; ++j ) { h[n][j] = ' '; } } int l[10]; int k = 0; for (Graphable_Element_List::iterator i = data.begin (); i != data.end (); ++i, ++k ) { l[k] = (*i).when (); int temp = (int)((*i).temp () - 80.0); for (int j = 0; j <= temp; ++j) { h[k][j] = '#'; } } for (int m = 0 ; m < 10 ; ++m) { ACE_DEBUG ((LM_INFO, ACE_TEXT ("%d "), l[m])); for (int j = 0; j < 10; ++j) { ACE_DEBUG ((LM_INFO, ACE_TEXT ("%c"), h[m][j])); } ACE_DEBUG ((LM_INFO, ACE_TEXT ("\n"))); } }
Graphable_Element.h
/* -*- C++ -*- */ // $Id: Graphable_Element.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef GRAPHABLE_ELEMENT_H #define GRAPHABLE_ELEMENT_H #include "Name_Binding.h" #include <list> // A helper class that knows how to sort two ACE_Name_Binding objects // which contain temperature metrics. The value stored in the binding // is expected to be of the format "time|temp". // // Listing 1 code/ch21 class Graphable_Element : public Name_Binding { public: Graphable_Element (ACE_Name_Binding *entry) : Name_Binding(entry) { sscanf (this->value (), "%d|%f", &this->when_, &this->temp_); } // Listing 1 // Listing 2 code/ch21 inline int when (void) const { return this->when_; } inline float temp (void) { return this->temp_; } // Listing 2 // Listing 3 code/ch21 inline bool operator< (const Graphable_Element &other) const { return this->when () < other.when (); } // Listing 3 // Listing 4 code/ch21 private: int when_; float temp_; }; typedef std::list<Graphable_Element> Graphable_Element_List; // Listing 4 #endif /* GRAPHABLE_ELEMENT_H */
Name_Binding.h
/* -*- C++ -*- */ // $Id: Name_Binding.h 94076 2011-05-23 07:11:11Z johnnyw $ #ifndef NAME_BINDING_H #define NAME_BINDING_H #include "ace/OS_NS_stdlib.h" #include "ace/OS_NS_string.h" #include "ace/Auto_Ptr.h" #include "ace/Name_Space.h" // Listing 1 code/ch21 class Name_Binding { public: Name_Binding (ACE_Name_Binding *entry) { this->name_ = entry->name_.char_rep (); this->value_ = entry->value_.char_rep (); this->type_ = ACE_OS::strdup (entry->type_); } Name_Binding (const ACE_NS_WString &n, const ACE_NS_WString &v, const char *t) { this->name_ = n.char_rep (); this->value_ = v.char_rep (); this->type_ = ACE_OS::strdup (t); } ~Name_Binding () { delete[] this->name_; delete[] this->value_; ACE_OS::free (const_cast<char*> (this->type_)); this->type_ = 0; } char *name (void) { return this->name_; } char *value (void) { return this->value_; } const char *type (void) { return this->type_; } int int_value (void) { return ACE_OS::atoi (this->value ()); } private: char *name_; char *value_; char *type_; }; typedef auto_ptr<Name_Binding> Name_Binding_Ptr; // Listing 1 #endif /* NAME_BINDING_H */
Naming_Context.h
/* -*- C++ -*- */ // $Id: Naming_Context.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef NAMING_CONTEXT_H #define NAMING_CONTEXT_H #include "ace/Naming_Context.h" #include "ace/OS_NS_stdio.h" #include "Name_Binding.h" // Listing 1 code/ch21 class Naming_Context : public ACE_Naming_Context { public: typedef ACE_Naming_Context inherited; int rebind (const char *name_in, const char *value_in, const char *type_in = "") { return this->inherited::rebind (name_in, value_in, type_in); } int rebind (const char *name_in, float value_in, const char *type_in = "") { char buf[BUFSIZ]; ACE_OS::sprintf (buf, "%2f", value_in); return this->inherited::rebind (name_in, (const char *)buf, type_in); } int rebind (const char *name_in, int value_in, const char *type_in = "") { char buf[BUFSIZ]; ACE_OS::sprintf (buf, "%d", value_in ); return this->inherited::rebind (name_in, (const char *)buf, type_in); } // Listing 1 // Listing 2 code/ch21 Name_Binding *fetch (const char *name) { ACE_NS_WString value; char *type = 0; if (this->resolve (name, value, type) != 0 || value.length () < 1) { return 0; } Name_Binding *rval = new Name_Binding (ACE_NS_WString (name), value, type); delete [] type; return rval; } // Listing 2 }; #endif /* NAMING_CONTEXT_H */
Temperature_Grapher.h
// $Id: Temperature_Grapher.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef TEMPERATURE_GRAPHER_H #define TEMPERATURE_GRAPHER_H #include "Thermometer.h" #include "Temperature_Grapher_Options.h" #include "Naming_Context.h" class Temperature_Grapher { public: Temperature_Grapher( Temperature_Grapher_Options & opt, Naming_Context & naming_context ) : opt_(opt), naming_context_(naming_context) { } void monitor(); protected: void update_graph(); private: Thermometer * thermometer_; Temperature_Grapher_Options & opt_; Naming_Context & naming_context_; }; #endif /* TEMPERATURE_GRAPHER_H */
Temperature_Grapher.cpp
// $Id: Temperature_Grapher.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "ace/OS_NS_unistd.h" #include "ace/Log_Msg.h" #include "Graph.h" #include "Graphable_Element.h" #include "Temperature_Grapher.h" // Listing 1 code/ch21 void Temperature_Grapher::monitor (void) { for (;;) { this->update_graph (); ACE_OS::sleep (this->opt_.poll_interval ()); } } // Listing 1 // Listing 2 code/ch21 void Temperature_Grapher::update_graph (void) { Name_Binding_Ptr lastUpdate (this->naming_context_.fetch ("lastUpdate")); if (!lastUpdate.get ()) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("No data to graph\n"))); return; } // Listing 2 // Listing 3 code/ch21 Name_Binding_Ptr lastGraphed (this->naming_context_.fetch ("lastGraphed")); if (lastGraphed.get () && lastGraphed->int_value () == lastUpdate->int_value ()) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Data already graphed\n"))); return; } // Listing 3 // Listing 4 code/ch21 ACE_BINDING_SET set; if (this->naming_context_.list_name_entries (set, "history[") != 0) { ACE_DEBUG ((LM_INFO, ACE_TEXT ("There's nothing to graph\n"))); return; } // Listing 4 // Listing 5 code/ch21 Graphable_Element_List graphable; ACE_BINDING_ITERATOR set_iterator (set); for (ACE_Name_Binding *entry = 0; set_iterator.next (entry) != 0; set_iterator.advance ()) { Name_Binding binding (entry); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\t%s\t%s\n"), binding.type (), binding.name (), binding.value ())); Graphable_Element *ge = new Graphable_Element (entry); graphable.push_back (*ge); } // Listing 5 // Listing 6 code/ch21 Graph g; g.graph (lastUpdate->value (), graphable); this->naming_context_.rebind ("lastGraphed", lastUpdate->int_value ()); // Listing 6 }
Temperature_Grapher_Options.h
// $Id: Temperature_Grapher_Options.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef TEMPERATURE_GRAPHER_OPTIONS_H #define TEMPERATURE_GRAPHER_OPTIONS_H class Temperature_Grapher_Options { public: Temperature_Grapher_Options( int argc, ACE_TCHAR ** argv ) { ACE_UNUSED_ARG(argc); ACE_UNUSED_ARG(argv); } int poll_interval() { return 20; // every 20 seconds } }; #endif /* TEMPERATURE_GRAPHER_OPTIONS_H */
Temperature_Monitor.h
// $Id: Temperature_Monitor.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef TEMPERATURE_MONITOR_H #define TEMPERATURE_MONITOR_H #include "Thermometer.h" #include "Temperature_Monitor_Options.h" #include "Naming_Context.h" class Temperature_Monitor { public: Temperature_Monitor( Temperature_Monitor_Options & opt, Naming_Context & naming_context ); void monitor(); protected: void record_temperature(float temp); void record_failure(); void reset_device(Name_Binding_Ptr & resetCount); private: Thermometer * thermometer_; Temperature_Monitor_Options & opt_; Naming_Context & naming_context_; }; #endif /* TEMPERATURE_MONITOR_H */
Temperature_Monitor.cpp
// $Id: Temperature_Monitor.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "ace/OS_NS_time.h" #include "ace/OS_NS_unistd.h" #include "ace/Log_Msg.h" #include "Thermometer.h" #include "Temperature_Monitor.h" #include "EMail.h" // Listing 1 code/ch21 Temperature_Monitor::Temperature_Monitor (Temperature_Monitor_Options &opt, Naming_Context &naming_context) : opt_(opt), naming_context_(naming_context) { } // Listing 1 // Listing 31 code/ch21 void Temperature_Monitor::record_temperature (float temp) { Name_Binding_Ptr current (this->naming_context_.fetch ("current")); if (current.get()) { this->naming_context_.rebind ("previous", current->value ()); } // Listing 31 // Listing 32 code/ch21 this->naming_context_.rebind ("current", temp); // Listing 32 // Listing 33 code/ch21 this->naming_context_.unbind ("lastReset"); this->naming_context_.unbind ("resetCount"); // Listing 33 } // Listing 41 code/ch21 void Temperature_Monitor::record_failure (void) { Name_Binding_Ptr lastReset (this->naming_context_.fetch ("lastReset")); Name_Binding_Ptr resetCount (this->naming_context_.fetch ("resetCount")); // Listing 41 // Listing 42 code/ch21 int now = (int) ACE_OS::time (); int lastResetTime; if (lastReset.get ()) { lastResetTime = lastReset->int_value (); } else { this->naming_context_.rebind ("lastReset", now); lastResetTime = now; } // Listing 42 // Listing 43 code/ch21 if (now - lastResetTime > this->opt_.reset_interval ()) { this->reset_device (resetCount); } // Listing 43 } // Listing 5 code/ch21 void Temperature_Monitor::reset_device (Name_Binding_Ptr &resetCount) { int number_of_resets = 1; if (resetCount.get ()) { number_of_resets = resetCount->int_value () + 1; if (number_of_resets > this->opt_.excessive_resets ()) { // Exclude 5 EMail notification; char message[BUFSIZ]; ACE_OS::sprintf (message, "Thermometer: %s\n" "Reset Count: %d\n", this->thermometer_->address(), number_of_resets); notification.send (this->opt_.admin_email (), this->opt_.email_from (), "Excessive number of thermometer resets", message); // Exclude 5 } } this->thermometer_->reset (); this->naming_context_.rebind ("lastReset", (int) ACE_OS::time ()); this->naming_context_.rebind ("resetCount", number_of_resets); } // Listing 5 // Listing 2 code/ch21 void Temperature_Monitor::monitor (void) { this->thermometer_ = new Thermometer (this->opt_.thermometer_address ()); for(;;) { float temp = this->thermometer_->temperature (); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Read temperature %.2f\n"), temp)); if (temp >= 0) { this->record_temperature (temp); } else { this->record_failure (); } ACE_OS::sleep (this->opt_.poll_interval ()); } ACE_NOTREACHED (delete this->thermometer_;) } // Listing 2
Temperature_Monitor2.h
// $Id: Temperature_Monitor2.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef TEMPERATURE_MONITOR_H #define TEMPERATURE_MONITOR_H #include "Thermometer.h" #include "Temperature_Monitor_Options.h" #include "Naming_Context.h" class Temperature_Monitor2 { public: Temperature_Monitor2 (Temperature_Monitor_Options & opt, Naming_Context & naming_context, Naming_Context & shared_context) : opt_(opt), naming_context_(naming_context), shared_context_(shared_context) { } void monitor (void); protected: void record_temperature (float temp); void record_history (float temp); void record_failure (void); void reset_device (Name_Binding_Ptr & resetCount); private: Thermometer *thermometer_; Temperature_Monitor_Options &opt_; Naming_Context &naming_context_; Naming_Context &shared_context_; }; #endif /* TEMPERATURE_MONITOR_H */
Temperature_Monitor2.cpp
// $Id: Temperature_Monitor2.cpp 94132 2011-06-01 05:53:39Z msmit $ #include "ace/OS_NS_time.h" #include "ace/OS_NS_unistd.h" #include "ace/Log_Msg.h" #include "Thermometer.h" #include "Temperature_Monitor2.h" #include "EMail.h" // Listing 1 code/ch21 void Temperature_Monitor2::record_temperature (float temp) { Name_Binding_Ptr current (this->naming_context_.fetch ("current")); if (current.get ()) { this->naming_context_.rebind ("previous", current->value ()); } this->record_history (temp); this->naming_context_.unbind ("lastFailure"); this->naming_context_.unbind ("lastReset"); this->naming_context_.unbind ("resetCount"); } // Listing 1 // Listing 2 code/ch21 void Temperature_Monitor2::record_history (float temp) { int now = (int)ACE_OS::time (); this->shared_context_.rebind ("lastUpdate", now); Name_Binding_Ptr counter (this->shared_context_.fetch ("counter")); int counterValue = counter.get () ? counter->int_value () : 0; char name[BUFSIZ]; ACE_OS::sprintf (name, "history[%d]", counterValue); char value[BUFSIZ]; ACE_OS::sprintf (value, "%d|%.2f", now, temp); this->shared_context_.rebind (name, value); ++counterValue; counterValue %= this->opt_.history_size (); this->shared_context_.rebind ("counter", counterValue); } // Listing 2 void Temperature_Monitor2::reset_device (Name_Binding_Ptr &resetCount) { int number_of_resets = 1; if (resetCount.get ()) { number_of_resets = resetCount->int_value () + 1; if (number_of_resets > this->opt_.excessive_resets ()) { EMail notification; char message[BUFSIZ]; ACE_OS::sprintf (message, "Thermometer: %s\n" "Reset Count: %d\n", this->thermometer_->address (), number_of_resets); notification.send (this->opt_.admin_email (), this->opt_.email_from (), "Excessive number of thermometer resets", message); } } this->thermometer_->reset (); this->naming_context_.rebind ("lastReset", (int)ACE_OS::time ()); this->naming_context_.rebind ("resetCount", number_of_resets); } void Temperature_Monitor2::record_failure (void) { Name_Binding_Ptr lastFailure (this->naming_context_.fetch ("lastFailure")); Name_Binding_Ptr lastReset (this->naming_context_.fetch ("lastReset")); Name_Binding_Ptr resetCount (this->naming_context_.fetch ("resetCount")); int now = (int) ACE_OS::time (); int lastFailureTime; int lastResetTime = 0; if (lastFailure.get ()) { lastFailureTime = lastFailure->int_value (); } else { this->naming_context_.rebind ("firstFailure", now); this->naming_context_.rebind ("lastReset", now); lastFailureTime = now; lastResetTime = now; } if (lastReset.get ()) { lastResetTime = lastReset->int_value (); } if (now - lastResetTime > this->opt_.reset_interval ()) { this->reset_device (resetCount); } this->naming_context_.rebind ("lastFailure", lastFailureTime); } void Temperature_Monitor2::monitor (void) { this->thermometer_ = new Thermometer (this->opt_.thermometer_address ()); for (;;) { float temp = this->thermometer_->temperature (); ACE_DEBUG ((LM_INFO, ACE_TEXT ("Read temperature %.2f\n"), temp)); if (temp >= 0) { this->record_temperature (temp); } else { this->record_failure (); } ACE_OS::sleep (this->opt_.poll_interval ()); } ACE_NOTREACHED (delete this->thermometer_;) }
Temperature_Monitor_Options.h
// $Id: Temperature_Monitor_Options.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef TEMPERATURE_MONITOR_OPTIONS_H #define TEMPERATURE_MONITOR_OPTIONS_H class Temperature_Monitor_Options { public: Temperature_Monitor_Options (int, ACE_TCHAR *[]) { } const char *thermometer_address (void) { return "serial:// s0/0x3e52"; } int poll_interval (void) { return 10; // every 10 seconds } int reset_interval (void) { return 60; // sixty seconds } int excessive_resets (void) { return 5; // no response in 5 minutes } const char *admin_email (void) { return "root@localhost"; } const char *email_from (void) { return "temperature monitor"; } int history_size() { return 10; } }; #endif /* TEMPERATURE_MONITOR_OPTIONS_H */
Thermometer.h
/* -*- C++ -*- */ // $Id: Thermometer.h 80826 2008-03-04 14:51:23Z wotte $ #ifndef THERMOMETER_H #define THERMOMETER_H #include "ace/OS_NS_stdlib.h" #include "ace/Log_Msg.h" class Thermometer { public: Thermometer (const char *addr) : addr_(addr), threshold_(5) { } float temperature (void) { int success = ACE_OS::rand () % 10; if (success < this->threshold_) { this->threshold_ = 7; return -1.0; } this->threshold_ = 3; int itemp = 80 + ACE_OS::rand () % 10; // 80 <= t <= 90 return (float)itemp; } const char *address (void) { return this->addr_; } void reset (void) { this->threshold_ = 4; ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Resetting thermometer %C\n"), this->address ())); } private: const char *addr_; int threshold_; }; #endif /* THERMOMETER_H */
Net local
// $Id: Netlocal.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "Naming_Context.h" #include "Temperature_Monitor2.h" #include "Temperature_Monitor_Options.h" // Listing 1 code/ch21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { Temperature_Monitor_Options opt (argc, argv); Naming_Context process_context; { ACE_Name_Options *name_options = process_context.name_options (); name_options->context (ACE_Naming_Context::PROC_LOCAL); ACE_TCHAR *nargv[] = { argv[0] }; name_options->parse_args (sizeof(nargv) / sizeof(ACE_TCHAR*), nargv); process_context.open (name_options->context ()); } Naming_Context shared_context; { ACE_Name_Options *name_options = shared_context.name_options (); name_options->process_name (argv[0]); name_options->context (ACE_Naming_Context::NET_LOCAL); shared_context.open (name_options->context ()); } Temperature_Monitor2 temperature_monitor (opt, process_context, shared_context); temperature_monitor.monitor (); process_context.close (); shared_context.close (); return 0; } // Listing 1
Net local reader
// $Id: Netlocal_reader.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "Naming_Context.h" #include "Temperature_Grapher.h" #include "Temperature_Grapher_Options.h" // Listing 1 code/ch21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { Temperature_Grapher_Options opt (argc, argv); Naming_Context naming_context; ACE_Name_Options *name_options = naming_context.name_options (); name_options->process_name (argv[0]); name_options->context (ACE_Naming_Context::NET_LOCAL); naming_context.open (name_options->context ()); Temperature_Grapher grapher (opt, naming_context); grapher.monitor (); naming_context.close (); return 0; } // Listing 1
Node local
// $Id: Nodelocal.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "Naming_Context.h" #include "Temperature_Monitor.h" #include "Temperature_Monitor_Options.h" // Listing 1 code/ch21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { Temperature_Monitor_Options opt (argc, argv); // Listing 1 // Listing 2 code/ch21 Naming_Context naming_context; ACE_Name_Options *name_options = naming_context.name_options(); // Listing 2 // Listing 3 code/ch21 ACE_TCHAR *naming_options_argv[] = { argv[0] }; name_options->parse_args (sizeof(naming_options_argv) / sizeof(ACE_TCHAR*), naming_options_argv); name_options->context (ACE_Naming_Context::PROC_LOCAL); naming_context.open (name_options->context ()); // Listing 3 // Listing 4 code/ch21 Temperature_Monitor temperature_monitor (opt, naming_context); temperature_monitor.monitor (); // Listing 4 // Listing 5 code/ch21 naming_context.close (); return 0; // Listing 5 }
Node local shared
// $Id: Nodelocal_shared.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "Naming_Context.h" #include "Temperature_Monitor2.h" #include "Temperature_Monitor_Options.h" // Listing 1 code/ch21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { Temperature_Monitor_Options opt (argc, argv); Naming_Context process_context; { ACE_Name_Options *name_options = process_context.name_options (); name_options->context (ACE_Naming_Context::PROC_LOCAL); ACE_TCHAR *nargv[] = { argv[0] }; name_options->parse_args (sizeof(nargv) / sizeof(ACE_TCHAR*) , nargv); process_context.open (name_options->context ()); } Naming_Context shared_context; { ACE_Name_Options *name_options = shared_context.name_options (); name_options->process_name (argv[0]); name_options->context (ACE_Naming_Context::NODE_LOCAL); shared_context.open (name_options->context ()); } Temperature_Monitor2 temperature_monitor (opt, process_context, shared_context); temperature_monitor.monitor (); process_context.close (); shared_context.close (); return 0; } // Listing 1
Node local shared reader
// $Id: Nodelocal_shared_reader.cpp 80826 2008-03-04 14:51:23Z wotte $ #include "Naming_Context.h" #include "Temperature_Grapher.h" #include "Temperature_Grapher_Options.h" // Listing 1 code/ch21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { Temperature_Grapher_Options opt (argc, argv); Naming_Context naming_context; ACE_Name_Options *name_options = naming_context.name_options (); name_options->process_name (argv[0]); name_options->context (ACE_Naming_Context::NODE_LOCAL); naming_context.open (name_options->context ()); Temperature_Grapher grapher (opt, naming_context); grapher.monitor (); naming_context.close (); return 0; } // Listing 1