summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2008-05-26 16:30:16 +0000
committerjai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2008-05-26 16:30:16 +0000
commit021c68cefc091ba868d186b95bf91182f90c569c (patch)
tree9c9f4bc80df871356a413e86f93d65b689138840
parentaf140812b88cc366f5fa153357dca943ebebc377 (diff)
downloadATCD-021c68cefc091ba868d186b95bf91182f90c569c.tar.gz
mods
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/Failure_Handler.cpp73
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/HMOptions.cpp140
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/HostMonitorImpl.cpp141
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/LinuxCPULoadCalculator.cpp76
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/Monitor_Thread.cpp33
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/RM_Proxy.cpp107
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/Timer.cpp168
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/Utilization_Monitor.cpp35
-rw-r--r--TAO/orbsvcs/examples/FaultTolerance/FLARe/host_monitor.cpp66
9 files changed, 839 insertions, 0 deletions
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/Failure_Handler.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Failure_Handler.cpp
new file mode 100644
index 00000000000..9067fe46693
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Failure_Handler.cpp
@@ -0,0 +1,73 @@
+/**
+ * @file C++ Implementation: Failure_Handler
+ *
+ * @brief Defines implementation of Failure_Handler.
+ *
+ */
+
+#include "Failure_Handler.h"
+#include "HostMonitorImpl.h"
+
+ProcessInfo::ProcessInfo (const std::string &pid, const std::string &hn, size_t p)
+: process_id (pid),
+ hostname (hn),
+ port (p)
+{}
+
+
+Failure_Handler::ProcessInfoMap Failure_Handler::process_map_;
+
+Failure_Handler::Failure_Handler ()
+: connector_factory_ (0),
+ host_monitor_ (0)
+{}
+
+int Failure_Handler::handle_input (ACE_HANDLE fd)
+{
+ ProcessInfo pinfo;
+ if (process_map_.find (fd, pinfo) == 0) /// if found
+ {
+ ACE_DEBUG ((LM_DEBUG,"It looks like process %s has failed.\n", pinfo.process_id.c_str()));
+ process_map_.unbind (fd);
+ if (host_monitor_->drop_process (pinfo.process_id) == 0)
+ /// release the handler.
+ return -1;
+ else
+ ACE_DEBUG ((LM_DEBUG,"drop_process failed process_id = %s.\n", pinfo.process_id.c_str()));
+ }
+
+ return -1;
+}
+
+void Failure_Handler::set_host_monitor (HostMonitorImpl *hm)
+{
+ host_monitor_ = hm;
+}
+
+int Failure_Handler::open (void *factory)
+{
+ connector_factory_ = static_cast <FactoryConnector *> (factory);
+ return super::open (factory);
+}
+
+int Failure_Handler::drop_process (ACE_HANDLE fd)
+{
+ ProcessInfo pinfo;
+ if ((process_map_.find (fd, pinfo) == 0) &&
+ (process_map_.unbind (fd) == 0))
+ {
+ connector_factory_->reactor ()->remove_handler (this, super::ALL_EVENTS_MASK);
+ ACE_DEBUG ((LM_DEBUG,"Record for process %s removed from the map.\n", pinfo.process_id.c_str()));
+ return 0;
+ }
+ else
+ return -1;
+}
+
+int Failure_Handler::watch_process (ACE_HANDLE fd,
+ const std::string &process_id,
+ const std::string &hostname,
+ size_t port)
+{
+ return process_map_.bind (fd, ProcessInfo (process_id, hostname, port));
+}
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/HMOptions.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/HMOptions.cpp
new file mode 100644
index 00000000000..f7c7cd42eda
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/HMOptions.cpp
@@ -0,0 +1,140 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <iostream>
+#include <sstream>
+#include <algorithm>
+#include "HMOptions.h"
+#include "ArgPair.h"
+#include "ace/Global_Macros.h"
+#include "ace/Guard_T.h"
+#include "ace/Log_Msg.h"
+#include "ace/Get_Opt.h"
+
+/// Initialize the static data member.
+HMOptions * volatile HMOptions::instance_ = 0;
+std::auto_ptr <HMOptions> HMOptions::deleter_;
+ACE_Thread_Mutex HMOptions::lock_;
+
+
+HMOptions::HMOptions (void)
+ : RM_ior_ ("file://rm.ior"),
+ arg_pair_ (0,0),
+ RM_update_freq_ (1),
+ load_monitor_freq_(2)
+{
+ char hostname [100];
+ gethostname (hostname, sizeof (hostname));
+ host_id_ = hostname;
+ ACE_DEBUG((LM_DEBUG,"Hostname is %s.\n",hostname));
+}
+
+HMOptions *HMOptions::instance (void)
+{
+ if (! instance_)
+ {
+ ACE_GUARD_RETURN (ACE_Thread_Mutex, guard, lock_, 0);
+ if (! instance_)
+ {
+ instance_ = new HMOptions ();
+ deleter_.reset (instance_);
+ }
+ }
+ return instance_;
+}
+
+bool
+HMOptions::parse_args (int argc, char **argv)
+{
+ bool retval = true;
+ this->arg_pair_ = ArgPair (argc, argv);
+
+ ACE_Get_Opt get_opts (argc, argv, "-i:h:r:l:n:o:u:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'u':
+ {
+ util_file_ = std::string (get_opts.opt_arg());
+ break;
+ }
+ case 'o':
+ {
+ HM_ior_file_ = std::string (get_opts.opt_arg());
+ break;
+ }
+ case 'i':
+ {
+ RM_ior_ = std::string (get_opts.opt_arg ());
+ ior_access_ = std::make_pair ('i', RM_ior_);
+ break;
+ }
+ case 'h':
+ {
+ host_id_ = std::string (get_opts.opt_arg ());
+ break;
+ }
+ case 'r':
+ {
+ std::istringstream istr (get_opts.opt_arg ());
+ if (!(istr >> RM_update_freq_))
+ return false;
+ break;
+ }
+ case 'l':
+ {
+ std::istringstream istr (get_opts.opt_arg ());
+ if (!(istr >> load_monitor_freq_))
+ return false;
+ break;
+ }
+ case 'n':
+ {
+ RM_ior_ = std::string (get_opts.opt_arg ());
+ ior_access_ = std::make_pair ('n', RM_ior_);
+ break;
+ }
+ }
+ return retval;
+};
+
+std::string HMOptions::HM_ior_file () const
+{
+ return HM_ior_file_;
+}
+
+std::string HMOptions::RM_ior () const
+{
+ return RM_ior_;
+}
+
+ArgPair HMOptions::arg_pair ()
+{
+ return arg_pair_;
+}
+
+std::string HMOptions::host_id () const
+{
+ return host_id_;
+}
+
+int HMOptions::RM_update_freq () const
+{
+ return RM_update_freq_;
+}
+
+std::string HMOptions::util_file () const
+{
+ return util_file_;
+}
+
+int HMOptions::load_monitor_freq () const
+{
+ return load_monitor_freq_;
+}
+
+std::pair <char, std::string> HMOptions::ior_access () const
+{
+ return ior_access_;
+}
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/HostMonitorImpl.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/HostMonitorImpl.cpp
new file mode 100644
index 00000000000..2850a09780f
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/HostMonitorImpl.cpp
@@ -0,0 +1,141 @@
+#include "HostMonitorImpl.h"
+#include "Failure_Handler.h"
+#include "Monitor_Thread.h"
+#include "RM_Proxy.h"
+#include "HMOptions.h"
+#include "LinuxCPULoadCalculator.h"
+#include "FCS_Monitor_Adapter.h"
+#include "Utilization_Monitor.h"
+
+#include "ace/Connector.h"
+#include "ace/Service_Object.h"
+#include "ace/Reactor.h"
+#include "ace/INET_Addr.h"
+#include "ace/Time_Value.h"
+#include "ace/Synch_Options.h"
+#include "ace/Thread_Mutex.h"
+
+
+HostMonitorImpl::HostMonitorImpl (CORBA::ORB_ptr orb, Monitor_Thread *mt)
+: monitor_thread_ (mt),
+ connector_ (monitor_thread_->get_reactor ()),
+ orb_ (CORBA::ORB::_duplicate(orb))
+{
+ this->create_rm_proxy ();
+}
+
+void
+HostMonitorImpl::dump (void)
+throw (CORBA::SystemException)
+{
+ //ACE_DEBUG ((LM_DEBUG, "inside dump method\n"));
+}
+
+
+::CORBA::Boolean
+HostMonitorImpl::register_process (const char *process_id, const char * hostname, CORBA::Long port)
+throw (CORBA::SystemException)
+{
+ //ACE_DEBUG ((LM_DEBUG, "Entering register process\n"));
+ Failure_Handler *handler = 0;
+ ACE_SOCK_Connector::PEER_ADDR serv_addr;
+ serv_addr.set (port, hostname);
+ ACE_Synch_Options options (ACE_Synch_Options::USE_TIMEOUT, ACE_Time_Value (1));
+
+ if (connector_.connect (handler, serv_addr, options) < 0)
+ {
+ ACE_ERROR_RETURN((LM_ERROR,"Failed to open an connector socket.\n"), 1);
+ }
+
+ //ACE_DEBUG ((LM_DEBUG, "Entering register process\n"));
+
+ handler->set_host_monitor (this);
+ handler->watch_process (handler->get_handle(), process_id, hostname, port);
+ process_map_.bind (process_id, handler);
+ //this->create_rm_proxy ();
+ ACE_DEBUG ((LM_DEBUG,"HostMonitorImpl::register_process process_id = %s, port = %d.\n",process_id, port));
+
+ return true;
+}
+
+::CORBA::Boolean
+HostMonitorImpl::unregister_process (const char *process_id)
+throw (CORBA::SystemException)
+{
+ Failure_Handler *handler = 0;
+ if (process_map_.find (process_id, handler) == 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,"HostMonitorImpl::unregister_process %s.\n", process_id));
+ if ((handler->drop_process (handler->get_handle ()) == 0))
+ {
+ if (remove_process (process_id) == 0)
+ return true;
+ }
+ else
+ ACE_DEBUG ((LM_DEBUG,"HostMonitorImpl::unregister_process Process %s can't be dropped!\n", process_id));
+ }
+ else
+ ACE_DEBUG ((LM_DEBUG,"HostMonitorImpl::unregister_process Invalid process_id = %s.\n", process_id));
+
+ return true;
+}
+
+int HostMonitorImpl::drop_process (const std::string &process_id)
+{
+ Failure_Handler *handler = 0;
+ if (process_map_.find (process_id, handler) == 0)
+ {
+ rm_proxy_->proc_failure (process_id);
+ return remove_process (process_id);
+ }
+ return -1;
+}
+
+RM_Proxy *HostMonitorImpl::create_rm_proxy (void)
+{
+ if (rm_proxy_.get() == 0)
+ {
+ std::auto_ptr <CPULoadCalculator> linux_load_calc (new LinuxCPULoadCalculator());
+ //std::auto_ptr <CPULoadCalculator> linux_load_calc (new FCS_Monitor_Adapter ());
+ std::auto_ptr <Utilization_Monitor> util_mon (
+ new Utilization_Monitor (linux_load_calc.get()));
+ linux_load_calc.release ();
+ std::auto_ptr <RM_Proxy> rm_proxy (new RM_Proxy (orb_));
+
+ rm_proxy->setCPULoadCalculator (util_mon.get());
+ util_mon->setRM_Proxy (rm_proxy.get());
+
+ rm_proxy->hertz (HMOptions::instance()->RM_update_freq());
+ util_mon->hertz (HMOptions::instance()->load_monitor_freq ());
+
+ util_mon->start ();
+ rm_proxy->start ();
+
+ /// Trasnfer of ownership.
+ this->util_mon_ = util_mon;
+ this->rm_proxy_ = rm_proxy;
+ }
+ return rm_proxy_.get();
+}
+
+void HostMonitorImpl::remove_rm_proxy (void)
+{
+ if (process_map_.current_size() == 0)
+ {
+ rm_proxy_->stop ();
+ util_mon_->stop ();
+ rm_proxy_.reset (0);
+ util_mon_.reset (0);
+ }
+}
+
+int HostMonitorImpl::remove_process (std::string const &process_id)
+{
+ if (process_map_.unbind (process_id) == 0)
+ {
+ remove_rm_proxy ();
+ return 0;
+ }
+ return -1;
+}
+
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/LinuxCPULoadCalculator.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/LinuxCPULoadCalculator.cpp
new file mode 100644
index 00000000000..d416268cf47
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/LinuxCPULoadCalculator.cpp
@@ -0,0 +1,76 @@
+/**
+ * @file C++ Implementation: LinuxCPULoadCalculator
+ *
+ * @brief Defines implementation of LinuxCPULoadCalculator.
+ *
+ */
+
+#include "LinuxCPULoadCalculator.h"
+#include "ace/OS_NS_string.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/Log_Msg.h"
+#include "ace/Guard_T.h"
+
+LinuxCPULoadCalculator::LinuxCPULoadCalculator()
+ : CPULoadCalculator()
+{
+}
+
+
+LinuxCPULoadCalculator::~LinuxCPULoadCalculator()
+{
+}
+
+double LinuxCPULoadCalculator::percent_load (void)
+{
+ ACE_Guard <ACE_Thread_Mutex> guard (calc_mutex_);
+ //ACE_DEBUG((LM_DEBUG,"entering percent_load."));
+ static char buf[1024];
+ static unsigned long prev_idle = 0;
+ static double prev_total = 0.0;
+
+ FILE *file_ptr = 0;
+ char *item = 0;
+ char *arg = 0;
+ unsigned long delta_idle = 0;
+ unsigned long user = 0;
+ unsigned long nice = 0;
+ unsigned long idle = 0;
+ unsigned long sys = 0;
+
+ double percent_cpu_load = 0.0;
+
+ if ((file_ptr = ACE_OS::fopen("/proc/stat", "r")) == 0)
+ return percent_cpu_load;
+
+ while ((ACE_OS::fgets (buf, sizeof (buf), file_ptr)) != 0)
+ {
+ item = ACE_OS::strtok (buf, " \t\n");
+ arg = ACE_OS::strtok (0, "\n");
+
+ if (item == 0 || arg == 0)
+ continue;
+ if (item[0] == 'c' && strlen (item) == 3)
+ {
+ sscanf (arg, "%lu %lu %lu %lu", &user, &nice, &sys, &idle);
+ break;
+ }
+ }
+
+ fclose (file_ptr);
+
+ delta_idle = idle - prev_idle;
+ double total;
+ double time_passed;
+ total = (double) (user + nice + sys + idle);
+ time_passed = total - prev_total;
+
+ percent_cpu_load = 100.0 - (delta_idle / time_passed * 100.0);
+
+ prev_idle = idle;
+ prev_total = total;
+
+ //ACE_DEBUG((LM_DEBUG,"exiting percent_load."));
+ return percent_cpu_load;
+}
+
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/Monitor_Thread.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Monitor_Thread.cpp
new file mode 100644
index 00000000000..a6929da10b2
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Monitor_Thread.cpp
@@ -0,0 +1,33 @@
+/**
+ * @file C++ Implementation: Monitor_Thread
+ *
+ * @brief Defines implementation of Monitor_Thread.
+ *
+ */
+
+#include "Monitor_Thread.h"
+
+#include "ace/TP_Reactor.h"
+
+Monitor_Thread::Monitor_Thread ()
+ : reactor_ (new ACE_TP_Reactor())
+{
+}
+
+int Monitor_Thread::svc ()
+{
+ if (reactor_.run_reactor_event_loop() == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,"run_reactor_event_loop failed\n"), -1);
+
+ return 0;
+}
+/*
+int Monitor_Thread::register_handler (ACE_Event_Handler *event_handler, ACE_Reactor_Mask mask)
+{
+ return reactor_.register_handler (event_handler, mask);
+}
+*/
+ACE_Reactor * Monitor_Thread::get_reactor ()
+{
+ return &reactor_;
+}
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/RM_Proxy.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/RM_Proxy.cpp
new file mode 100644
index 00000000000..298b0f29791
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/RM_Proxy.cpp
@@ -0,0 +1,107 @@
+
+#include "RM_Proxy.h"
+#include "HMOptions.h"
+#include "monitorC.h"
+#include "HMOptions.h"
+#include "CPULoadCalculator.h"
+#include "orbsvcs/orbsvcs/CosNamingC.h"
+
+#include "ace/Log_Msg.h"
+
+#include <stdexcept>
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+
+#include "ArgPair.h"
+
+RM_Proxy::RM_Proxy (CORBA::ORB_ptr orb)
+: load_calc_ (0),
+ orb_ (CORBA::ORB::_duplicate (orb))
+{
+ /// Initilize the ORB.
+ ArgPair arg_pair = HMOptions::instance()->arg_pair();
+
+ //CORBA::ORB_var orb = CORBA::ORB_init (arg_pair.argc, arg_pair.argv,
+ // "ORB_FOR_RM_Proxy");
+ CORBA::Object_var obj = obtain_RM_ior (orb_.in ());
+
+ if (CORBA::is_nil (obj))
+ {
+ ACE_DEBUG((LM_ERROR, "Nil Reference of ReplicationManager\n"));
+ throw std::runtime_error ("Nil Reference of ReplicationManager");
+ }
+
+ /// Downcast the object reference to a reference of type HostMonitor.
+ RM_var_ = ReplicationManager::_narrow (obj);
+ if (CORBA::is_nil (RM_var_))
+ {
+ ACE_DEBUG((LM_ERROR, "Argument is not a ReplicationManager reference.\n"));
+ throw std::runtime_error ("Argument is not a ReplicationManager reference.");
+ }
+}
+
+RM_Proxy::~RM_Proxy ()
+{
+}
+
+CORBA::Object_var RM_Proxy::obtain_RM_ior (CORBA::ORB_ptr orb)
+{
+ std::pair <char, std::string> ior_access = HMOptions::instance ()->ior_access ();
+
+ if (ior_access.first == 'i') /// file based IOR
+ {
+ return orb->string_to_object (ior_access.second.c_str());
+ }
+ else if (ior_access.first == 'n') /// Naming Service based IOR
+ {
+ CORBA::Object_var naming_obj =
+ orb->resolve_initial_references ("NameService");
+
+ if (CORBA::is_nil (naming_obj.in ()))
+ ACE_DEBUG ((LM_ERROR,"Unable to get the Naming Service.\n"));
+
+
+ CosNaming::NamingContext_var naming_context =
+ CosNaming::NamingContext::_narrow (naming_obj.in ());
+
+ CosNaming::Name name (1);
+ name.length (1);
+ name[0].id = CORBA::string_dup (ior_access.second.c_str());
+ name[0].kind = CORBA::string_dup ("");
+
+ return naming_context->resolve (name);
+ }
+ else
+ {
+ return orb->string_to_object (HMOptions::instance()->RM_ior ().c_str ());
+ }
+}
+
+void RM_Proxy::setCPULoadCalculator (CPULoadCalculator *load_calc)
+{
+ this->load_calc_ = load_calc;
+}
+
+void RM_Proxy::proc_failure (const std::string & process_id)
+{
+ try
+ {
+ RM_var_->proc_failure (process_id.c_str());
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Exception caught:");
+ }
+}
+
+int
+RM_Proxy::pulse (void)
+{
+ //ACE_DEBUG((LM_ERROR,"host_id=%s\n",HMOptions::instance()->host_id().c_str()));
+ //ACE_DEBUG((LM_ERROR,"load=%d\n", (int)load_calc_->percent_load()));
+ RM_var_->util_update (HMOptions::instance()->host_id().c_str (),
+ load_calc_->percent_load());
+ return 0;
+}
+
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/Timer.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Timer.cpp
new file mode 100644
index 00000000000..acc801242eb
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Timer.cpp
@@ -0,0 +1,168 @@
+
+#include "Timer.h"
+#include "ace/Timer_Queue.h"
+#include "ace/Reactor.h"
+
+//=================================================================
+
+// constructor
+Timer::Timer (void)
+ : done_ (0),
+ active_ (0),
+ hertz_ (0),
+ tid_ (0)
+{
+ // Setup a reactor different from what the ORB is using that we shall use
+ // exclusively for timer capabilities.
+ this->reactor (new ACE_Reactor);
+}
+
+// destructor
+Timer::~Timer ()
+{
+ delete this->reactor ();
+ this->reactor (0);
+}
+
+// get our attribute
+double
+Timer::hertz ()
+{
+ return this->hertz_;
+}
+
+// set our attribute
+void
+Timer::hertz (double h)
+{
+ this->hertz_ = h;
+}
+
+// start the timer
+void
+Timer::start ()
+{
+ // we are using this step in case we want to restart the timer capabilities
+ // again
+ this->done_ = 0;
+
+ // check if parameters are valid
+ if (this->hertz_ == 0 || this->active_ !=0) { // Not valid
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("[Timer::start] ")
+ ACE_TEXT ("Bad Parameters\n")));
+ // we should throw some exception
+ return;
+ }
+
+ // start an active object that will handle events - particularly timeout
+ // events
+ if (this->activate () == -1) {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("[Timer::start] ")
+ ACE_TEXT ("Active object activation failed (%p)\n")));
+ // we should throw some exception
+ return;
+ }
+
+ // we are now active
+ this->active_ = 1;
+
+ long int interval = 1000000 / hertz_;
+
+ // start a periodic timer
+ this->tid_ = this->reactor ()->schedule_timer (this,
+ 0,
+ ACE_Time_Value (0, interval),
+ ACE_Time_Value (0, interval));
+
+ if (this->tid_ == -1) {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("[Timer::start] ")
+ ACE_TEXT ("Scheduling timer failed (%p)\n")));
+ // we should throw some exception
+ return;
+ }
+
+ // success
+}
+
+// stopping the timer
+void
+Timer::stop ()
+{
+ if (this->active_ == 0) { // Not valid.
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("[Timer::stop] ")
+ ACE_TEXT ("bad parameter\n")));
+ // we should throw some exception
+ return;
+ }
+
+ // cancel the timer
+ this->reactor ()->cancel_timer (this);
+
+ // we are no longer active
+ this->active_ = 0;
+
+ // asynchronous notification to the active object thread
+ this->done_ = 1;
+
+ // send an event to the reactor which will invoke the handle_close
+ this->reactor ()->notify ();
+
+ ///ACE_DEBUG ((LM_DEBUG, "Waiting\n"));
+
+ // wait for the active object thread to quit
+ this->wait ();
+}
+
+// callback function from the timeout handler.
+int
+Timer::pulse (void)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("obtain utilization input\n")));
+
+ return 0;
+}
+
+// handling the timeout
+int
+Timer::handle_timeout (const ACE_Time_Value &,
+ const void *)
+{
+ // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("[Timer::handle_timeout] - timeout\n")));
+ // timeout has occured. Time to callback. The callback function will do the
+ // RM's job of getting utilization info from the hosts.
+ return this->pulse ();
+}
+
+// cleanup
+int
+Timer::handle_close (ACE_HANDLE handle,
+ ACE_Reactor_Mask close_mask)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("[%x] handle = %d, close_mask = %d\n"),
+ this,
+ handle,
+ close_mask));
+
+ return 0;
+}
+
+// active object thread
+int
+Timer::svc (void)
+{
+ // set the owner
+ this->reactor ()->owner (ACE_OS::thr_self ());
+
+ // continue until someone stops us asynchronously
+ while (!this->done_)
+ this->reactor ()->handle_events ();
+
+ return 0;
+}
+
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/Utilization_Monitor.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Utilization_Monitor.cpp
new file mode 100644
index 00000000000..31d6357f90d
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/Utilization_Monitor.cpp
@@ -0,0 +1,35 @@
+
+#include "Utilization_Monitor.h"
+#include "HMOptions.h"
+
+#include "ace/Log_Msg.h"
+
+Utilization_Monitor::Utilization_Monitor (CPULoadCalculator *load_calc)
+: load_calc_ (load_calc),
+ load_ (0),
+ outfile_ (HMOptions::instance()->util_file().c_str())
+{
+}
+
+Utilization_Monitor::~Utilization_Monitor ()
+{}
+
+int
+Utilization_Monitor::pulse (void)
+{
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Utilization_Monitor::pulse\n")));
+ load_ = load_calc_->percent_load ();
+ outfile_ << load_ << std::endl;
+
+ return 0;
+}
+
+double Utilization_Monitor::percent_load (void)
+{
+ return load_;
+}
+
+void Utilization_Monitor::setRM_Proxy (RM_Proxy *rm_proxy)
+{
+ this->rm_proxy_ = rm_proxy;
+}
diff --git a/TAO/orbsvcs/examples/FaultTolerance/FLARe/host_monitor.cpp b/TAO/orbsvcs/examples/FaultTolerance/FLARe/host_monitor.cpp
new file mode 100644
index 00000000000..8addf5ff4a9
--- /dev/null
+++ b/TAO/orbsvcs/examples/FaultTolerance/FLARe/host_monitor.cpp
@@ -0,0 +1,66 @@
+#include <iostream>
+#include <fstream>
+#include <string>
+
+#include "HostMonitorImpl.h"
+#include "Monitor_Thread.h"
+#include "HMOptions.h"
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+
+int main (int argc, char* argv[])
+{
+ try {
+
+ HMOptions::instance()->parse_args (argc, argv);
+ //std::copy (argv, argv + argc,
+ // std::ostream_iterator <std::string> (std::cout, "\n"));
+ /// First initialize the ORB, that will remove some arguments...
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv, "ORB");
+ //std::copy (argv, argv + argc,
+ // std::ostream_iterator <std::string> (std::cout, "\n"));
+
+ /// Initilize RootPOA.
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references ("RootPOA");
+
+ /// Create the POA object reference to type POA.
+ PortableServer::POA_var poa =
+ PortableServer::POA::_narrow (poa_object.in ());
+
+ /// Activate the POA manager.
+ PortableServer::POAManager_var poa_manager =
+ poa->the_POAManager ();
+ poa_manager->activate ();
+
+
+ Monitor_Thread monitor_thread;
+ /// Initilize the timedate object on heap.
+ HostMonitorImpl * host_monitor = new HostMonitorImpl (orb, &monitor_thread);
+ PortableServer::ServantBase_var safe_host (host_monitor);
+ ACE_UNUSED_ARG (safe_host);
+
+ HostMonitor_var hmvar = host_monitor->_this();
+ CORBA::String_var hmstr = orb->object_to_string (hmvar.in());
+
+ /// Copy the IOR in the IORFILE.
+ std::ofstream outfile(HMOptions::instance()->HM_ior_file().c_str());
+ outfile << hmstr;
+ outfile.close ();
+
+ monitor_thread.activate ();
+ orb->run();
+
+ /// Destroy the POA, waiting until the destruction terminates
+ poa->destroy (1, 1);
+ orb->destroy ();
+ }
+ catch (CORBA::Exception &ex) {
+ //std::cerr << "A CORBA exception was raised!" << std::endl;
+ ACE_PRINT_EXCEPTION (ex, "A CORBA exception was raised:");
+ return -1;
+ }
+ return 0;
+}