diff options
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/LoadBalancing')
54 files changed, 0 insertions, 8496 deletions
diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.cpp deleted file mode 100644 index 5ea2a76ec77..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.cpp +++ /dev/null @@ -1,244 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.h" -#include "tao/ORB_Constants.h" -#include "ace/OS_NS_time.h" -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_unistd.h" -#include "ace/os_include/os_netdb.h" -#include "ace/os_include/sys/os_pstat.h" -#include "ace/os_include/sys/os_loadavg.h" -#if defined(__NetBSD__) || defined (__APPLE__) -#include <sys/sysctl.h> -#endif - -ACE_RCSID (LoadBalancing, - LB_CPU_Load_Average_Monitor, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_CPU_Load_Average_Monitor::TAO_LB_CPU_Load_Average_Monitor ( - const char * location_id, - const char * location_kind) - : location_ (1) -{ - this->location_.length (1); - - if (location_id == 0) - { - char host[MAXHOSTNAMELEN + 1]; - if (ACE_OS::hostname (host, sizeof (host)) != 0) - { - // Couldn't determine hostname. Use the current time - // instead. - CORBA::ULong t = static_cast<CORBA::ULong> (ACE_OS::time ()); - - // A 64 byte buffer is more than enough to contain the - // string representation of a 32 bit unsigned integer. - char buf[64] = { '\0' }; - ACE_OS::sprintf (buf, "%u", t); - - this->location_[0].id = CORBA::string_dup (buf); - this->location_[0].kind = CORBA::string_dup ("Creation Time"); - } - else - { - this->location_[0].id = CORBA::string_dup (host); - this->location_[0].kind = CORBA::string_dup ("Hostname"); - } - } - else - { - this->location_[0].id = CORBA::string_dup (location_id); - - if (location_kind != 0) - this->location_[0].kind = CORBA::string_dup (location_kind); - } -} - -TAO_LB_CPU_Load_Average_Monitor::~TAO_LB_CPU_Load_Average_Monitor (void) -{ -} - -CosLoadBalancing::Location * -TAO_LB_CPU_Load_Average_Monitor::the_location (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Location * location; - ACE_NEW_THROW_EX (location, - CosLoadBalancing::Location (this->location_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - return location; -} - -CosLoadBalancing::LoadList * -TAO_LB_CPU_Load_Average_Monitor::loads (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Float load = 0; - - // Obtain the number of processors each time a load is computed. - // The idea is to take into account the processor failures that can - // occur on platforms that continue running with the remaining - // processors. - // - // @@ Is this a realistic scenario? Perhaps we should just cache - // the number of processors and assume that any processor failure - // is a catastrophic one. - -#if 0 - - SYSTEM_INFO sys_info; - ::GetSystemInfo (&sys_info); - - ACE_ASSERT (sys_info.dwNumberOfProcessors > 0); - - load = ::GetLoadAvg () / sys_info.dwNumberOfProcessors; - -#elif defined (linux) || defined (sun) - - // Only bother getting the load average over the last minute. - // - // @todo Make this configurable so that the load average over the - // last 5 and 15 minutes can be used instead. - double loadavg[1]; - -# if defined (linux) \ - && ((defined (__GLIBC__) && defined (__GLIBC_MINOR__) \ - && __GLIBC__ == 2 && __GLIBC_MINOR__ < 2) \ - || (!defined (_BSD_SOURCE) && !defined (_GNU_SOURCE))) - - // GLibc < 2.2 does not implement getloadavg(). Furthermore, - // getloadavg() is only "visible" if _BSD_SOURCE or _GNU_SOURCE is - // defined. - - // Obtain the load average directly from the `/proc' filesystem. - FILE * s = ::fopen ("/proc/loadavg", "r"); - - if (s == 0) - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - errno), - CORBA::COMPLETED_NO), - 0); - - fscanf (s, "%f", &loadavg[0]); - - (void) fclose (s); - - const int samples = 1; - -# else - -# if defined (ACE_LACKS_GETLOADAVG) - - const int samples = 0; - -# else - - const int samples = ::getloadavg (loadavg, 1); - -# endif /* ACE_LACKS_GETLOADAVG */ - -# endif /* linux - && ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) - || (!_BSD_SOURCE && !_GNU_SOURCE)) */ - - if (samples == 1) - { - const long num_processors = ::sysconf (_SC_NPROCESSORS_ONLN); - - ACE_ASSERT (num_processors > 0); - - if (num_processors > 0) - load = loadavg[0] / num_processors; - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - } - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - -#elif defined (__NetBSD__) || defined (__APPLE__) - - double loadavg[1]; - - const int samples = ::getloadavg (loadavg, 1); - - if (samples == 1) - { - int mib[2], num_processors; - size_t len; - - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - len = sizeof(num_processors); - - sysctl(mib, 2, &num_processors, &len, NULL, 0); - - ACE_ASSERT (num_processors > 0); - - if (num_processors > 0) - load = loadavg[0] / num_processors; - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - } - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - -#elif defined (__hpux) - - struct pst_dynamic psd; - - if (::pstat_getdynamic (&psd, sizeof (psd), (size_t) 1, 0) != -1) - { - const long & num_processors = psd.psd_proc_cnt; - - ACE_ASSERT (num_processors > 0); - - if (num_processors > 0) - load = psd.psd_avg_1_min / num_processors; - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - } - else - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); // Correct exception? - -#endif - -#if defined (linux) || defined (sun) || defined (__hpux) || defined(__NetBSD__) || defined (__APPLE__) - - CosLoadBalancing::LoadList * tmp; - ACE_NEW_THROW_EX (tmp, - CosLoadBalancing::LoadList (1), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - CosLoadBalancing::LoadList_var load_list = tmp; - - load_list->length (1); - - load_list[0].id = CosLoadBalancing::LoadAverage; - load_list[0].value = load; - - return load_list._retn (); - -#else - - ACE_UNUSED_ARG (load); - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0); - -#endif /* linux || sun || __hpux || __NetBSD__ || __APPLE__ */ - -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.h deleted file mode 100644 index 12bb7c1df80..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Load_Average_Monitor.h +++ /dev/null @@ -1,103 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_CPU_Load_Average_Monitor.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_CPU_LOAD_AVERAGE_MONITOR_H -#define TAO_LB_CPU_LOAD_AVERAGE_MONITOR_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LoadBalancing_export.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingS.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_CPU_Load_Average_Monitor - * - * @brief LoadMonitor implementation that monitors the overall CPU - * load on a given host. - * - * Loads returned from this load monitor are the average number of - * processes in the "run" queue over a ***FIXME*** seconds averaged - * over the number of processors. For example, a load of 2 on a dual - * CPU host is returned as an average load of 1 by this CPU load - * monitor, a load of 5 on a quad CPU host will be reported as a load - * of 1.25 (i.e. 5/4), and so on and so forth. - */ -class TAO_LoadBalancing_Export TAO_LB_CPU_Load_Average_Monitor - : public virtual POA_CosLoadBalancing::LoadMonitor -{ -public: - - /// Constructor - /** - * If no location is supplied the hostname or IP address is used by - * default. - */ - TAO_LB_CPU_Load_Average_Monitor (const char * location_id = 0, - const char * location_kind = 0); - - /** - * @name CosLoadBalancing::LoadMonitor Methods - * - * Methods required by the CosLoadBalancing::LoadMonitor interface. - */ - //@{ - - /// Return the location at which the LoadMonitor resides. - /** - * The returned "Location" is a sequence of length 1. - */ - virtual CosLoadBalancing::Location * the_location ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Return the average CPU load at the location which this - /// LoadMonitor resides. - /** - * @return A "Load" sequence of length 1 that contains a LoadId - * equal to CosLoadBalancing::LoadAverage, and the average CPU - * load. - */ - virtual CosLoadBalancing::LoadList * loads ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - //@} - -protected: - - /// Destructor - /** - * Protected destructor to enforce proper memory management through - * reference counting. - */ - ~TAO_LB_CPU_Load_Average_Monitor (void); - -private: - - /// The name of the location at which this LoadMonitor resides. - CosLoadBalancing::Location location_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_CPU_LOAD_AVERAGE_MONITOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.cpp deleted file mode 100644 index 48a8267e189..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.h" -#include "tao/ORB_Constants.h" -#include "ace/OS_NS_time.h" -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_unistd.h" -#include "ace/os_include/os_netdb.h" -#include "ace/os_include/sys/os_loadavg.h" - -ACE_RCSID (LoadBalancing, - LB_CPU_Utilization_Monitor, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -double calc_cpu_loading (void) -{ - 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 = fopen("/proc/stat", "r")) == 0) - return percent_cpu_load; - - while ((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; - - return percent_cpu_load; - -} - - -TAO_LB_CPU_Utilization_Monitor::TAO_LB_CPU_Utilization_Monitor (const char * location_id, - const char * location_kind) - : location_ (1) -{ - this->location_.length (1); - - if (location_id == 0) - { - char host[MAXHOSTNAMELEN + 1]; - if (ACE_OS::hostname (host, sizeof (host)) != 0) - { - // Couldn't determine hostname. Use the current time - // instead. - CORBA::ULong t = static_cast<CORBA::ULong> (ACE_OS::time ()); - - // A 64 byte buffer is more than enough to contain the - // string representation of a 32 bit unsigned integer. - char buf[64] = { '\0' }; - ACE_OS::sprintf (buf, "%u", t); - - this->location_[0].id = CORBA::string_dup (buf); - this->location_[0].kind = CORBA::string_dup ("Creation Time"); - } - else - { - this->location_[0].id = CORBA::string_dup (host); - this->location_[0].kind = CORBA::string_dup ("Hostname"); - } - } - else - { - this->location_[0].id = CORBA::string_dup (location_id); - - if (location_kind != 0) - this->location_[0].kind = CORBA::string_dup (location_kind); - } -} - -TAO_LB_CPU_Utilization_Monitor::~TAO_LB_CPU_Utilization_Monitor (void) -{ -} - -CosLoadBalancing::Location * -TAO_LB_CPU_Utilization_Monitor::the_location (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Location * location; - ACE_NEW_THROW_EX (location, - CosLoadBalancing::Location (this->location_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - return location; -} - -CosLoadBalancing::LoadList * -TAO_LB_CPU_Utilization_Monitor::loads (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Float load = 0; - -#if defined (linux) || defined (sun) - - double load_double = calc_cpu_loading (); - load = load_double; - - CosLoadBalancing::LoadList * tmp; - ACE_NEW_THROW_EX (tmp, - CosLoadBalancing::LoadList (1), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - CosLoadBalancing::LoadList_var load_list = tmp; - - load_list->length (1); - - load_list[0].id = CosLoadBalancing::LoadAverage; - load_list[0].value = load; - - ACE_DEBUG ((LM_DEBUG, "%2f\n", load_list[0].value)); - - return load_list._retn (); - -#else - - ACE_UNUSED_ARG (load); - ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0); - -#endif /* linux || sun */ - -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.h deleted file mode 100644 index c369ce8e2c0..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_CPU_Utilization_Monitor.h +++ /dev/null @@ -1,100 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_CPU_Utilization_Monitor.h - * - * $Id$ - * - * @author Jaiganesh Balasubramanian <jai@dre.vanderbilt.edu> - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_CPU_UTILIZATION_MONITOR_H -#define TAO_LB_CPU_UTILIZATION_MONITOR_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LoadBalancing_export.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingS.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_CPU_Utilization_Monitor - * - * @brief LoadMonitor implementation that monitors the overall CPU - * load on a given host. - * - * Loads returned from this load monitor is the utilization of - * CPU in the "form" of percentage. - */ -class TAO_LoadBalancing_Export TAO_LB_CPU_Utilization_Monitor - : public virtual POA_CosLoadBalancing::LoadMonitor -{ -public: - - /// Constructor - /** - * If no location is supplied the hostname or IP address is used by - * default. - */ - TAO_LB_CPU_Utilization_Monitor (const char * location_id = 0, - const char * location_kind = 0); - - /** - * @name CosLoadBalancing::LoadMonitor Methods - * - * Methods required by the CosLoadBalancing::LoadMonitor interface. - */ - //@{ - - /// Return the location at which the LoadMonitor resides. - /** - * The returned "Location" is a sequence of length 1. - */ - virtual CosLoadBalancing::Location * the_location ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Return the average CPU load at the location which this - /// LoadMonitor resides. - /** - * @return A "Load" sequence of length 1 that contains a LoadId - * equal to CosLoadBalancing::LoadAverage, and the average CPU - * load. - */ - virtual CosLoadBalancing::LoadList * loads ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - //@} - -protected: - - /// Destructor - /** - * Protected destructor to enforce proper memory management through - * reference counting. - */ - ~TAO_LB_CPU_Utilization_Monitor (void); - -private: - - /// The name of the location at which this LoadMonitor resides. - CosLoadBalancing::Location location_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_CPU_UTILIZATION_MONITOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.cpp deleted file mode 100644 index abfe60c3f23..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ClientComponent.h" -#include "orbsvcs/LoadBalancing/LB_ClientORBInitializer.h" - -#include "tao/ORB_Constants.h" -#include "tao/ORBInitializer_Registry.h" - -ACE_RCSID (LoadBalancing, - LB_ClientComponent, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -int -TAO_LB_ClientComponent::init (int /* argc */, ACE_TCHAR * /* argv */[]) -{ - return this->register_orb_initializer (); -} - -int -TAO_LB_ClientComponent::fini (void) -{ - return 0; -} - -int -TAO_LB_ClientComponent::register_orb_initializer (void) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Register the LB_ClientComponent ORB initializer. - PortableInterceptor::ORBInitializer_ptr tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_ClientORBInitializer, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_TRY_CHECK; - - PortableInterceptor::ORBInitializer_var initializer = tmp; - - PortableInterceptor::register_orb_initializer (initializer.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Unable to register LB_ClientComponent ORB " - "initializer."); - return -1; - } - ACE_ENDTRY; - - return 0; -} - -TAO_END_VERSIONED_NAMESPACE_DECL - -ACE_STATIC_SVC_DEFINE (TAO_LB_ClientComponent, - ACE_TEXT ("LB_ClientComponent"), - ACE_SVC_OBJ_T, - &ACE_SVC_NAME (TAO_LB_ClientComponent), - ACE_Service_Type::DELETE_THIS | - ACE_Service_Type::DELETE_OBJ, - 0) - -ACE_FACTORY_DEFINE (TAO_LoadBalancing, TAO_LB_ClientComponent) diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.h deleted file mode 100644 index 8431950aff4..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientComponent.h +++ /dev/null @@ -1,68 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ClientComponent.h - * - * $Id$ - - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - -#ifndef TAO_LB_CLIENTCOMPONENT_H -#define TAO_LB_CLIENTCOMPONENT_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LoadBalancing_export.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/LB_ORTC.h" - -#include "ace/Service_Object.h" -#include "ace/Service_Config.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_ClientComponent - * - * @brief Service_Object that can be used to add load balancer support - * to a CORBA-based client. - * - * CORBA applications wishing to transparently add load shedding support - * can load this object via the ACE_Service_Configurator (e.g. by - * listing it in a `svc.conf' file). - */ -class TAO_LoadBalancing_Export TAO_LB_ClientComponent - : public ACE_Service_Object -{ -public: - - /// Initializes object when dynamic linking occurs. - virtual int init (int argc, ACE_TCHAR *argv[]); - - /// Terminates object when dynamic unlinking occurs. - virtual int fini (void); - -protected: - - /// Register the LB_ClientComponent's ORBInitializer. - int register_orb_initializer (void); - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -ACE_STATIC_SVC_DECLARE_EXPORT (TAO_LoadBalancing, TAO_LB_ClientComponent) -ACE_STATIC_SVC_REQUIRE (TAO_LB_ClientComponent) -ACE_FACTORY_DECLARE (TAO_LoadBalancing, TAO_LB_ClientComponent) - - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_CLIENTCOMPONENT_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.cpp deleted file mode 100644 index 10ef40d2a54..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ClientORBInitializer.h" -#include "orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.h" - -#include "tao/ORB_Constants.h" - -ACE_RCSID (LoadBalancing, - LB_ClientORBInitializer, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -void -TAO_LB_ClientORBInitializer::pre_init ( - PortableInterceptor::ORBInitInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ClientORBInitializer::post_init ( - PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - PortableInterceptor::ClientRequestInterceptor_ptr tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_ClientRequestInterceptor, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableInterceptor::ClientRequestInterceptor_var client_interceptor = tmp; - - info->add_client_request_interceptor (client_interceptor.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.h deleted file mode 100644 index 595c7198ea0..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientORBInitializer.h +++ /dev/null @@ -1,78 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ClientORBInitializer.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_CLIENT_ORB_INITIALIZER_H -#define TAO_LB_CLIENT_ORB_INITIALIZER_H - -#include /**/ "ace/pre.h" - -#include "tao/PI/PI.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/LocalObject.h" - -// This is to remove "inherits via dominance" warnings from MSVC. -// MSVC is being a little too paranoid. -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_ORBInitializer - * - * @brief ORBInitializer for the LB_ClientComponent Service_Object. - * - * This ORBInitializer simply creates and registers with the ORB the - * ClientRequestInterceptor that handles injection of the - * CosLoadBalancing::LOAD_MANAGED ServiceContext into each request's - * ServiceContextList. - */ -class TAO_LB_ClientORBInitializer - : public virtual PortableInterceptor::ORBInitializer, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /** - * @name PortableInterceptor::ORBInitializer Methods - * - * Methods required by the PortableInterceptor::ORBInitializer - * interface. - */ - //@{ - virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_CLIENT_ORB_INITIALIZER_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.cpp deleted file mode 100644 index 870a88577d2..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.h" - -#include "orbsvcs/CosLoadBalancingC.h" - - -ACE_RCSID (LoadBalancing, - TAO_LB_ClientRequestInterceptor, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -char * -TAO_LB_ClientRequestInterceptor::name ( - ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("TAO_LB_ClientRequestInterceptor"); -} - -void -TAO_LB_ClientRequestInterceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ClientRequestInterceptor::send_request ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ - /* - CORBA::Object_var t = ri->target (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - */ - - // A ServiceContext with an empty payload (i.e. zero length - // context_data) will be embedded into the request. - IOP::ServiceContext service_context; - service_context.context_id = CosLoadBalancing::LOAD_MANAGED; - - - /* - // A CDR encapsulation IOP::Codec could be used here, but it uses - // interpreted marshaling, which is slower than the compiled - // marshaling used below. - - TAO_OutputCDR cdr; - cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER); - - // Marshal the target object, i.e. the object reference that points - // back to the object group into the ServiceContextList. - cdr << t.in (); - - // TAO extension, replace the contents of the octet sequence with - // the CDR stream. - const CORBA::ULong tl = cdr.total_length (); - service_context.context_data.length (tl); - CORBA::Octet * buf = service_context.context_data.get_buffer (); - for (const ACE_Message_Block * i = cdr.begin (); - i != 0; - i = i->cont ()) - { - const size_t len = i->length (); - - // @todo It would be nice to avoid this copy. - ACE_OS::memcpy (buf, i->rd_ptr (), len); - buf += len; - } - */ - - const CORBA::Boolean replace = 0; - ri->add_request_service_context (service_context, - replace - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -void -TAO_LB_ClientRequestInterceptor::send_poll ( - PortableInterceptor::ClientRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ClientRequestInterceptor::receive_reply ( - PortableInterceptor::ClientRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ClientRequestInterceptor::receive_exception ( - PortableInterceptor::ClientRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ -} - -void -TAO_LB_ClientRequestInterceptor::receive_other ( - PortableInterceptor::ClientRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.h deleted file mode 100644 index 124a845a989..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ClientRequestInterceptor.h +++ /dev/null @@ -1,114 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ClientRequestInterceptor.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_CLIENT_REQUEST_INTERCEPTOR_H -#define TAO_LB_CLIENT_REQUEST_INTERCEPTOR_H - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/PI/PI.h" -#include "tao/PortableInterceptorC.h" -#include "tao/LocalObject.h" - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_ClientRequestInterceptor - * - * @brief Load balancer client request interceptor that injects an - * IOP::ServiceContext into a request's - * IOP::ServiceContextList. - * - * Load shedding requires that a specific ServiceContext exists - * in the request's ServiceContextList. The server side will attempt - * to detect if that ServiceContext exists, and shed load if it does. - * - * @note This model introduces a Denial-of-Service vulnerability. - * Malicious or incorrectly configured clients can spoof the - * server into thinking that it is invoking requests on a - * non-load balanced object. At that point, the server will let - * the request through, completely bypassing the load shedding - * mechanism! A server side-only mechanism can correct this - * vulnerability, but at the potential cost of additional - * resource overhead. - */ -class TAO_LB_ClientRequestInterceptor - : public virtual PortableInterceptor::ClientRequestInterceptor, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /** - * @name Methods Required by the Client Request Interceptor - * Interface - * - * These are methods that must be implemented since they are pure - * virtual in the abstract base class. They are the canonical - * methods required for all client request interceptors. - */ - //@{ - /// Return the name of this ClientRequestInterceptor. - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void send_request ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - - virtual void send_poll ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void receive_reply ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void receive_exception ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - - virtual void receive_other ( - PortableInterceptor::ClientRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - //@} - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#endif /* TAO_LB_CLIENT_REQUEST_INTERCEPTOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.cpp deleted file mode 100644 index 3e6d76a10aa..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_Component.h" -#include "orbsvcs/LoadBalancing/LB_ORBInitializer.h" - -#include "tao/ORB_Constants.h" -#include "tao/ORBInitializer_Registry.h" -#include "ace/OS_NS_strings.h" - -ACE_RCSID (LoadBalancing, - LB_Component, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -int -TAO_LB_Component::init (int argc, ACE_TCHAR * argv[]) -{ - // There must be at least six arguments. - if (argc < 6) - return -1; - - // Try to optimize sequence growth by growing it once. - const CORBA::ULong initial_len = argc / 6; // -LBGroup group - // -LBTypeId type_id - // -LBLocation location - - CORBA::StringSeq object_groups (initial_len); - object_groups.length (initial_len); - - CORBA::StringSeq repository_ids (initial_len); - repository_ids.length (initial_len); - - CORBA::String_var location; - - CORBA::ULong len = 0; - - for (int i = 0; i < argc; ++i) - { - if (ACE_OS::strcasecmp (argv[i], "-LBGroup") == 0) - { - const CORBA::ULong j = len; - ++len; - - ++i; // 1 - - object_groups.length (len); - object_groups[j] = CORBA::string_dup (argv[i]); - - ++i; // 2 - - if (ACE_OS::strcasecmp (argv[i], "-LBTypeId") != 0) - return -1; - - ++i; // 3 - - repository_ids.length (len); - repository_ids[j] = CORBA::string_dup (argv[i]); - } - else if (ACE_OS::strcasecmp (argv[i], "-LBTypeId") == 0) - { - const CORBA::ULong j = len; - ++len; - - ++i; // 1 - - repository_ids.length (len); - repository_ids[j] = CORBA::string_dup (argv[i]); - - ++i; // 2 - - if (ACE_OS::strcasecmp (argv[i], "-LBGroup") != 0) - return -1; - - ++i; // 3 - - object_groups.length (len); - object_groups[j] = CORBA::string_dup (argv[i]); - } - else if (ACE_OS::strcasecmp (argv[i], "-LBLocation") == 0) - { - ++i; - location = CORBA::string_dup (argv[i]); - } - } - - return this->register_orb_initializer (object_groups, - repository_ids, - location.in ()); -} - -int -TAO_LB_Component::fini (void) -{ - return 0; -} - -int -TAO_LB_Component::register_orb_initializer ( - const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Register the LB_Component ORB initializer. - PortableInterceptor::ORBInitializer_ptr tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_ORBInitializer (object_groups, - repository_ids, - location), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_TRY_CHECK; - - PortableInterceptor::ORBInitializer_var initializer = tmp; - - PortableInterceptor::register_orb_initializer (initializer.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Unable to register LB_Component ORB " - "initializer."); - return -1; - } - ACE_ENDTRY; - - return 0; -} - -TAO_END_VERSIONED_NAMESPACE_DECL - -ACE_STATIC_SVC_DEFINE (TAO_LB_Component, - ACE_TEXT ("LB_Component"), - ACE_SVC_OBJ_T, - &ACE_SVC_NAME (TAO_LB_Component), - ACE_Service_Type::DELETE_THIS - | ACE_Service_Type::DELETE_OBJ, - 0) - -ACE_FACTORY_DEFINE (TAO_LoadBalancing, TAO_LB_Component) diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.h deleted file mode 100644 index 26273daab93..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Component.h +++ /dev/null @@ -1,70 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_Component.h - * - * $Id$ - - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - -#ifndef TAO_LB_COMPONENT_H -#define TAO_LB_COMPONENT_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LoadBalancing_export.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/LB_ORTC.h" - -#include "ace/Service_Object.h" -#include "ace/Service_Config.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_Component - * - * @brief Service_Object that can be used to add load balancer support - * to a CORBA-based server. - * - * Servers wishing to transparently add load balancing/management - * support load this object via the ACE_Service_Configurator (e.g. by - * listing it in a `svc.conf' file). - */ -class TAO_LoadBalancing_Export TAO_LB_Component - : public ACE_Service_Object -{ -public: - - /// Initializes object when dynamic linking occurs. - virtual int init (int argc, ACE_TCHAR *argv[]); - - /// Terminates object when dynamic unlinking occurs. - virtual int fini (void); - -protected: - - /// Register the LB_Component's ORBInitializer. - int register_orb_initializer (const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location); - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -ACE_STATIC_SVC_DECLARE_EXPORT (TAO_LoadBalancing, TAO_LB_Component) -ACE_STATIC_SVC_REQUIRE (TAO_LB_Component) -ACE_FACTORY_DECLARE (TAO_LoadBalancing, TAO_LB_Component) - - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_COMPONENT_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.cpp deleted file mode 100644 index 3f555d17a5c..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_IORInterceptor.h" -#include "orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h" -#include "orbsvcs/LoadBalancing/LB_LoadAlert.h" - -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -ACE_RCSID (LoadBalancing, - LB_IORInterceptor, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_IORInterceptor::TAO_LB_IORInterceptor ( - const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location, - CosLoadBalancing::LoadManager_ptr lm, - const char * orb_id, - TAO_LB_LoadAlert & load_alert) - : object_groups_ (object_groups), - repository_ids_ (repository_ids), - location_ (location), - lm_ (CosLoadBalancing::LoadManager::_duplicate (lm)), - orb_id_ (CORBA::string_dup (orb_id)), - load_alert_ (load_alert), - la_ref_ (), - lock_ () -{ -} - -char * -TAO_LB_IORInterceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("TAO_LB_IORInterceptor"); -} - -void -TAO_LB_IORInterceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // Force the LoadManager reference to be released since the ORB's - // lifetime is tied to object reference lifetimes. - (void) this->lm_.out (); -} - -void -TAO_LB_IORInterceptor::establish_components ( - PortableInterceptor::IORInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_IORInterceptor::components_established ( - PortableInterceptor::IORInfo_ptr info - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - int argc = 0; - CORBA::ORB_var orb = CORBA::ORB_init (argc, - 0, - this->orb_id_.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Save a copy of the current ObjectReferenceFactory. - PortableInterceptor::ObjectReferenceFactory_var old_orf = - info->current_factory (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - PortableInterceptor::ObjectReferenceFactory * tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_ObjectReferenceFactory (old_orf.in (), - this->object_groups_, - this->repository_ids_, - this->location_.in (), - orb.in (), - this->lm_.in ()), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableInterceptor::ObjectReferenceFactory_var orf = tmp; - - info->current_factory (orf.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -void -TAO_LB_IORInterceptor::adapter_manager_state_changed ( - const char *, - PortableInterceptor::AdapterState state - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (state == PortableInterceptor::ACTIVE) - { - this->register_load_alert (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - } -} - -void -TAO_LB_IORInterceptor::adapter_state_changed ( - const PortableInterceptor::ObjectReferenceTemplateSeq &, - PortableInterceptor::AdapterState state - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (state == PortableInterceptor::ACTIVE) - { - this->register_load_alert (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - } -} - -void -TAO_LB_IORInterceptor::register_load_alert (ACE_ENV_SINGLE_ARG_DECL) -{ - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_); - - if (!CORBA::is_nil (this->la_ref_.in ())) - return; - } - - ACE_TRY_EX (foo) - { - // By now, the RootPOA has been fully initialized, so it is safe - // to activate the LoadAlert object. - CosLoadBalancing::LoadAlert_var la = - this->load_alert_._this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK_EX (foo); - - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_); - - this->la_ref_ = la; - } - - } - ACE_CATCHANY - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "LoadAlert::_this()"); - } - ACE_ENDTRY; - ACE_CHECK; - - ACE_TRY - { - PortableGroup::Location location (1); - location.length (1); - location[0].id = CORBA::string_dup (this->location_.in ()); - - this->lm_->register_load_alert (location, - this->la_ref_.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCH (CosLoadBalancing::LoadAlertAlreadyPresent, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "LoadManager::register_load_alert"); - - ACE_TRY_THROW (CORBA::BAD_INV_ORDER ()); - } - ACE_CATCH (CosLoadBalancing::LoadAlertNotAdded, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "LoadManager::register_load_alert"); - - ACE_TRY_THROW (CORBA::INTERNAL ()); - } - ACE_ENDTRY; - ACE_CHECK; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.h deleted file mode 100644 index 6b93c951912..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_IORInterceptor.h +++ /dev/null @@ -1,152 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_IORInterceptor.h - * - * $Id$ - - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - -#ifndef TAO_LB_IOR_INTERCEPTOR_H -#define TAO_LB_IOR_INTERCEPTOR_H - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingC.h" -#include "tao/LocalObject.h" -#include "tao/IORInterceptor/IORInterceptor.h" - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// Forward declarations. -class TAO_LB_LoadAlert; - - -/** - * @class TAO_LB_IORInterceptor - * - * @brief TAO Load Balancer IOR interceptor. - * - * This IORInterceptor is registered in object group member ORBs. - * During creation of the object group member reference, this - * IORInterceptor will change the "current_factory" attribute of the - * PortableInterceptor::IORInfo object to the Load Balancer's - * ObjectReferenceFactory. - * - * @see LB_ObjectReferenceFactory.h for details. - */ -class TAO_LB_IORInterceptor - : public virtual PortableInterceptor::IORInterceptor_3_0, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /// Constructor. - TAO_LB_IORInterceptor (const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location, - CosLoadBalancing::LoadManager_ptr lm, - const char * orb_id, - TAO_LB_LoadAlert & load_alert); - - /** - * @name Methods Required by the IOR Interceptor Interface - * - * These are methods that must be implemented since they are pure - * virtual in the abstract base class. They are the canonical - * methods required for all IOR interceptors. - */ - //@{ - /// Return the name of this IORInterceptor. - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Cleanup resources acquired by this IORInterceptor. - virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Add the tagged components to the IOR. - virtual void establish_components ( - PortableInterceptor::IORInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC (( - CORBA::SystemException - )); - - virtual void components_established ( - PortableInterceptor::IORInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void adapter_manager_state_changed ( - const char * id, - PortableInterceptor::AdapterState state - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC (( - CORBA::SystemException - )); - - virtual void adapter_state_changed ( - const PortableInterceptor::ObjectReferenceTemplateSeq & templates, - PortableInterceptor::AdapterState state - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC (( - CORBA::SystemException - )); - - //@} - -private: - - /// Create and register the LoadAlert object with the LoadManager. - void register_load_alert (ACE_ENV_SINGLE_ARG_DECL); - -private: - - /// List of stringified object group references. - const CORBA::StringSeq object_groups_; - - /// List of RepositoryIds for object that will be load - /// managed/balanced. - const CORBA::StringSeq repository_ids_; - - /// Location at which the LoadBalancing component resides. - CORBA::String_var location_; - - /// Reference to the LoadManager. - CosLoadBalancing::LoadManager_var lm_; - - /// ORBid of the ORB this IORInterceptor is registered with. - CORBA::String_var orb_id_; - - /// Reference to the LoadAlert servant. - TAO_LB_LoadAlert & load_alert_; - - /// Reference to the LoadAlert object. - CosLoadBalancing::LoadAlert_var la_ref_; - - /// Synchronize access to the class state. - TAO_SYNCH_MUTEX lock_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#endif /* TAO_LB_IOR_INTERCEPTOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.cpp deleted file mode 100644 index 00c4fa6203d..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.cpp +++ /dev/null @@ -1,641 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LeastLoaded.h" -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" -#include "orbsvcs/LoadBalancing/LB_Random.h" - -#include "orbsvcs/PortableGroup/PG_conf.h" - -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -#include "ace/Null_Mutex.h" -#include "ace/OS_NS_string.h" - - -ACE_RCSID (LoadBalancing, - LB_LeastLoaded, - "$Id$") - - -#if !defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LeastLoaded.inl" -#endif /* defined INLINE */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LeastLoaded::TAO_LB_LeastLoaded (PortableServer::POA_ptr poa) - : poa_ (PortableServer::POA::_duplicate (poa)), - load_map_ (0), - lock_ (0), - properties_ (), - critical_threshold_ (TAO_LB::LL_DEFAULT_CRITICAL_THRESHOLD), - reject_threshold_ (TAO_LB::LL_DEFAULT_REJECT_THRESHOLD), - tolerance_ (TAO_LB::LL_DEFAULT_TOLERANCE), - dampening_ (TAO_LB::LL_DEFAULT_DAMPENING), - per_balance_load_ (TAO_LB::LL_DEFAULT_DAMPENING) -{ - // A load map that retains previous load values at a given location - // and lock are only needed if dampening is enabled, i.e. non-zero. - if (this->dampening_ != 0) - { - ACE_NEW (this->load_map_, TAO_LB_LoadMap (TAO_PG_MAX_LOCATIONS)); - - ACE_NEW (this->lock_, TAO_SYNCH_MUTEX); - } - - // Initialize the random load balancing strategy. - TAO_LB_Random::init (); -} - -TAO_LB_LeastLoaded::~TAO_LB_LeastLoaded (void) -{ - delete this->load_map_; - delete this->lock_; -} - -char * -TAO_LB_LeastLoaded::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("LeastLoaded"); -} - -CosLoadBalancing::Properties * -TAO_LB_LeastLoaded::get_properties (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Properties * props = 0; - ACE_NEW_THROW_EX (props, - CosLoadBalancing::Properties (this->properties_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - return props; -} - -void -TAO_LB_LeastLoaded::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // Only the first load is used by this load balancing strategy. - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - CosLoadBalancing::Load load; // Unused - - this->push_loads (the_location, - loads, - load - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LeastLoaded::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & load - ACE_ENV_ARG_DECL) -{ - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - // Only the first load is used by this load balancing strategy. - const CosLoadBalancing::Load & new_load = loads[0]; - - if (this->load_map_ != 0) - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, *this->lock_); - - TAO_LB_LoadMap::ENTRY * entry; - if (this->load_map_->find (the_location, entry) == 0) - { - CosLoadBalancing::Load & previous_load = entry->int_id_; - - if (previous_load.id != new_load.id) - ACE_THROW (CORBA::BAD_PARAM ()); // Somebody switched - // LoadIds on us! - - previous_load.value = - this->effective_load (previous_load.value, new_load.value); - - load = previous_load; - } - else - { - const CosLoadBalancing::Load eff_load = - { - new_load.id, - this->effective_load (0, new_load.value) - }; - - if (this->load_map_->bind (the_location, eff_load) != 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "ERROR: TAO_LB_LeastLoaded - " - "Unable to push loads\n")); - - ACE_THROW (CORBA::INTERNAL ()); - } - - load = eff_load; - } - } - else - { - load.id = new_load.id; - load.value = this->effective_load (0, new_load.value); - } -} - -CosLoadBalancing::LoadList * -TAO_LB_LeastLoaded::get_loads (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0); - - CosLoadBalancing::LoadList_var loads = - load_manager->get_loads (the_location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->push_loads (the_location, - loads.in (), - loads[0] - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return loads._retn (); -} - - -CORBA::Object_ptr -TAO_LB_LeastLoaded::next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - CORBA::Object::_nil ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (locations->length () == 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), - CORBA::Object::_nil ()); - - // @@ RACE CONDITION. OBJECT GROUP MEMBERSHIP MAY CHANGE AFTER - // RETRIEVING LOCATIONS! HOW DO WE HANDLE THAT? - - PortableGroup::Location location; - CORBA::Boolean found_location = - this->get_location (load_manager, - locations.in (), - location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (found_location) - { -// ACE_DEBUG ((LM_DEBUG, -// "RETURNING REFERENCE FOR LOCATION \"%s\"\n", -// location[0].id.in ())); - - return load_manager->get_member_ref (object_group, - location - ACE_ENV_ARG_PARAMETER); - } - else - { - // No loads have been reported for any of the locations the - // object group members reside at. If no loads have been - // reported to the LoadManager, adaptive load balancing - // decisions cannot be made. Fall back on a non-adaptive - // strategy, such as the Random load balancing strategy, - // instead. - // - // @note The Random load balancing strategy is used since it is - // very lightweight and stateless. - - return TAO_LB_Random::_tao_next_member (object_group, - load_manager, - locations.in () - ACE_ENV_ARG_PARAMETER); - } -} - -void -TAO_LB_LeastLoaded::analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW (CORBA::BAD_PARAM ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (locations->length () == 0) - ACE_THROW (CORBA::TRANSIENT ()); - - const CORBA::ULong len = locations->length (); - - // Iterate through the entire location list to determine which - // locations require load to be shed. - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - const PortableGroup::Location & loc = locations[i]; - - // Retrieve the load list for the location from the - // LoadManager and push it to this Strategy's load - // processor. - CosLoadBalancing::LoadList_var current_loads = - load_manager->get_loads (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - CosLoadBalancing::Load load; - this->push_loads (loc, - current_loads.in (), - load - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -/* - ACE_DEBUG ((LM_DEBUG, - "EFFECTIVE_LOAD == %f\n" - "CRITICAL == %f\n" - "REJECT == %f\n" - "DAMPENING == %f\n", - load.value, - this->critical_threshold_, - this->reject_threshold_, - this->dampening_)); -*/ - // Perform load rebalancing only if the critical threshold - // was set. - if (this->critical_threshold_ != 0) - { - if (load.value > this->critical_threshold_) - { -/* - ACE_DEBUG ((LM_DEBUG, - "%P --- ALERTING LOCATION %u\n", - i)); -*/ - - // The location is overloaded. Perform load - // shedding by informing the LoadAlert object - // associated with the member at that location it - // should redirect client requests back to the - // LoadManager. - load_manager->enable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - else - { - // The location is not overloaded. Disable load - // shedding at given location. - load_manager->disable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - } - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // No load available for the requested location. Try the - // next location. - } - ACE_ENDTRY; - ACE_CHECK; - } -} - -PortableServer::POA_ptr -TAO_LB_LeastLoaded::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - -CORBA::Boolean -TAO_LB_LeastLoaded::get_location ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations, - PortableGroup::Location & location - ACE_ENV_ARG_DECL) -{ - CORBA::Float min_load = FLT_MAX; // Start out with the largest - // positive value. - - CORBA::ULong location_index = 0; - CORBA::Boolean found_location = 0; - CORBA::Boolean found_load = 0; - - const CORBA::ULong len = locations.length (); - - // Iterate through the entire location list to find the least loaded - // of them. - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - const PortableGroup::Location & loc = locations[i]; - - // Retrieve the load list for the location from the LoadManager - // and push it to this Strategy's load processor. - CosLoadBalancing::LoadList_var current_loads = - load_manager->get_loads (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - found_load = 1; - - CosLoadBalancing::Load load; - this->push_loads (loc, - current_loads.in (), - load - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -/* - ACE_DEBUG ((LM_DEBUG, - "LOC = %u" - "\tC = %d" - "\treject = %f" - "\tload = %f\n" - "\tmin_load = %f\n", - i, - (this->reject_threshold_ == 0 - || load.value < this->reject_threshold_), - this->reject_threshold_, - load.value, - min_load)); -*/ - if ((this->reject_threshold_ == 0 - || load.value < this->reject_threshold_) - && load.value < min_load) - { -// ACE_DEBUG ((LM_DEBUG, -// "**** LOAD == %f\n", -// load.value)); - - if (i > 0 && load.value != 0) - { - /* - percent difference = - (min_load - load.value) / load.value - == (min_load / load.value) - 1 - - The latter form is used to avoid a potential - arithmetic overflow problem, such as when - (min_load - load.value) > FLT_MAX, assuming that - either load.value is negative and min_load is - positive, or vice versa. - */ - const CORBA::Float percent_diff = - (min_load / load.value) - 1; - - /* - A "thundering herd" phenomenon may occur when - location loads are basically the same (e.g. only - differ by a very small amount), where one object - group member ends up receiving the majority of - requests from different clients. In order to - prevent a single object group member from - receiving such request bursts, one of two equally - loaded locations is chosen at random. Thanks to - Carlos, Marina and Jody at ATD for coming up with - this solution to this form of the thundering herd - problem. - - See the documentation for - TAO_LB::LL_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF in - LB_LeastLoaded.h for additional information. - */ - if (percent_diff <= TAO_LB::LL_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF) - { - // Prevent integer arithmetic overflow. - const CORBA::Float NUM_MEMBERS = 2; - - // n == 0: Use previously selected location. - // n == 1: Use current location. - const CORBA::ULong n = - static_cast<CORBA::ULong> (NUM_MEMBERS * ACE_OS::rand () - / (RAND_MAX + 1.0)); - - ACE_ASSERT (n == 0 || n == 1); - - if (n == 1) - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "** NEW MIN_LOAD == %f\n", -// min_load)); - } - -// if (n == 0) -// ACE_DEBUG ((LM_DEBUG, "^^^^^ PREVIOUS LOCATION\n")); -// else -// ACE_DEBUG ((LM_DEBUG, "^^^^^ CURRENT LOCATION\n")); - - } - else - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "***** NEW MIN_LOAD == %f\n", -// min_load)); - } - } - else - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "NEW MIN_LOAD == %f\n", -// min_load)); - } - } - - // ACE_DEBUG ((LM_DEBUG, "NEW MIN_LOAD == %f\n", min_load)); - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // No load available for the requested location. Try the - // next location. - } - ACE_ENDTRY; - ACE_CHECK_RETURN (0); - } - -// ACE_DEBUG ((LM_DEBUG, -// "FOUND_LOAD == %u\n" -// "FOUND_LOCATION == %u\n", -// found_load, -// found_location)); - - // If no loads were found, return without an exception to allow this - // strategy to select a member using an alternative method - // (e.g. random selection). - if (found_load) - { - if (found_location) - { - //ACE_DEBUG ((LM_DEBUG, "LOCATED = %u\n", location_index)); - location = locations[location_index]; - } - else if (this->reject_threshold_ != 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), 0); - -// ACE_DEBUG ((LM_DEBUG, "LOCATION ID == %s\n", location[0].id.in ())); - } - - return found_location; -} - -void -TAO_LB_LeastLoaded::init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) -{ - CORBA::Float critical_threshold = - TAO_LB::LL_DEFAULT_CRITICAL_THRESHOLD; - CORBA::Float reject_threshold = TAO_LB::LL_DEFAULT_REJECT_THRESHOLD; - CORBA::Float tolerance = TAO_LB::LL_DEFAULT_TOLERANCE; - CORBA::Float dampening = TAO_LB::LL_DEFAULT_DAMPENING; - CORBA::Float per_balance_load = TAO_LB::LL_DEFAULT_PER_BALANCE_LOAD; - - const PortableGroup::Property * ct = 0; // critical threshold property - - const CORBA::ULong len = props.length (); - for (CORBA::ULong i = 0; i < len; ++i) - { - const PortableGroup::Property & property = props[i]; - if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LeastLoaded.CriticalThreshold") == 0) - { - this->extract_float_property (property, - critical_threshold - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - ct = &property; - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LeastLoaded.RejectThreshold") == 0) - { - this->extract_float_property (property, - reject_threshold - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LeastLoaded.Tolerance") == 0) - { - this->extract_float_property (property, - tolerance - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Valid tolerance values are greater than or equal to one. - if (tolerance < 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LeastLoaded.Dampening") == 0) - { - this->extract_float_property (property, - dampening - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Dampening range is [0,1). - if (dampening < 0 || dampening >= 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LeastLoaded.PerBalanceLoad") == 0) - { - this->extract_float_property (property, - per_balance_load - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - } - - if (critical_threshold != 0 && reject_threshold != 0 - && critical_threshold <= reject_threshold) - ACE_THROW (PortableGroup::InvalidProperty (ct->nam, ct->val)); - - this->properties_ = props; - - this->critical_threshold_ = critical_threshold; - this->reject_threshold_ = reject_threshold; - this->tolerance_ = tolerance; - this->dampening_ = dampening; - this->per_balance_load_ = per_balance_load; -/* - ACE_DEBUG ((LM_DEBUG, - "--------------------------------\n" - "critical_threshold = %f\n" - "reject_threshold = %f\n" - "tolerance = %f\n" - "dampening = %f\n" - "per_balance_load = %f\n" - "--------------------------------\n", - critical_threshold, - reject_threshold, - tolerance, - dampening, - per_balance_load)); -*/ -} - -void -TAO_LB_LeastLoaded::extract_float_property ( - const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL) -{ - if (!(property.val >>= value)) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.h deleted file mode 100644 index a7843028c66..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.h +++ /dev/null @@ -1,229 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_LeastLoaded.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef LB_LEAST_LOADED_H -#define LB_LEAST_LOADED_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingS.h" - -#include "ace/Synch_Traits.h" -#include "ace/Thread_Mutex.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -namespace TAO_LB -{ - /** - * @name Default LeastLoaded strategy parameters. - * - * Defaults defined by the Load Balancing specification. - */ - //@{ - const CORBA::Float LL_DEFAULT_CRITICAL_THRESHOLD = 0; - const CORBA::Float LL_DEFAULT_REJECT_THRESHOLD = 0; - const CORBA::Float LL_DEFAULT_TOLERANCE = 1; - const CORBA::Float LL_DEFAULT_DAMPENING = 0; - const CORBA::Float LL_DEFAULT_PER_BALANCE_LOAD = 0; - //@} - - /** - * @name TAO-specific LeastLoaded strategy parameters. - * - * Parameters internal to TAO's LeastLoaded strategy - * implementation. - */ - //@{ - /// Percentage difference between two load values that determines - /// whether the loads are considered equivalent. - /** - * If the percent difference between two loads, i.e.: - * (Old Load - New Load) / New Load - * is less than or equal to this value, the two loads will be - * considered equivalent. In such a case, an object group member - * residing at the location corresponding to one of the two loads - * will be selected at random. - */ - const CORBA::Float LL_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF = 0.01f; // 1% - //@} -} - -/** - * @class TAO_LB_LeastLoaded - * - * @brief "Least loaded" load balancing strategy - * - * This load balancing strategy is designed to select an object group - * member residing at a location with the smallest load. - */ -class TAO_LB_LeastLoaded - : public virtual POA_CosLoadBalancing::Strategy -{ -public: - - /// Constructor. - TAO_LB_LeastLoaded (PortableServer::POA_ptr poa); - - /** - * @name CosLoadBalancing::Strategy methods - * - * Methods required by the CosLoadBalancing::Strategy interface. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::Properties * get_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::LoadList * get_loads ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - virtual CORBA::Object_ptr next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - virtual void analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - /// Returns the default POA for this servant. - virtual PortableServer::POA_ptr _default_POA ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS - ); - - /// Initialize the LeastLoaded instance with the given properties. - void init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL); - -protected: - - /// Destructor. - ~TAO_LB_LeastLoaded (void); - - /// Retrieve the least loaded location from the given list of - /// locations. - CORBA::Boolean get_location (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations, - PortableGroup::Location & location - ACE_ENV_ARG_DECL); - - /// Return the effective load. - CORBA::Float effective_load (CORBA::Float previous_load, - CORBA::Float new_load); - - /// Push the new load into this Strategy's load processor, and - /// return the corresponding effective load. - void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & effective_load - ACE_ENV_ARG_DECL); - - /// Utility method to extract a CORBA::Float value from the given - /// property. - void extract_float_property (const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL); - -private: - - /// This servant's default POA. - PortableServer::POA_var poa_; - - /// Table that maps location to load list. - TAO_LB_LoadMap * load_map_; - - /// Lock used to ensure atomic access to state retained by this - /// class. - TAO_SYNCH_MUTEX * lock_; - - /// Cached set of properties used when initializing this strategy. - CosLoadBalancing::Properties properties_; - - /** - * @name LeastLoaded Property Values - * - * Cached LeastLoaded load balancing strategy property values. - */ - //@{ - - /// The critical load threshold. - /** - * Load rebalancing/shedding will occur if loads at a given location - * are greater than this value. The default value is zero, which - * indicates that no load rebalancing/shedding will occur. - */ - CORBA::Float critical_threshold_; - - /// The request rejection threshold. - /** - * If the load at a given location is greater than this value, the - * member at that location will not be considered when choosing a - * member to the request will be forwarded. If all locations have - * loads greater than this value, a @c CORBA::TRANSIENT exception - * will be thrown unless the reject threshold is zero, which is the - * default. If the request rejection threshold is zero, a @c - * CORBA::TRANSIENT will not be thrown by this load balancing - * strategy, unless no object group members have been added yet. - */ - CORBA::Float reject_threshold_; - - /// - CORBA::Float tolerance_; - - /// - CORBA::Float dampening_; - - /// - CORBA::Float per_balance_load_; - - //@} - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - - -#if defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LeastLoaded.inl" -#endif /* defined INLINE */ - -#include /**/ "ace/post.h" - -#endif /* LB_LEAST_LOADED_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.inl b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.inl deleted file mode 100644 index e59193f3c6f..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LeastLoaded.inl +++ /dev/null @@ -1,27 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -ACE_INLINE CORBA::Float -TAO_LB_LeastLoaded::effective_load (CORBA::Float previous_load, - CORBA::Float new_load) -{ - // Apply per-balance load. (Recompute raw load) - previous_load += this->per_balance_load_; - - // Apply dampening. (Recompute new raw load) - CORBA::Float result = - this->dampening_ * previous_load + (1 - this->dampening_) * new_load; - - ACE_ASSERT (this->tolerance_ != 0); - - // Compute the effective load. - result /= this->tolerance_; - - return result; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.cpp deleted file mode 100644 index a57212dbce6..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadAlert.h" - - -ACE_RCSID (LoadBalancer, - LB_LoadAlert, - "$Id$") - -#if !defined (__ACE_INLINE__) -# include "orbsvcs/LoadBalancing/LB_LoadAlert.inl" -#endif /* __ACE_INLINE__ */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadAlert::TAO_LB_LoadAlert (void) - : alerted_ (0), - lock_ () -{ -} - -TAO_LB_LoadAlert::~TAO_LB_LoadAlert (void) -{ -} - -void -TAO_LB_LoadAlert::enable_alert (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_); - - this->alerted_ = 1; -} - -void -TAO_LB_LoadAlert::disable_alert (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_); - - this->alerted_ = 0; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.h deleted file mode 100644 index f5345ef7f07..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.h +++ /dev/null @@ -1,87 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_LoadAlert.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_LOAD_ALERT_H -#define TAO_LB_LOAD_ALERT_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingS.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/PortableGroupC.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -class TAO_LoadBalancing_Export TAO_LB_LoadAlert - : public virtual POA_CosLoadBalancing::LoadAlert -{ -public: - - /// Constructor. - TAO_LB_LoadAlert (void); - - /** - * @name CosLoadBalancing::LoadAlert Methods - * - * Methods required by the CosLoadBalancing::LoadAlert interface. - */ - //@{ - - /// Forward requests back to the load manager via the object group - /// reference. - virtual void enable_alert (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Stop forwarding requests, and begin accepting them again. - virtual void disable_alert (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - //@} - - /// Has this LoadAlert servant been alerted of a high load condition - /// by the LoadManager. - CORBA::Boolean alerted (void) const; - -// protected: - - /// Destructor. - /** - * Protected destructor to enforce correct memory management via - * reference counting. - */ - virtual ~TAO_LB_LoadAlert (void); - -private: - - /// Has this LoadAlert servant been alerted of a high load condition - /// by the LoadManager? - CORBA::Boolean alerted_; - - /// Lock used to synchronized access to the LoadAlert state. - mutable TAO_SYNCH_MUTEX lock_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined (__ACE_INLINE__) -# include "orbsvcs/LoadBalancing/LB_LoadAlert.inl" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_ALERT_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.inl b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.inl deleted file mode 100644 index abff1d3087e..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert.inl +++ /dev/null @@ -1,16 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -ACE_INLINE CORBA::Boolean -TAO_LB_LoadAlert::alerted (void) const -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, monitor, this->lock_, 0); - - return this->alerted_; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.cpp deleted file mode 100644 index 0378e9f584e..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadAlertInfo.h" -#include "orbsvcs/PortableGroup/PG_Operators.h" - -ACE_RCSID (LoadBalancing, - LB_LoadAlertInfo, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadAlertInfo::TAO_LB_LoadAlertInfo (void) - : load_alert (), - alerted (0) -{ -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.h deleted file mode 100644 index 47c3f7b384c..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertInfo.h +++ /dev/null @@ -1,54 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_LoadAlertInfo.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_LOAD_ALERT_INFO_H -#define TAO_LB_LOAD_ALERT_INFO_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingC.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_LoadAlertInfo - * - * @brief Structure that contains all LoadAlert-specific information. - * - * Structure that contains all LoadAlert-specific information. - */ -struct TAO_LB_LoadAlertInfo -{ - /// Constructor. - TAO_LB_LoadAlertInfo (void); - - /// Reference to the LoadAlert object. - CosLoadBalancing::LoadAlert_var load_alert; - - /// True if the LoadAlert object has been alerted about a given load - /// condition. False otherwise. - CORBA::Boolean alerted; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_ALERT_INFO_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertMap.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertMap.h deleted file mode 100644 index 5451acafddb..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlertMap.h +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_LoadAlertMap.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_LOAD_ALERT_MAP_H -#define TAO_LB_LOAD_ALERT_MAP_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/LoadBalancing/LB_LoadAlertInfo.h" - -#include "orbsvcs/PortableGroup/PG_Location_Hash.h" -#include "orbsvcs/PortableGroup/PG_Location_Equal_To.h" - -#include "ace/Hash_Map_Manager_T.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// LoadAlertInfo hash map typedef. -typedef ACE_Hash_Map_Manager_Ex< - PortableGroup::Location, - TAO_LB_LoadAlertInfo, - TAO_PG_Location_Hash, - TAO_PG_Location_Equal_To, - ACE_Null_Mutex> TAO_LB_LoadAlertMap; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_ALERT_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.cpp deleted file mode 100644 index ca2bf1b5116..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadAlert_Handler.h" - -#include "tao/debug.h" - - -ACE_RCSID (LoadBalancing, - LB_LoadAlert_Handler, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadAlert_Handler::~TAO_LB_LoadAlert_Handler (void) -{ -} - -void -TAO_LB_LoadAlert_Handler::enable_alert (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_LoadAlert_Handler::enable_alert_excep ( - ::Messaging::ExceptionHolder * - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("Exception caught when invoking ") - ACE_TEXT ("LoadAlert::enable_alert()\n"))); -} - -void -TAO_LB_LoadAlert_Handler::disable_alert (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_LoadAlert_Handler::disable_alert_excep ( - ::Messaging::ExceptionHolder * - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("Exception caught when invoking ") - ACE_TEXT ("LoadAlert::disable_alert()\n"))); -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.h deleted file mode 100644 index d19518ce96d..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAlert_Handler.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- - -// ============================================================================ -/** - * @file LB_LoadAlert_Handler.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -// ============================================================================ - -#ifndef TAO_LB_LOAD_ALERT_REPLY_HANDLER_H -#define TAO_LB_LOAD_ALERT_REPLY_HANDLER_H - -#include "orbsvcs/CosLoadBalancingS.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -// This is to remove "inherits via dominance" warnings from MSVC. -// MSVC is being a little too paranoid. -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_LoadAlert_Handler - * - * @brief The AMI reply handler for replies from all LoadAlert - * objects. - * - * This class handles all asynchronously received replies from all - * registered LoadAlert objects. It only exists to receive - * asynchronously sent exceptions. - */ -class TAO_LB_LoadAlert_Handler - : public virtual POA_CosLoadBalancing::AMI_LoadAlertHandler -{ -public: - - virtual void enable_alert (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void enable_alert_excep ( - ::Messaging::ExceptionHolder * - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void disable_alert (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void disable_alert_excep ( - ::Messaging::ExceptionHolder * - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - -protected: - - /// Protected destructor to enforce propery memory management - /// through reference counting. - ~TAO_LB_LoadAlert_Handler (void); - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#endif /* TAO_LB_LOAD_ALERT_REPLY_HANDLER_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.cpp deleted file mode 100644 index c6a0d0c3fa3..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.cpp +++ /dev/null @@ -1,454 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadAverage.h" -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" -#include "orbsvcs/LoadBalancing/LB_Random.h" - -#include "orbsvcs/PortableGroup/PG_conf.h" - -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -#include "ace/Null_Mutex.h" -#include "ace/OS_NS_string.h" - - -ACE_RCSID (LoadBalancing, - LB_LoadAverage, - "$Id$") - - -#if !defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LoadAverage.inl" -#endif /* defined INLINE */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadAverage::TAO_LB_LoadAverage (PortableServer::POA_ptr poa) - : poa_ (PortableServer::POA::_duplicate (poa)), - load_map_ (0), - lock_ (0), - properties_ (), - tolerance_ (TAO_LB::LA_DEFAULT_TOLERANCE), - dampening_ (TAO_LB::LA_DEFAULT_DAMPENING), - per_balance_load_ (TAO_LB::LA_DEFAULT_DAMPENING) -{ - // A load map that retains previous load values at a given location - // and lock are only needed if dampening is enabled, i.e. non-zero. - if (this->dampening_ != 0) - { - ACE_NEW (this->load_map_, TAO_LB_LoadMap (TAO_PG_MAX_LOCATIONS)); - - ACE_NEW (this->lock_, TAO_SYNCH_MUTEX); - } - - // Initialize the random load balancing strategy. - TAO_LB_Random::init (); -} - -TAO_LB_LoadAverage::~TAO_LB_LoadAverage (void) -{ - delete this->load_map_; - delete this->lock_; -} - -char * -TAO_LB_LoadAverage::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("LoadAverage"); -} - -CosLoadBalancing::Properties * -TAO_LB_LoadAverage::get_properties (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Properties * props = 0; - ACE_NEW_THROW_EX (props, - CosLoadBalancing::Properties (this->properties_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - return props; -} - -void -TAO_LB_LoadAverage::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // Only the first load is used by this load balancing strategy. - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - CosLoadBalancing::Load load; // Unused - - this->push_loads (the_location, - loads, - load - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadAverage::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & load - ACE_ENV_ARG_DECL) -{ - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - // Only the first load is used by this load balancing strategy. - const CosLoadBalancing::Load & new_load = loads[0]; - - if (this->load_map_ != 0) - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, *this->lock_); - - TAO_LB_LoadMap::ENTRY * entry; - if (this->load_map_->find (the_location, entry) == 0) - { - CosLoadBalancing::Load & previous_load = entry->int_id_; - - if (previous_load.id != new_load.id) - ACE_THROW (CORBA::BAD_PARAM ()); // Somebody switched - // LoadIds on us! - - previous_load.value = - this->effective_load (previous_load.value, new_load.value); - - load = previous_load; - } - else - { - const CosLoadBalancing::Load eff_load = - { - new_load.id, - this->effective_load (0, new_load.value) - }; - - if (this->load_map_->bind (the_location, eff_load) != 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "ERROR: TAO_LB_LoadAverage - " - "Unable to push loads\n")); - - ACE_THROW (CORBA::INTERNAL ()); - } - - load = eff_load; - } - } - else - { - load.id = new_load.id; - load.value = this->effective_load (0, new_load.value); - } -} - -CosLoadBalancing::LoadList * -TAO_LB_LoadAverage::get_loads (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0); - - CosLoadBalancing::LoadList_var loads = - load_manager->get_loads (the_location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->push_loads (the_location, - loads.in (), - loads[0] - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return loads._retn (); -} - - -CORBA::Object_ptr -TAO_LB_LoadAverage::next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - CORBA::Object::_nil ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (locations->length () == 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), - CORBA::Object::_nil ()); - - // @note The Random load balancing strategy is used since it is - // very lightweight and stateless. - - return TAO_LB_Random::_tao_next_member (object_group, - load_manager, - locations.in () - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadAverage::analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW (CORBA::BAD_PARAM ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (locations->length () == 0) - ACE_THROW (CORBA::TRANSIENT ()); - - const CORBA::ULong len = locations->length (); - - CosLoadBalancing::Load total_load = { 0, 0 }; - CosLoadBalancing::Load avg_load = { 0, 0 }; - - CosLoadBalancing::LoadList tmp (len); - tmp.length (1); - - // Iterate through the entire location list to determine - // the average load of all the locations - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - const PortableGroup::Location & loc = locations[i]; - - // Retrieve the load list for the location from the - // LoadManager and push it to this Strategy's load - // processor. - CosLoadBalancing::LoadList_var current_loads = - load_manager->get_loads (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - CosLoadBalancing::Load load; - this->push_loads (loc, - current_loads.in (), - load - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - // @@ Jai, please use the compound "+=" operator here. It - // is more efficient in this case. - total_load.value = total_load.value + load.value; - - tmp[i] = load; - - /* - ACE_DEBUG ((LM_DEBUG, - "TOTAL == %f\n", - total_load.value)); - */ - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // no location found - // - } - ACE_ENDTRY; - ACE_CHECK; - } - - avg_load.value = total_load.value / len; -/* - ACE_DEBUG ((LM_DEBUG, - "AVERAGE LOAD == %f\n", - avg_load.value)); -*/ - - // Iterate through the entire location list to determine - // the location where the load has to be shed. - for (CORBA::ULong j = 0; j < len; ++j) - { - ACE_TRY_EX (SECOND) - { - const PortableGroup::Location & loc = locations[j]; - - /* - ACE_DEBUG ((LM_DEBUG, - "EFFECTIVE_LOAD == %f\n" - "AVERAGE == %f\n", - tmp[i].value, - avg_load.value)); - */ - - if (tmp[j].value <= avg_load.value) - { - load_manager->disable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (SECOND); - } - else - { - CORBA::Float percent_diff = - (tmp[j].value / avg_load.value) - 1; - - if (tmp[j].value == avg_load.value) - { - percent_diff = 0; - } -/* - ACE_DEBUG ((LM_DEBUG, - "ALERT LOC == %u" - "\tAVG LOAD == %f\n" - "\tLOAD == %f\n" - "\tPERCENT == %f\n", - i, - avg_load.value, - tmp[i].value, - percent_diff)); -*/ - - // @@ Jai, please correct the indentation on the below - // conditional blocks so that they conform to the ACE - // coding style. - if (percent_diff <= TAO_LB::LA_DEFAULT_DIFF_AVERAGE_CUTOFF) - { - load_manager->disable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (SECOND); - } - else if ((percent_diff > TAO_LB::LA_DEFAULT_DIFF_AVERAGE_CUTOFF) - && (percent_diff < 1)) - { -/* - ACE_DEBUG ((LM_DEBUG, - "%P --- ALERTING LOCATION %u\n", - i)); -*/ - - load_manager->enable_alert (loc - ACE_ENV_ARG_PARAMETER); - - ACE_TRY_CHECK_EX (SECOND); - } - - } - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // no location found - // - } - ACE_ENDTRY; - ACE_CHECK; - } - -} - -PortableServer::POA_ptr -TAO_LB_LoadAverage::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - -void -TAO_LB_LoadAverage::init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) -{ - CORBA::Float tolerance = TAO_LB::LA_DEFAULT_TOLERANCE; - CORBA::Float dampening = TAO_LB::LA_DEFAULT_DAMPENING; - CORBA::Float per_balance_load = TAO_LB::LA_DEFAULT_PER_BALANCE_LOAD; - - const CORBA::ULong len = props.length (); - for (CORBA::ULong i = 0; i < len; ++i) - { - const PortableGroup::Property & property = props[i]; - if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadAverage.Tolerance") == 0) - { - this->extract_float_property (property, - tolerance - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Valid tolerance values are greater than or equal to one. - if (tolerance < 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadAverage.Dampening") == 0) - { - this->extract_float_property (property, - dampening - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Dampening range is [0,1). - if (dampening < 0 || dampening >= 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadAverage.PerBalanceLoad") == 0) - { - this->extract_float_property (property, - per_balance_load - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - } - - this->properties_ = props; - - this->tolerance_ = tolerance; - this->dampening_ = dampening; - this->per_balance_load_ = per_balance_load; - - /* - ACE_DEBUG ((LM_DEBUG, - "--------------------------------\n" - "tolerance = %f\n" - "dampening = %f\n" - "per_balance_load = %f\n" - "--------------------------------\n", - tolerance, - dampening, - per_balance_load)); - */ -} - -void -TAO_LB_LoadAverage::extract_float_property ( - const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL) -{ - if (!(property.val >>= value)) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.h deleted file mode 100644 index 4af286ee527..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.h +++ /dev/null @@ -1,184 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_LoadAverage.h - * - * $Id$ - * - * @author Jaiganesh Balasubramanian <jai@dre.vanderbilt.edu> - * @author Ossama Othman <ossama@dre.vanderbilt.edu> - */ -//============================================================================= - - -#ifndef LB_LOAD_AVERAGE_H -#define LB_LOAD_AVERAGE_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingS.h" - -#include "ace/Synch_Traits.h" -#include "ace/Thread_Mutex.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -namespace TAO_LB -{ - /** - * @name Default LoadAverage strategy parameters. - * - * Defaults defined by the Load Balancing specification. - */ - //@{ - const CORBA::Float LA_DEFAULT_TOLERANCE = 1; - const CORBA::Float LA_DEFAULT_DAMPENING = 0; - const CORBA::Float LA_DEFAULT_PER_BALANCE_LOAD = 0; - - const CORBA::Float LA_DEFAULT_DIFF_AVERAGE_CUTOFF = 0.8f; - //@} - -} - -/** - * @class TAO_LB_LoadAverage - * - * @brief "Least loaded" load balancing strategy - * - * This load balancing strategy is designed to select an object group - * member residing at a location with the smallest load. - */ -class TAO_LB_LoadAverage - : public virtual POA_CosLoadBalancing::Strategy -{ -public: - - /// Constructor. - TAO_LB_LoadAverage (PortableServer::POA_ptr poa); - - /** - * @name CosLoadBalancing::Strategy methods - * - * Methods required by the CosLoadBalancing::Strategy interface. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::Properties * get_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::LoadList * get_loads ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - virtual CORBA::Object_ptr next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - virtual void analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - /// Returns the default POA for this servant. - virtual PortableServer::POA_ptr _default_POA ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS - ); - - /// Initialize the LoadAverage instance with the given properties. - void init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL); - -protected: - - /// Destructor. - ~TAO_LB_LoadAverage (void); - - /// Return the effective load. - CORBA::Float effective_load (CORBA::Float previous_load, - CORBA::Float new_load); - - /// Push the new load into this Strategy's load processor, and - /// return the corresponding effective load. - void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & effective_load - ACE_ENV_ARG_DECL); - - /// Utility method to extract a CORBA::Float value from the given - /// property. - void extract_float_property (const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL); - -private: - - /// This servant's default POA. - PortableServer::POA_var poa_; - - /// Table that maps location to load list. - TAO_LB_LoadMap * load_map_; - - /// Lock used to ensure atomic access to state retained by this - /// class. - TAO_SYNCH_MUTEX * lock_; - - /// Cached set of properties used when initializing this strategy. - CosLoadBalancing::Properties properties_; - - /** - * @name LoadAverage Property Values - * - * Cached LoadAverage load balancing strategy property values. - */ - //@{ - - /// - CORBA::Float tolerance_; - - /// - CORBA::Float dampening_; - - /// - CORBA::Float per_balance_load_; - - //@} - - CosLoadBalancing::LoadList current_loads_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LoadAverage.inl" -#endif /* defined INLINE */ - -#include /**/ "ace/post.h" - -#endif /* LB_LOAD_AVERAGE_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.inl b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.inl deleted file mode 100644 index 347374c1a7c..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadAverage.inl +++ /dev/null @@ -1,26 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -ACE_INLINE CORBA::Float -TAO_LB_LoadAverage::effective_load (CORBA::Float previous_load, - CORBA::Float new_load) -{ - // Apply per-balance load. (Recompute raw load) - previous_load += this->per_balance_load_; - - // Apply dampening. (Recompute new raw load) - CORBA::Float result = - this->dampening_ * previous_load + (1 - this->dampening_) * new_load; - - ACE_ASSERT (this->tolerance_ != 0); - - // Compute the effective load. - result /= this->tolerance_; - - return result; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadListMap.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadListMap.h deleted file mode 100644 index 4dd83f2e2b9..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadListMap.h +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_LoadListMap.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_LOAD_LIST_MAP_H -#define TAO_LB_LOAD_LIST_MAP_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/PortableGroupC.h" - -#include "orbsvcs/PortableGroup/PG_Location_Hash.h" -#include "orbsvcs/PortableGroup/PG_Location_Equal_To.h" - -#include "ace/Hash_Map_Manager_T.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// LoadList hash map. -typedef ACE_Hash_Map_Manager_Ex< - PortableGroup::Location, - CosLoadBalancing::LoadList, - TAO_PG_Location_Hash, - TAO_PG_Location_Equal_To, - ACE_Null_Mutex> TAO_LB_LoadListMap; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_LIST_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.cpp deleted file mode 100644 index 10b42090791..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.cpp +++ /dev/null @@ -1,1295 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadManager.h" -#include "orbsvcs/LoadBalancing/LB_MemberLocator.h" -#include "orbsvcs/LoadBalancing/LB_LoadAlert_Handler.h" -#include "orbsvcs/LoadBalancing/LB_RoundRobin.h" -#include "orbsvcs/LoadBalancing/LB_Random.h" -#include "orbsvcs/LoadBalancing/LB_LoadMinimum.h" -#include "orbsvcs/LoadBalancing/LB_LoadAverage.h" -#include "orbsvcs/LoadBalancing/LB_LeastLoaded.h" -#include "orbsvcs/LoadBalancing/LB_conf.h" - -#include "orbsvcs/PortableGroup/PG_Property_Utils.h" -#include "orbsvcs/PortableGroup/PG_conf.h" - -#include "tao/Messaging/Messaging.h" -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -#include "ace/Reactor.h" -#include "ace/Reverse_Lock_T.h" -#include "ace/SString.h" -#include "ace/OS_NS_sys_time.h" -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_string.h" - - -ACE_RCSID (LoadBalancing, - LB_LoadManager, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadManager::TAO_LB_LoadManager (void) - : reactor_ (0), - poa_ (), - root_poa_ (), - monitor_lock_ (), - load_lock_ (), - load_alert_lock_ (), - lock_ (), - monitor_map_ (TAO_PG_MAX_LOCATIONS), - load_map_ (TAO_PG_MAX_LOCATIONS), - load_alert_map_ (TAO_PG_MAX_LOCATIONS), - object_group_manager_ (), - property_manager_ (object_group_manager_), - generic_factory_ (object_group_manager_, property_manager_), - pull_handler_ (), - timer_id_ (-1), - lm_ref_ (), - round_robin_ (), - random_ (), - least_loaded_ (), - load_minimum_ (), - load_average_ (), - built_in_balancing_strategy_info_name_ (1), - built_in_balancing_strategy_name_ (1), - custom_balancing_strategy_name_ (1) -{ - this->pull_handler_.initialize (&this->monitor_map_, this); - - // @note "this->init()" is not called here (in the constructor) - // since it may thrown an exception. Throwing an exception in - // a constructor in an emulated exception environment is - // problematic since native exception semantics cannot be - // reproduced in such a case. As such, init() must be called - // by whatever code instantiates this LoadManager. -} - -TAO_LB_LoadManager::~TAO_LB_LoadManager (void) -{ -} - -void -TAO_LB_LoadManager::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - { - ACE_GUARD (TAO_SYNCH_MUTEX, - guard, - this->load_lock_); - - if (this->load_map_.rebind (the_location, loads) == -1) - ACE_THROW (CORBA::INTERNAL ()); - } - - // Analyze loads for object groups that have members residing at the - // given location. - PortableGroup::ObjectGroups_var groups = - this->object_group_manager_.groups_at_location (the_location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - const CORBA::ULong len = groups->length (); - - for (CORBA::ULong i = 0; i < len; ++i) - { - PortableGroup::ObjectGroup_ptr object_group = - groups[i]; - - ACE_TRY - { - PortableGroup::Properties_var properties = - this->get_properties (object_group - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - PortableGroup::Value value; - CosLoadBalancing::Strategy_ptr strategy; - - if ((TAO_PG::get_property_value ( - this->built_in_balancing_strategy_name_, - properties.in (), - value) - || TAO_PG::get_property_value ( - this->custom_balancing_strategy_name_, - properties.in (), - value)) - && (value >>= strategy) - && !CORBA::is_nil (strategy)) - { - strategy->analyze_loads (object_group, - this->lm_ref_.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - } - ACE_CATCHANY - { - // Ignore all exceptions. - } - ACE_ENDTRY; - ACE_CHECK; - } -} - -CosLoadBalancing::LoadList * -TAO_LB_LoadManager::get_loads (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - CosLoadBalancing::LoadList * tmp; - ACE_NEW_THROW_EX (tmp, - CosLoadBalancing::LoadList, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - CosLoadBalancing::LoadList_var loads = tmp; - - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->load_lock_, - 0); - - if (this->load_map_.find (the_location, *tmp) == 0) - return loads._retn (); - else - ACE_THROW_RETURN (CosLoadBalancing::LocationNotFound (), 0); -} - -void -TAO_LB_LoadManager::enable_alert (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CosLoadBalancing::LoadAlertNotFound)) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->load_alert_lock_); - - TAO_LB_LoadAlertMap::ENTRY * entry; - if (this->load_alert_map_.find (the_location, entry) == 0) - { - TAO_LB_LoadAlertInfo & info = entry->int_id_; - - // @note This could be problematic if the LoadAlert object is - // registered with more than LoadManager. - - if (info.alerted == 1) - return; // No need to set the alert status. It has already - // been set. - - // Duplicate before releasing the LoadAlertMap lock to prevent a - // race condition from occuring. The LoadAlertInfo map may be - // altered prior to invoking an operation on the LoadAlert - // object. - CosLoadBalancing::LoadAlert_var load_alert = - CosLoadBalancing::LoadAlert::_duplicate (info.load_alert.in ()); - - // The alert condition will be enabled. - // @@ What happens if the below call fails? This variable - // should be reset to zero! - info.alerted = 1; - - { - // Release the lock prior to making the below remote - // invocation. - ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock ( - this->load_alert_lock_); - ACE_GUARD (ACE_Reverse_Lock<TAO_SYNCH_MUTEX>, - reverse_guard, - reverse_lock); - - // Use AMI to make the following operation "non-blocking," - // allowing the caller to continue without being forced to - // wait for a response. - // - // AMI is used to improve member selection times and overall - // throughput since the LoadAlert object need not be alerted - // synchronously. In particular, the load alert can and - // should be performed in parallel to other tasks, such as - // member selection. - load_alert->sendc_enable_alert (this->load_alert_handler_.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - } - else - ACE_THROW (CosLoadBalancing::LoadAlertNotFound ()); -} - -void -TAO_LB_LoadManager::disable_alert (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CosLoadBalancing::LoadAlertNotFound)) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->load_alert_lock_); - - TAO_LB_LoadAlertMap::ENTRY * entry; - if (this->load_alert_map_.find (the_location, entry) == 0) - { - TAO_LB_LoadAlertInfo & info = entry->int_id_; - - // @note This could be problematic if the LoadAlert object is - // registered with more than LoadManager. - if (info.alerted == 0) - return; // No need to set the alert status. It has already - // been set. - - // Duplicate before releasing the LoadAlertMap lock to prevent a - // race condition from occuring. The LoadAlertInfo map may be - // altered prior to invoking an operation on the LoadAlert - // object. - CosLoadBalancing::LoadAlert_var load_alert = - CosLoadBalancing::LoadAlert::_duplicate (info.load_alert.in ()); - - // The alert condition will be disabled. - // @@ What happens if the below call fails? This variable - // should be reset to one! - info.alerted = 0; - - { - // Release the lock prior to making the below remote - // invocation. - ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock ( - this->load_alert_lock_); - ACE_GUARD (ACE_Reverse_Lock<TAO_SYNCH_MUTEX>, - reverse_guard, - reverse_lock); - - // Use AMI to make the following operation "non-blocking," - // allowing the caller to continue without being forced to - // wait for a response. - // - // AMI is used to improve member selection times and overall - // throughput since the LoadAlert object need not be alerted - // synchronously. In particular, the load alert can and - // should be performed in parallel to other tasks, such as - // member selection. - load_alert->sendc_disable_alert (this->load_alert_handler_.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - } - else - ACE_THROW (CosLoadBalancing::LoadAlertNotFound ()); -} - -void -TAO_LB_LoadManager::register_load_alert ( - const PortableGroup::Location & the_location, - CosLoadBalancing::LoadAlert_ptr load_alert - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertAlreadyPresent, - CosLoadBalancing::LoadAlertNotAdded)) -{ - if (CORBA::is_nil (load_alert)) - ACE_THROW (CORBA::BAD_PARAM ()); - - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->load_alert_lock_); - - TAO_LB_LoadAlertInfo info; - info.load_alert = CosLoadBalancing::LoadAlert::_duplicate (load_alert); - - int result = this->load_alert_map_.bind (the_location, info); - - if (result == 1) - { - ACE_THROW (CosLoadBalancing::LoadAlertAlreadyPresent ()); - } - else if (result == -1) - { - // Problems dude! - ACE_THROW (CosLoadBalancing::LoadAlertNotAdded ()); - } -} - -CosLoadBalancing::LoadAlert_ptr -TAO_LB_LoadManager::get_load_alert ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertNotFound)) -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->load_alert_lock_, - CosLoadBalancing::LoadAlert::_nil ()); - - TAO_LB_LoadAlertMap::ENTRY * entry; - if (this->load_alert_map_.find (the_location, entry) == 0) - { - TAO_LB_LoadAlertInfo & info = entry->int_id_; - - return - CosLoadBalancing::LoadAlert::_duplicate (info.load_alert.in ()); - } - else - { - ACE_THROW_RETURN (CosLoadBalancing::LoadAlertNotFound (), - CosLoadBalancing::LoadAlert::_nil ()); - } -} - -void -TAO_LB_LoadManager::remove_load_alert ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertNotFound)) -{ - // Disable the "alert" status on the LoadAlert object since it will - // no longer be associated with the LoadManager. In particular, - // requests should be allowed through once again since there will be - // no way to control the load shedding mechanism once the LoadAlert - // object is no longer under the control of the LoadManager. - this->disable_alert (the_location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->load_alert_lock_); - - if (this->load_alert_map_.unbind (the_location) != 0) - { - ACE_THROW (CosLoadBalancing::LoadAlertNotFound ()); - } -} - -void -TAO_LB_LoadManager::register_load_monitor ( - const PortableGroup::Location & the_location, - CosLoadBalancing::LoadMonitor_ptr load_monitor - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::MonitorAlreadyPresent)) -{ - if (CORBA::is_nil (load_monitor)) - ACE_THROW (CORBA::BAD_PARAM ()); - - const CosLoadBalancing::LoadMonitor_var the_monitor = - CosLoadBalancing::LoadMonitor::_duplicate (load_monitor); - - ACE_GUARD (TAO_SYNCH_MUTEX, - guard, - this->monitor_lock_); - - int result = this->monitor_map_.bind (the_location, the_monitor); - - if (result == 0 - && this->monitor_map_.current_size () == 1) - { - // Register the "pull monitoring" event handler only after the - // first load monitor is registered. This is an optimization to - // prevent unnecessary invocation of the "pull monitoring" event - // handler. - ACE_Time_Value interval (TAO_LB_PULL_HANDLER_INTERVAL, 0); - ACE_Time_Value restart (TAO_LB_PULL_HANDLER_RESTART, 0); - this->timer_id_ = this->reactor_->schedule_timer (&this->pull_handler_, - 0, - interval, - restart); - - if (this->timer_id_ == -1) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "TAO_LB_LoadManager::register_load_monitor: " - "Unable to schedule timer.\n")); - - (void) this->monitor_map_.unbind (the_location); - - ACE_THROW (CORBA::INTERNAL ()); - } - } - else if (result == 1) - { - ACE_THROW (CosLoadBalancing::MonitorAlreadyPresent ()); - } - else if (result != 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "TAO_LB_LoadManager::register_load_monitor: " - "Unable to register load monitor.\n")); - - ACE_THROW (CORBA::INTERNAL ()); - } -} - -CosLoadBalancing::LoadMonitor_ptr -TAO_LB_LoadManager::get_load_monitor ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->monitor_lock_, - CosLoadBalancing::LoadMonitor::_nil ()); - - TAO_LB_MonitorMap::ENTRY * entry; - if (this->monitor_map_.find (the_location, entry) == 0) - { - return - CosLoadBalancing::LoadMonitor::_duplicate (entry->int_id_.in ()); - } - - ACE_THROW_RETURN (CosLoadBalancing::LocationNotFound (), - CosLoadBalancing::LoadMonitor::_nil ()); -} - -void -TAO_LB_LoadManager::remove_load_monitor ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, - guard, - this->monitor_lock_); - - if (this->monitor_map_.unbind (the_location) != 0) - ACE_THROW (CosLoadBalancing::LocationNotFound ()); - - // If no load monitors are registered with the load balancer than - // shutdown the "pull monitoring." - if (this->timer_id_ != -1 - && this->monitor_map_.current_size () == 0) - { - if (this->reactor_->cancel_timer (this->timer_id_) == 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "TAO_LB_LoadManager::remove_load_monitor: " - "Unable to cancel timer.\n")); - - ACE_THROW (CORBA::INTERNAL ()); - } - - this->timer_id_ = -1; - } -} - -void -TAO_LB_LoadManager::set_default_properties ( - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)) -{ - PortableGroup::Properties new_props (props); - this->preprocess_properties (new_props - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - this->property_manager_.set_default_properties (new_props - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::Properties * -TAO_LB_LoadManager::get_default_properties ( - ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return - this->property_manager_.get_default_properties ( - ACE_ENV_SINGLE_ARG_PARAMETER); -} - -void -TAO_LB_LoadManager::remove_default_properties ( - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)) -{ - this->property_manager_.remove_default_properties (props - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadManager::set_type_properties ( - const char *type_id, - const PortableGroup::Properties & overrides - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)) -{ - PortableGroup::Properties new_overrides (overrides); - this->preprocess_properties (new_overrides - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - this->property_manager_.set_type_properties (type_id, - new_overrides - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::Properties * -TAO_LB_LoadManager::get_type_properties ( - const char *type_id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return - this->property_manager_.get_type_properties (type_id - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadManager::remove_type_properties ( - const char *type_id, - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)) -{ - this->property_manager_.remove_type_properties (type_id, - props - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadManager::set_properties_dynamically ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Properties & overrides - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)) -{ - PortableGroup::Properties new_overrides (overrides); - this->preprocess_properties (new_overrides - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - this->property_manager_.set_properties_dynamically (object_group, - new_overrides - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::Properties * -TAO_LB_LoadManager::get_properties ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)) -{ - return - this->property_manager_.get_properties (object_group - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroup_ptr -TAO_LB_LoadManager::create_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location, - const char * type_id, - const PortableGroup::Criteria & the_criteria - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberAlreadyPresent, - PortableGroup::NoFactory, - PortableGroup::ObjectNotCreated, - PortableGroup::InvalidCriteria, - PortableGroup::CannotMeetCriteria)) -{ - return - this->object_group_manager_.create_member (object_group, - the_location, - type_id, - the_criteria - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroup_ptr -TAO_LB_LoadManager::add_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location, - CORBA::Object_ptr member - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberAlreadyPresent, - PortableGroup::ObjectNotAdded)) -{ - return - this->object_group_manager_.add_member (object_group, - the_location, - member - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroup_ptr -TAO_LB_LoadManager::remove_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - return - this->object_group_manager_.remove_member (object_group, - the_location - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::Locations * -TAO_LB_LoadManager::locations_of_members ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)) -{ - return - this->object_group_manager_.locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroups * -TAO_LB_LoadManager::groups_at_location ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return - this->object_group_manager_.groups_at_location (the_location - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroupId -TAO_LB_LoadManager::get_object_group_id ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)) -{ - return - this->object_group_manager_.get_object_group_id (object_group - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroup_ptr -TAO_LB_LoadManager::get_object_group_ref ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)) -{ - return - this->object_group_manager_.get_object_group_ref (object_group - ACE_ENV_ARG_PARAMETER); -} - -PortableGroup::ObjectGroup_ptr TAO_LB_LoadManager::get_object_group_ref_from_id ( - PortableGroup::ObjectGroupId group_id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC(( - CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)) -{ - return this->object_group_manager_.get_object_group_ref_from_id ( - group_id - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Object_ptr -TAO_LB_LoadManager::get_member_ref ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - return - this->object_group_manager_.get_member_ref (object_group, - the_location - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Object_ptr -TAO_LB_LoadManager::create_object ( - const char * type_id, - const PortableGroup::Criteria & the_criteria, - PortableGroup::GenericFactory::FactoryCreationId_out - factory_creation_id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::NoFactory, - PortableGroup::ObjectNotCreated, - PortableGroup::InvalidCriteria, - PortableGroup::InvalidProperty, - PortableGroup::CannotMeetCriteria)) -{ -// this->init (ACE_ENV_SINGLE_ARG_PARAMETER); -// ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - - PortableGroup::Criteria new_criteria (the_criteria); - this->preprocess_properties (new_criteria - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - CORBA::Object_ptr obj = - this->generic_factory_.create_object (type_id, - new_criteria, - factory_creation_id - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - - return obj; -} - -#if 0 -void -TAO_LB_LoadManager::process_criteria ( - const PortableGroup::Criteria & the_criteria - ACE_ENV_ARG_DECL) -{ - // List of invalid criteria. If this list has a length greater than - // zero, then the PortableGroup::InvalidCriteria exception will - // be thrown. - PortableGroup::Criteria invalid_criteria; - - int found_factory = 0; // If factory was found in the_criteria, then - // set to 1. - - // Parse the criteria. - CORBA::ULong criteria_count = the_criteria.length (); - for (CORBA::ULong i = 0; i < criteria_size; ++i) - { - CORBA::UShort initial_number_replicas = 0; - PortableGroup::FactoryInfos factory_infos; - - // Obtain the InitialNumberMembers from the_criteria. - if (this->get_initial_number_replicas (type_id, - the_criteria[i], - initial_number_replicas) != 0) - { - CORBA::ULong len = invalid_criteria.length (); - invalid_criteria.length (len + 1); - invalid_criteria[len] = the_criteria[i]; - } - - // Obtain the FactoryInfos from the_criteria. This method also - // ensures that GenericFactories at different locations are used. - else if (this->get_factory_infos (type_id, - the_criteria[i], - factory_infos) == 0) - found_factory = 1; - - // Unknown property - else - ACE_THROW (PortableGroup::InvalidProperty (the_criteria[i].nam, - the_criteria[i].val)); - } - - if (invalid_criteria.length () != 0) - ACE_THROW (PortableGroup::InvalidCriteria (invalid_criteria)); - - if (found_factory == 0) - ACE_THROW (PortableGroup::NoFactory ()); -} -#endif /* 0 */ - -void -TAO_LB_LoadManager::delete_object ( - const PortableGroup::GenericFactory::FactoryCreationId & - factory_creation_id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectNotFound)) -{ - this->generic_factory_.delete_object (factory_creation_id - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Object_ptr -TAO_LB_LoadManager::next_member (const PortableServer::ObjectId & oid - ACE_ENV_ARG_DECL) -{ - PortableGroup::ObjectGroup_var object_group = - this->object_group_manager_.object_group (oid); - - if (CORBA::is_nil (object_group.in ())) - ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), - CORBA::Object::_nil ()); - - PortableGroup::Properties_var properties = - this->get_properties (object_group.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - // Prefer custom load balancing strategies over built-in ones. - PortableGroup::Value value; - CosLoadBalancing::Strategy_ptr strategy; - - if ((TAO_PG::get_property_value (this->built_in_balancing_strategy_name_, - properties.in (), - value) - || TAO_PG::get_property_value (this->custom_balancing_strategy_name_, - properties.in (), - value)) - && (value >>= strategy) - && !CORBA::is_nil (strategy)) - { - return strategy->next_member (object_group.in (), - this->lm_ref_.in () - ACE_ENV_ARG_PARAMETER); - } - - ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), - CORBA::Object::_nil ()); -} - -void -TAO_LB_LoadManager::init (ACE_Reactor * reactor, - CORBA::ORB_ptr orb, - PortableServer::POA_ptr root_poa - ACE_ENV_ARG_DECL) -{ - ACE_ASSERT (!CORBA::is_nil (orb)); - ACE_ASSERT (!CORBA::is_nil (root_poa)); - - ACE_GUARD (TAO_SYNCH_MUTEX, - guard, - this->lock_); - - if (CORBA::is_nil (this->poa_.in ())) - { - // Create a new transient servant manager object in the child - // POA. - PortableServer::ServantManager_ptr tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_MemberLocator (this), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableServer::ServantManager_var member_locator = tmp; - - // Create the appropriate RequestProcessingPolicy - // (USE_SERVANT_MANAGER) and ServantRetentionPolicy (NON_RETAIN) - // for a ServantLocator. - PortableServer::RequestProcessingPolicy_var request = - root_poa->create_request_processing_policy ( - PortableServer::USE_SERVANT_MANAGER - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - PortableServer::ServantRetentionPolicy_var retention = - root_poa->create_servant_retention_policy ( - PortableServer::NON_RETAIN - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Create the PolicyList containing the policies necessary for - // the POA to support ServantLocators. - CORBA::PolicyList policy_list; - policy_list.length (2); - policy_list[0] = - PortableServer::RequestProcessingPolicy::_duplicate ( - request.in ()); - policy_list[1] = - PortableServer::ServantRetentionPolicy::_duplicate ( - retention.in ()); - - // Create the child POA with the above ServantManager policies. - // The ServantManager will be the MemberLocator. - PortableServer::POAManager_var poa_manager = - root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - // The child POA's name will consist of a string that includes - // the current time in milliseconds in hexidecimal format (only - // four bytes will be used). This is an attempt to prevent - // different load manager servants within the same ORB from - // using the same POA. - const ACE_Time_Value tv = ACE_OS::gettimeofday (); - const CORBA::Long time = - static_cast<CORBA::Long> (tv.msec ()); // Time in milliseconds. - - char poa_name[] = "TAO_LB_LoadManager_POA - 0xZZZZZZZZ"; - char * astr = - poa_name - + sizeof (poa_name) - - 9 /* 8 + 1 */; - - // Overwrite the last 8 characters in the POA name with the - // hexadecimal representation of the time in milliseconds. - ACE_OS::sprintf (astr, "%x", time); - - this->poa_ = root_poa->create_POA (poa_name, - poa_manager.in (), - policy_list - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - request->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - retention->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - // Now set the MemberLocator as the child POA's Servant - // Manager. - this->poa_->set_servant_manager (member_locator.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - this->object_group_manager_.poa (this->poa_.in ()); - this->generic_factory_.poa (this->poa_.in ()); - - // Activate the child POA. - poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - this->reactor_ = reactor; - this->root_poa_ = PortableServer::POA::_duplicate (root_poa); - } - - if (CORBA::is_nil (this->lm_ref_.in ())) - { - this->lm_ref_ = this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - orb->register_initial_reference ("LoadManager", - this->lm_ref_.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - - if (CORBA::is_nil (this->load_alert_handler_.in ())) - { - TAO_LB_LoadAlert_Handler * handler; - ACE_NEW_THROW_EX (handler, - TAO_LB_LoadAlert_Handler, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableServer::ServantBase_var safe_handler = handler; - - this->load_alert_handler_ = - handler->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - } - - this->built_in_balancing_strategy_info_name_.length (1); - this->built_in_balancing_strategy_info_name_[0].id = - CORBA::string_dup ("org.omg.CosLoadBalancing.StrategyInfo"); - - this->built_in_balancing_strategy_name_.length (1); - this->built_in_balancing_strategy_name_[0].id = - CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy"); - - this->custom_balancing_strategy_name_.length (1); - this->custom_balancing_strategy_name_[0].id = - CORBA::string_dup ("org.omg.CosLoadBalancing.CustomStrategy"); -} - -void -TAO_LB_LoadManager::preprocess_properties (PortableGroup::Properties & props - ACE_ENV_ARG_DECL) -{ - // @@ This is slow. Optimize this code. - - const CORBA::ULong len = props.length (); - for (CORBA::ULong i = 0; i < len; ++i) - { - PortableGroup::Property & property = props[i]; - if (property.nam == this->custom_balancing_strategy_name_) - { - CosLoadBalancing::CustomStrategy_ptr strategy; - if (!(property.val >>= strategy) - || CORBA::is_nil (strategy)) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (property.nam == this->built_in_balancing_strategy_info_name_) - { - CosLoadBalancing::StrategyInfo * info; - - if (property.val >>= info) - { - // Convert the property from a "StrategyInfo" property - // to a "Strategy" property. - - CosLoadBalancing::Strategy_var strategy = - this->make_strategy (info - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (!CORBA::is_nil (strategy.in ())) - { - property.nam = this->built_in_balancing_strategy_name_; - - property.val <<= strategy.in (); - } - else - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - else - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - else if (property.nam == this->built_in_balancing_strategy_name_) - { - // It is illegal to set the Strategy property externally. - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - } -} - -CosLoadBalancing::Strategy_ptr -TAO_LB_LoadManager::make_strategy (CosLoadBalancing::StrategyInfo * info - ACE_ENV_ARG_DECL) -{ - /** - * @todo We need a strategy factory. This is just too messy. - */ - - if (ACE_OS::strcmp (info->name.in (), "RoundRobin") == 0) - { - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CosLoadBalancing::Strategy::_nil ()); - - if (CORBA::is_nil (this->round_robin_.in ())) - { - TAO_LB_RoundRobin * rr_servant; - ACE_NEW_THROW_EX (rr_servant, - TAO_LB_RoundRobin (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = rr_servant; - - this->round_robin_ = - rr_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - } - } - - return CosLoadBalancing::Strategy::_duplicate (this->round_robin_.in ()); - } - - else if (ACE_OS::strcmp (info->name.in (), "Random") == 0) - { - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CosLoadBalancing::Strategy::_nil ()); - - if (CORBA::is_nil (this->random_.in ())) - { - TAO_LB_Random * rnd_servant; - ACE_NEW_THROW_EX (rnd_servant, - TAO_LB_Random (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = rnd_servant; - - this->random_ = - rnd_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - } - } - - return CosLoadBalancing::Strategy::_duplicate (this->random_.in ()); - } - - else if (ACE_OS::strcmp (info->name.in (), "LeastLoaded") == 0) - { - // If no LeastLoaded properties have been set, just use the - // default/cached LeastLoaded instance. Otherwise create and - // return a new LeastLoaded instance with the appropriate - // properties. - - if (info->props.length () == 0) - { - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CosLoadBalancing::Strategy::_nil ()); - - if (CORBA::is_nil (this->least_loaded_.in ())) - { - TAO_LB_LeastLoaded * ll_servant; - ACE_NEW_THROW_EX (ll_servant, - TAO_LB_LeastLoaded (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = ll_servant; - - this->least_loaded_ = - ll_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - } - } - - return - CosLoadBalancing::Strategy::_duplicate (this->least_loaded_.in ()); - } - else - { - TAO_LB_LeastLoaded * ll_servant; - ACE_NEW_THROW_EX (ll_servant, - TAO_LB_LeastLoaded (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = ll_servant; - - ll_servant->init (info->props - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - return ll_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - } - } - else if (ACE_OS::strcmp (info->name.in (), "LoadMinimum") == 0) - { - - if (info->props.length () == 0) - { - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CosLoadBalancing::Strategy::_nil ()); - - if (CORBA::is_nil (this->load_minimum_.in ())) - { - TAO_LB_LoadMinimum * lm_servant; - ACE_NEW_THROW_EX (lm_servant, - TAO_LB_LoadMinimum (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = lm_servant; - - this->load_minimum_ = - lm_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - } - } - - return - CosLoadBalancing::Strategy::_duplicate (this->load_minimum_.in ()); - } - else - { - TAO_LB_LoadMinimum * lm_servant; - ACE_NEW_THROW_EX (lm_servant, - TAO_LB_LoadMinimum (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = lm_servant; - - lm_servant->init (info->props - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - return lm_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - } - } - else if (ACE_OS::strcmp (info->name.in (), "LoadAverage") == 0) - { - - if (info->props.length () == 0) - { - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CosLoadBalancing::Strategy::_nil ()); - - if (CORBA::is_nil (this->load_average_.in ())) - { - TAO_LB_LoadAverage * la_servant; - ACE_NEW_THROW_EX (la_servant, - TAO_LB_LoadAverage (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = la_servant; - - this->load_average_ = - la_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - } - } - - return - CosLoadBalancing::Strategy::_duplicate (this->load_average_.in ()); - } - else - { - TAO_LB_LoadAverage * la_servant; - ACE_NEW_THROW_EX (la_servant, - TAO_LB_LoadAverage (this->root_poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - PortableServer::ServantBase_var s = la_servant; - - la_servant->init (info->props - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CosLoadBalancing::Strategy::_nil ()); - - return la_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - } - } - return CosLoadBalancing::Strategy::_nil (); -} - -// void -// TAO_LB_LoadManager::update_strategy () -// { -// } - -// void -// TAO_LB_LoadManager::deactivate_strategy (ACE_ENV_ARG_DECL) -// { -// PortableServer::ObjectId_var oid = -// this->poa_->reference_to_id ( -// this->poa_->deactivate_object (); -// } - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.h deleted file mode 100644 index 42ce6c006c4..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadManager.h +++ /dev/null @@ -1,519 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_LoadManager.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_LOAD_MANAGER_H -#define TAO_LB_LOAD_MANAGER_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingS.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - - -#include "orbsvcs/LoadBalancing/LB_LoadAlertMap.h" -#include "orbsvcs/LoadBalancing/LB_MonitorMap.h" -#include "orbsvcs/LoadBalancing/LB_LoadListMap.h" -#include "orbsvcs/LoadBalancing/LB_Pull_Handler.h" - -#include "orbsvcs/PortableGroupC.h" - -#include "orbsvcs/PortableGroup/PG_PropertyManager.h" -#include "orbsvcs/PortableGroup/PG_GenericFactory.h" -#include "orbsvcs/PortableGroup/PG_ObjectGroupManager.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -class TAO_LoadBalancing_Export TAO_LB_LoadManager - : public virtual POA_CosLoadBalancing::LoadManager -{ -public: - - /// Constructor. - TAO_LB_LoadManager (void); - - /** - * @name CosLoadBalancing::LoadManager Methods - * - * Methods required by the CosLoadBalancing::LoadManager interface. - */ - //@{ - - /// For the PUSH load monitoring style. - virtual void push_loads (const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Return the raw loads at the given location. - virtual CosLoadBalancing::LoadList * get_loads ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - /// Inform member at given location of load alert condition. - virtual void enable_alert (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CosLoadBalancing::LoadAlertNotFound)); - - /// Inform member at given location that load alert condition has - /// passed. - virtual void disable_alert (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CosLoadBalancing::LoadAlertNotFound)); - - /// Register a LoadAlert object for the member at the given - /// location. - virtual void register_load_alert ( - const PortableGroup::Location & the_location, - CosLoadBalancing::LoadAlert_ptr load_alert - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertAlreadyPresent, - CosLoadBalancing::LoadAlertNotAdded)); - - /// Retrieve the LoadAlert object for the member at the given - /// location. - virtual CosLoadBalancing::LoadAlert_ptr get_load_alert ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertNotFound)); - - /// Remove (de-register) the LoadAlert object for the member at the - /// given location. - virtual void remove_load_alert (const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LoadAlertNotFound)); - - /// Register a load monitor with the load balancer. - virtual void register_load_monitor ( - const PortableGroup::Location & the_location, - CosLoadBalancing::LoadMonitor_ptr load_monitor - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::MonitorAlreadyPresent)); - - /// Return a reference to the load monitor at the given location. - virtual CosLoadBalancing::LoadMonitor_ptr get_load_monitor ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - /// Remove a load monitor at the given location from the load - /// balancer. - virtual void remove_load_monitor ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - //@} - - /** - * @name PortableGroup::PropertyManager Methods - * - * Methods required by the PortableGroup::PropertyManager interface. - */ - //@{ - - /// Set the default properties to be used by all object groups. - virtual void set_default_properties ( - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)); - - /// Get the default properties used by all object groups. - virtual PortableGroup::Properties * get_default_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Remove default properties. - virtual void remove_default_properties ( - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)); - - /// Set properties associated with a given Replica type. These - /// properties override the default properties. - virtual void set_type_properties ( - const char * type_id, - const PortableGroup::Properties & overrides - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)); - - /** - * Return the properties associated with a give Replica type. These - * properties include the type-specific properties in use, in - * addition to the default properties that were not overridden. - */ - virtual PortableGroup::Properties * get_type_properties ( - const char * type_id - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Remove the given properties associated with the Replica type ID. - virtual void remove_type_properties ( - const char * type_id, - const PortableGroup::Properties & props - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)); - - /** - * Dynamically set the properties associated with a given object - * group as the load balancer and replicas are being executed. - * These properties override the type-specific and default - * properties. - */ - virtual void set_properties_dynamically ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Properties & overrides - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::InvalidProperty, - PortableGroup::UnsupportedProperty)); - - /** - * Return the properties currently in use by the given object - * group. These properties include those that were set dynamically, - * type-specific properties that weren't overridden, properties that - * were used when the Replica was created, and default properties - * that weren't overridden. - */ - virtual PortableGroup::Properties * get_properties ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)); - - //@} - - /** - * @name PortableGroup::ObjectGroupManager methods - * - * Methods required by the PortableGroup::ObjectGroupManager - * interface. - */ - //@{ - - /// Create a member using the load balancer ObjectGroupManager, and - /// add the created object to the ObjectGroup. - virtual PortableGroup::ObjectGroup_ptr create_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location, - const char * type_id, - const PortableGroup::Criteria & the_criteria - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberAlreadyPresent, - PortableGroup::NoFactory, - PortableGroup::ObjectNotCreated, - PortableGroup::InvalidCriteria, - PortableGroup::CannotMeetCriteria)); - - /// Add an existing object to the ObjectGroup. - virtual PortableGroup::ObjectGroup_ptr add_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location, - CORBA::Object_ptr member - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberAlreadyPresent, - PortableGroup::ObjectNotAdded)); - - /** - * Remove an object at a specific location from the given - * ObjectGroup. Deletion of application created objects must be - * deleted by the application. Objects created by the - * infrastructure (load balancer) will be deleted by the - * infrastructure. - */ - virtual PortableGroup::ObjectGroup_ptr remove_member ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - /// Return the locations of the members in the given ObjectGroup. - virtual PortableGroup::Locations * locations_of_members ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)); - - /// Return the locations of the members in the given ObjectGroup. - virtual PortableGroup::ObjectGroups * groups_at_location ( - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Return the ObjectGroupId for the given ObjectGroup. - virtual PortableGroup::ObjectGroupId get_object_group_id ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)); - - /// @note Does this method make sense for load balanced objects? - virtual PortableGroup::ObjectGroup_ptr get_object_group_ref ( - PortableGroup::ObjectGroup_ptr object_group - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)); - - /// TAO specific method - virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_id ( - PortableGroup::ObjectGroupId group_id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC(( - CORBA::SystemException, - PortableGroup::ObjectGroupNotFound)); - - /// Return the reference corresponding to the Replica of a given - /// ObjectGroup at the given location. - virtual CORBA::Object_ptr get_member_ref ( - PortableGroup::ObjectGroup_ptr object_group, - const PortableGroup::Location & loc - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - //@} - - /** - * @name PortableGroup::GenericFactory methods - * - * Methods required by the PortableGroup::GenericFactory interface. - */ - //@{ - - /** - * Create an object of the specified type that adheres to the - * restrictions defined by the provided Criteria. The out - * FactoryCreationId parameter may be passed to the delete_object() - * method to delete the object. - */ - virtual CORBA::Object_ptr create_object ( - const char * type_id, - const PortableGroup::Criteria & the_criteria, - PortableGroup::GenericFactory::FactoryCreationId_out - factory_creation_id - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::NoFactory, - PortableGroup::ObjectNotCreated, - PortableGroup::InvalidCriteria, - PortableGroup::InvalidProperty, - PortableGroup::CannotMeetCriteria)); - - /** - * Delete the object corresponding to the provided - * FactoryCreationId. If the object is actually an ObjectGroup, - * then all members within the ObjectGroup will be deleted. - * Afterward, the ObjectGroup itself will be deleted. - */ - virtual void delete_object ( - const PortableGroup::GenericFactory::FactoryCreationId & - factory_creation_id - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectNotFound)); - - //@} - - /// Return the next member to which client requests will be - /// forwarded. - /** - * Select the next member of the object group corresponding to the - * given ObjectId. The object group's load balancing strategy - * will be queried for that member. - */ - CORBA::Object_ptr next_member (const PortableServer::ObjectId & oid - ACE_ENV_ARG_DECL); - -public: - - /// Initialize the load balancer. This will cause a child POA to be - /// created with the appropriate policies to support ServantLocators - /// (i.e. for the MemberLocator). - void init (ACE_Reactor * reactor, - CORBA::ORB_ptr orb, - PortableServer::POA_ptr root_poa - ACE_ENV_ARG_DECL); - -protected: - - /// Destructor. - /** - * Destructor is protected to enforce correct memory management - * through reference counting. - */ - ~TAO_LB_LoadManager (void); - -private: - - /// Extract the value of the InitialNumberReplicas property from - /// the_criteria. - int get_initial_number_replicas ( - const char * type_id, - const PortableGroup::Criteria & the_criteria, - CORBA::UShort & initial_number_replicas) const; - - /// Extract the value of the Factories property from the_criteria. - /** - * This method ensures that the locations in the returned - * FactoryInfos are unique. This is necessary to ensure that only - * one replica of a given type is created by the load balancer at a - * given location. - */ - int get_factory_infos ( - const char * type_id, - const PortableGroup::Criteria & the_criteria, - PortableGroup::FactoryInfos & factory_infos) const; - - /// Preprocess Strategy or CustomStrategy properties. - /** - * This method takes care of converting StrategyInfo properties to - * Strategy properties, and verifying that CustomStrategy references - * are not nil. - */ - void preprocess_properties (PortableGroup::Properties & props - ACE_ENV_ARG_DECL); - - /// Create a built-in load balancing strategy and return a reference - /// to it. - CosLoadBalancing::Strategy_ptr make_strategy ( - CosLoadBalancing::StrategyInfo * info - ACE_ENV_ARG_DECL); - -private: - - /// Reactor used when pulling loads from registered load monitors. - ACE_Reactor * reactor_; - - /// The POA that dispatches requests to the MemberLocator. - PortableServer::POA_var poa_; - - /// The Root POA. - PortableServer::POA_var root_poa_; - - /// Mutex that provides synchronization for the LoadMonitor map. - TAO_SYNCH_MUTEX monitor_lock_; - - /// Mutex that provides synchronization for the LoadMap table. - TAO_SYNCH_MUTEX load_lock_; - - /// Mutex that provides synchronization for the LoadAlert table. - TAO_SYNCH_MUTEX load_alert_lock_; - - /// Mutex that provides synchronization for the LoadManager's - /// state. - TAO_SYNCH_MUTEX lock_; - - /// Table that maps PortableGroup::Location to load monitor at that - /// location. - TAO_LB_MonitorMap monitor_map_; - - /// Table that maps location to load list. - TAO_LB_LoadListMap load_map_; - - /// Table that maps object group and location to LoadAlert object. - TAO_LB_LoadAlertMap load_alert_map_; - - /// The ObjectGroupManager that implements the functionality - /// necessary for application-controlled object group membership. - TAO_PG_ObjectGroupManager object_group_manager_; - - /// The PropertyManager that is reponsible for parsing all criteria, - /// and keeping track of property-type_id associations. - TAO_PG_PropertyManager property_manager_; - - /// The GenericFactory responsible for creating all object groups. - TAO_PG_GenericFactory generic_factory_; - - /// The event handler that performs "pull monitoring" on all - /// registered load monitors. - TAO_LB_Pull_Handler pull_handler_; - - /// Timer ID corresponding to the timer that fires off the "pull - /// monitoring" event handler. - long timer_id_; - - /// Cached object reference that points to this servant. - CosLoadBalancing::LoadManager_var lm_ref_; - - /// Cached object reference that points to the AMI handler for all - /// LoadAlert objects. - CosLoadBalancing::AMI_LoadAlertHandler_var load_alert_handler_; - - /** - * @name Built-in load balancing strategy implementations - * - * "Built-in" load balancing strategies defined by the load - * balancing specification. - */ - //@{ - /// The "RoundRobin" load balancing strategy. - CosLoadBalancing::Strategy_var round_robin_; - - /// The "Random" load balancing strategy. - CosLoadBalancing::Strategy_var random_; - - /// The "LeastLoaded" load balancing strategy. - CosLoadBalancing::Strategy_var least_loaded_; - - /// The "LoadMinimum" load balancing strategy. - CosLoadBalancing::Strategy_var load_minimum_; - - /// The "LoadAverage" load balancing strategy. - CosLoadBalancing::Strategy_var load_average_; - //@} - - /// Cached instance of the Property name - /// "org.omg.CosLoadBalancing.StrategyInfo". - PortableGroup::Name built_in_balancing_strategy_info_name_; - - /// Cached instance of the Property name - /// "org.omg.CosLoadBalancing.Strategy". - PortableGroup::Name built_in_balancing_strategy_name_; - - /// Cached instance of the Property name - /// "org.omg.CosLoadBalancing.CustomStrategy". - PortableGroup::Name custom_balancing_strategy_name_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_MANAGER_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMap.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMap.h deleted file mode 100644 index 2e75bbba1f3..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMap.h +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_LoadMap.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_LOAD_MAP_H -#define TAO_LB_LOAD_MAP_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/PortableGroupC.h" - -#include "orbsvcs/PortableGroup/PG_Location_Hash.h" -#include "orbsvcs/PortableGroup/PG_Location_Equal_To.h" - -#include "ace/Hash_Map_Manager_T.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// Load hash map. -typedef ACE_Hash_Map_Manager_Ex< - PortableGroup::Location, - CosLoadBalancing::Load, - TAO_PG_Location_Hash, - TAO_PG_Location_Equal_To, - ACE_Null_Mutex> TAO_LB_LoadMap; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOAD_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.cpp deleted file mode 100644 index b271606a0fb..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.cpp +++ /dev/null @@ -1,664 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadMinimum.h" -#include "ace/OS_NS_sys_time.h" -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" -#include "orbsvcs/LoadBalancing/LB_Random.h" - -#include "orbsvcs/PortableGroup/PG_conf.h" - -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -#include "ace/Null_Mutex.h" -#include "ace/OS_NS_string.h" - - -ACE_RCSID (LoadBalancing, - LB_LoadMinimum, - "$Id$") - - -#if !defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LoadMinimum.inl" -#endif /* defined INLINE */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_LoadMinimum::TAO_LB_LoadMinimum (PortableServer::POA_ptr poa) - : poa_ (PortableServer::POA::_duplicate (poa)), - load_map_ (0), - lock_ (0), - properties_ (), - tolerance_ (TAO_LB::LM_DEFAULT_TOLERANCE), - dampening_ (TAO_LB::LM_DEFAULT_DAMPENING), - per_balance_load_ (TAO_LB::LM_DEFAULT_DAMPENING) -{ - // A load map that retains previous load values at a given location - // and lock are only needed if dampening is enabled, i.e. non-zero. - if (this->dampening_ != 0) - { - ACE_NEW (this->load_map_, TAO_LB_LoadMap (TAO_PG_MAX_LOCATIONS)); - - ACE_NEW (this->lock_, TAO_SYNCH_MUTEX); - } - - // Initialize the random load balancing strategy. - TAO_LB_Random::init (); -} - -TAO_LB_LoadMinimum::~TAO_LB_LoadMinimum (void) -{ - delete this->load_map_; - delete this->lock_; -} - -char * -TAO_LB_LoadMinimum::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("LoadMinimum"); -} - -CosLoadBalancing::Properties * -TAO_LB_LoadMinimum::get_properties (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Properties * props = 0; - ACE_NEW_THROW_EX (props, - CosLoadBalancing::Properties (this->properties_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - return props; -} - -void -TAO_LB_LoadMinimum::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // Only the first load is used by this load balancing strategy. - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - CosLoadBalancing::Load load; // Unused - - this->push_loads (the_location, - loads, - load - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_LoadMinimum::push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & load - ACE_ENV_ARG_DECL) -{ - if (loads.length () == 0) - ACE_THROW (CORBA::BAD_PARAM ()); - - // Only the first load is used by this load balancing strategy. - const CosLoadBalancing::Load & new_load = loads[0]; - - if (this->load_map_ != 0) - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, *this->lock_); - - TAO_LB_LoadMap::ENTRY * entry; - if (this->load_map_->find (the_location, entry) == 0) - { - CosLoadBalancing::Load & previous_load = entry->int_id_; - - if (previous_load.id != new_load.id) - ACE_THROW (CORBA::BAD_PARAM ()); // Somebody switched - // LoadIds on us! - - previous_load.value = - this->effective_load (previous_load.value, new_load.value); - - load = previous_load; - } - else - { - const CosLoadBalancing::Load eff_load = - { - new_load.id, - this->effective_load (0, new_load.value) - }; - - if (this->load_map_->bind (the_location, eff_load) != 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "ERROR: TAO_LB_LoadMinimum - " - "Unable to push loads\n")); - - ACE_THROW (CORBA::INTERNAL ()); - } - - load = eff_load; - } - } - else - { - load.id = new_load.id; - load.value = this->effective_load (0, new_load.value); - } -} - -CosLoadBalancing::LoadList * -TAO_LB_LoadMinimum::get_loads (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0); - - CosLoadBalancing::LoadList_var loads = - load_manager->get_loads (the_location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - this->push_loads (the_location, - loads.in (), - loads[0] - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return loads._retn (); -} - - -CORBA::Object_ptr -TAO_LB_LoadMinimum::next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - CORBA::Object::_nil ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (locations->length () == 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), - CORBA::Object::_nil ()); - - // @@ RACE CONDITION. OBJECT GROUP MEMBERSHIP MAY CHANGE AFTER - // RETRIEVING LOCATIONS! HOW DO WE HANDLE THAT? - - PortableGroup::Location location; - CORBA::Boolean found_location = - this->get_location (load_manager, - locations.in (), - location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (found_location) - { -/* - ACE_DEBUG ((LM_DEBUG, - "RETURNING REFERENCE FOR LOCATION \"%s\"\n", - location[0].id.in ())); -*/ - - return load_manager->get_member_ref (object_group, - location - ACE_ENV_ARG_PARAMETER); - } - else - { - // No loads have been reported for any of the locations the - // object group members reside at. If no loads have been - // reported to the LoadManager, adaptive load balancing - // decisions cannot be made. Fall back on a non-adaptive - // strategy, such as the Random load balancing strategy, - // instead. - // - // @note The Random load balancing strategy is used since it is - // very lightweight and stateless. -/* - ACE_DEBUG ((LM_DEBUG, - "CALLING RANDOM REFERENCE FOR LOCATION \n")); -*/ - - return TAO_LB_Random::_tao_next_member (object_group, - load_manager, - locations.in () - ACE_ENV_ARG_PARAMETER); - } -} - -void -TAO_LB_LoadMinimum::analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW (CORBA::BAD_PARAM ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (locations->length () == 0) - ACE_THROW (CORBA::TRANSIENT ()); - - const CORBA::ULong len = locations->length (); - - CosLoadBalancing::Load total_load = { 0, 0 }; - CosLoadBalancing::Load avg_load = { 0, 0 }; - - CORBA::Float min_load = FLT_MAX; - - CosLoadBalancing::LoadList tmp (len); - tmp.length (1); - - // Iterate through the entire location list to determine - // the average load of all the locations - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - const PortableGroup::Location & loc = locations[i]; - - // Retrieve the load list for the location from the - // LoadManager and push it to this Strategy's load - // processor. - CosLoadBalancing::LoadList_var current_loads = - load_manager->get_loads (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - CosLoadBalancing::Load load; - this->push_loads (loc, - current_loads.in (), - load - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - total_load.value = total_load.value + load.value; - tmp[i] = load; - - if ((load.value < min_load) && (load.value != 0)) - { - min_load = load.value; - } - - /* - ACE_DEBUG ((LM_DEBUG, - "TOTAL == %f\n", - total_load.value)); - */ - - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // no location found - // - } - ACE_ENDTRY; - ACE_CHECK; - } - - avg_load.value = total_load.value / len; -/* - ACE_DEBUG ((LM_DEBUG, - "AVERAGE LOAD == %f" - "\tMIN LOAD == %f\n", - avg_load.value, - min_load)); -*/ - - // Iterate through the entire location list to determine - // the location where the load has to be shed. - for (CORBA::ULong j = 0; j < len; ++j) - { - ACE_TRY_EX (SECOND) - { - const PortableGroup::Location & loc = locations[j]; - - /* - ACE_DEBUG ((LM_DEBUG, - "EFFECTIVE_LOAD == %f\n" - "AVERAGE == %f\n", - tmp[i].value, - avg_load.value)); - */ - - if (tmp[j].value <= avg_load.value) - { - load_manager->disable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (SECOND); - } - else - { - - CORBA::Float percent_diff = - (tmp[j].value / min_load) - 1; - - if (tmp[j].value == min_load) - { - percent_diff = 0; - } -/* - ACE_DEBUG ((LM_DEBUG, - "ALERT LOC == %u" - "\tMIN LOAD == %f\n" - "\tLOAD == %f\n" - "\tPERCENT == %f\n", - i, - min_load, - tmp[i].value, - percent_diff)); -*/ - - if (percent_diff <= TAO_LB::LM_DEFAULT_DIFF_AVERAGE_CUTOFF) - { - load_manager->disable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (SECOND); - } - else if ((percent_diff > TAO_LB::LM_DEFAULT_DIFF_AVERAGE_CUTOFF) - && (percent_diff < 1)) - { -/* - ACE_DEBUG ((LM_DEBUG, - "%P --- ALERTING LOCATION %u\n", - i)); -*/ - load_manager->enable_alert (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (SECOND); - } - } - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // no location found - // - } - ACE_ENDTRY; - ACE_CHECK; - } - -} - -PortableServer::POA_ptr -TAO_LB_LoadMinimum::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - -CORBA::Boolean -TAO_LB_LoadMinimum::get_location ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations, - PortableGroup::Location & location - ACE_ENV_ARG_DECL) -{ - CORBA::Float min_load = FLT_MAX; // Start out with the largest - // positive value. - - CORBA::ULong location_index = 0; - CORBA::Boolean found_location = 0; - CORBA::Boolean found_load = 0; - - const CORBA::ULong len = locations.length (); - - // Iterate through the entire location list to find the least loaded - // of them. - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - const PortableGroup::Location & loc = locations[i]; - - // Retrieve the load list for the location from the LoadManager - // and push it to this Strategy's load processor. - CosLoadBalancing::LoadList_var current_loads = - load_manager->get_loads (loc - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - found_load = 1; - - CosLoadBalancing::Load load; - this->push_loads (loc, - current_loads.in (), - load - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -/* - ACE_DEBUG ((LM_DEBUG, - "LOC == %u" - "\tMIN LOAD == %f\n" - "\tLOAD == %f\n", - i, - min_load, - load.value)); -*/ - if (load.value < min_load) - { - - if (i > 0 && load.value != 0) - { - /* - percent difference = - (min_load - load.value) / load.value - == (min_load / load.value) - 1 - - The latter form is used to avoid a potential - arithmetic overflow problem, such as when - (min_load - load.value) > FLT_MAX, assuming that - either load.value is negative and min_load is - positive, or vice versa. - */ - const CORBA::Float percent_diff = - (min_load / load.value) - 1; - /* - A "thundering herd" phenomenon may occur when - location loads are basically the same (e.g. only - differ by a very small amount), where one object - group member ends up receiving the majority of - requests from different clients. In order to - prevent a single object group member from - receiving such request bursts, one of two equally - loaded locations is chosen at random. Thanks to - Carlos, Marina and Jody at ATD for coming up with - this solution to this form of the thundering herd - problem. - - See the documentation for - TAO_LB::LL_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF in - LB_LoadMinimum.h for additional information. - */ - if (percent_diff <= TAO_LB::LM_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF) - { - // Prevent integer arithmetic overflow. - const CORBA::Float NUM_MEMBERS = 2; - - // n == 0: Use previously selected location. - // n == 1: Use current location. - const CORBA::ULong n = - static_cast<CORBA::ULong> (NUM_MEMBERS * ACE_OS::rand () - / (RAND_MAX + 1.0)); - - ACE_ASSERT (n == 0 || n == 1); - - if (n == 1) - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "** NEW MIN_LOAD == %f\n", -// min_load)); - } - -// if (n == 0) -// ACE_DEBUG ((LM_DEBUG, "^^^^^ PREVIOUS LOCATION\n")); -// else -// ACE_DEBUG ((LM_DEBUG, "^^^^^ CURRENT LOCATION\n")); - - } - else - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "***** NEW MIN_LOAD == %f\n", -// min_load)); - } - } - else - { - min_load = load.value; - location_index = i; - found_location = 1; - -// ACE_DEBUG ((LM_DEBUG, -// "NEW MIN_LOAD == %f\n", -// min_load)); - } - } - - // ACE_DEBUG ((LM_DEBUG, "NEW MIN_LOAD == %f\n", min_load)); - } - ACE_CATCH (CosLoadBalancing::LocationNotFound, ex) - { - // No load available for the requested location. Try the - // next location. - } - ACE_ENDTRY; - ACE_CHECK_RETURN (0); - } - -// ACE_DEBUG ((LM_DEBUG, -// "FOUND_LOAD == %u\n" -// "FOUND_LOCATION == %u\n", -// found_load, -// found_location)); - - // If no loads were found, return without an exception to allow this - // strategy to select a member using an alternative method - // (e.g. random selection). - if (found_load) - { - if (found_location) - { - location = locations[location_index]; - //ACE_DEBUG ((LM_DEBUG, "LOCATED = %u\n", location_index)); - } - } - - //ACE_DEBUG ((LM_DEBUG, "LOCATED = %u\n", location_index)); - - return found_location; -} - -void -TAO_LB_LoadMinimum::init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL) -{ - CORBA::Float tolerance = TAO_LB::LM_DEFAULT_TOLERANCE; - CORBA::Float dampening = TAO_LB::LM_DEFAULT_DAMPENING; - CORBA::Float per_balance_load = TAO_LB::LM_DEFAULT_PER_BALANCE_LOAD; - - const CORBA::ULong len = props.length (); - for (CORBA::ULong i = 0; i < len; ++i) - { - const PortableGroup::Property & property = props[i]; - if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadMinimum.Tolerance") == 0) - { - this->extract_float_property (property, - tolerance - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Valid tolerance values are greater than or equal to one. - if (tolerance < 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadMinimum.Dampening") == 0) - { - this->extract_float_property (property, - dampening - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Dampening range is [0,1). - if (dampening < 0 || dampening >= 1) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); - } - - else if (ACE_OS::strcmp (property.nam[0].id.in (), - "org.omg.CosLoadBalancing.Strategy.LoadMinimum.PerBalanceLoad") == 0) - { - this->extract_float_property (property, - per_balance_load - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - } - - this->properties_ = props; - - this->tolerance_ = tolerance; - this->dampening_ = dampening; - this->per_balance_load_ = per_balance_load; - - /* - ACE_DEBUG ((LM_DEBUG, - "--------------------------------\n" - "tolerance = %f\n" - "dampening = %f\n" - "per_balance_load = %f\n" - "--------------------------------\n", - tolerance, - dampening, - per_balance_load)); - */ -} - -void -TAO_LB_LoadMinimum::extract_float_property ( - const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL) -{ - if (!(property.val >>= value)) - ACE_THROW (PortableGroup::InvalidProperty (property.nam, - property.val)); -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.h deleted file mode 100644 index c979845aa0c..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.h +++ /dev/null @@ -1,208 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_LoadMinimum.h - * - * $Id$ - * - * @author Jaiganesh Balasubramanian <jai@dre.vanderbilt.edu> - * Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef LB_LOAD_MINIMUM_H -#define LB_LOAD_MINIMUM_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LB_LoadMap.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/CosLoadBalancingS.h" - -#include "ace/Synch_Traits.h" -#include "ace/Thread_Mutex.h" - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -namespace TAO_LB -{ - /** - * @name Default LoadMinimum strategy parameters. - * - * Defaults defined by the Load Balancing specification. - */ - //@{ - const CORBA::Float LM_DEFAULT_TOLERANCE = 1; - const CORBA::Float LM_DEFAULT_DAMPENING = 0; - const CORBA::Float LM_DEFAULT_PER_BALANCE_LOAD = 0; - //@} - - /** - * @name TAO-specific LoadMinimum strategy parameters. - * - * Parameters internal to TAO's LoadMinimum strategy - * implementation. - */ - //@{ - /// Percentage difference between two load values that determines - /// whether the loads are considered equivalent. - /** - * If the percent difference between two loads, i.e.: - * (Old Load - New Load) / New Load - * is less than or equal to this value, the two loads will be - * considered equivalent. In such a case, an object group member - * residing at the location corresponding to one of the two loads - * will be selected at random. - */ - const CORBA::Float LM_DEFAULT_LOAD_PERCENT_DIFF_CUTOFF = 0.05f; // 1% - const CORBA::Float LM_DEFAULT_DIFF_AVERAGE_CUTOFF = 0.4f; // 80% - //@} -} - -/** - * @class TAO_LB_LoadMinimum - * - * @brief "Least loaded" load balancing strategy - * - * This load balancing strategy is designed to select an object group - * member residing at a location with the smallest load. - */ -class TAO_LB_LoadMinimum - : public virtual POA_CosLoadBalancing::Strategy -{ -public: - - /// Constructor. - TAO_LB_LoadMinimum (PortableServer::POA_ptr poa); - - /** - * @name CosLoadBalancing::Strategy methods - * - * Methods required by the CosLoadBalancing::Strategy interface. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::Properties * get_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::LoadList * get_loads ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - virtual CORBA::Object_ptr next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - virtual void analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - /// Returns the default POA for this servant. - virtual PortableServer::POA_ptr _default_POA ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS - ); - - /// Initialize the LoadMinimum instance with the given properties. - void init (const PortableGroup::Properties & props - ACE_ENV_ARG_DECL); - -protected: - - /// Destructor. - ~TAO_LB_LoadMinimum (void); - - /// Retrieve the least loaded location from the given list of - /// locations. - CORBA::Boolean get_location (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations, - PortableGroup::Location & location - ACE_ENV_ARG_DECL); - - /// Return the effective load. - CORBA::Float effective_load (CORBA::Float previous_load, - CORBA::Float new_load); - - /// Push the new load into this Strategy's load processor, and - /// return the corresponding effective load. - void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads, - CosLoadBalancing::Load & effective_load - ACE_ENV_ARG_DECL); - - /// Utility method to extract a CORBA::Float value from the given - /// property. - void extract_float_property (const PortableGroup::Property & property, - CORBA::Float & value - ACE_ENV_ARG_DECL); - -private: - - /// This servant's default POA. - PortableServer::POA_var poa_; - - /// Table that maps location to load list. - TAO_LB_LoadMap * load_map_; - - /// Lock used to ensure atomic access to state retained by this - /// class. - TAO_SYNCH_MUTEX * lock_; - - /// Cached set of properties used when initializing this strategy. - CosLoadBalancing::Properties properties_; - - /** - * @name LoadMinimum Property Values - * - * Cached LoadMinimum load balancing strategy property values. - */ - //@{ - - /// - CORBA::Float tolerance_; - - /// - CORBA::Float dampening_; - - /// - CORBA::Float per_balance_load_; - - //@} - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined (__ACE_INLINE__) -#include "orbsvcs/LoadBalancing/LB_LoadMinimum.inl" -#endif /* defined INLINE */ - -#include /**/ "ace/post.h" - -#endif /* LB_LOAD_MINIMUM_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.inl b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.inl deleted file mode 100644 index dc120b38783..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_LoadMinimum.inl +++ /dev/null @@ -1,26 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -ACE_INLINE CORBA::Float -TAO_LB_LoadMinimum::effective_load (CORBA::Float previous_load, - CORBA::Float new_load) -{ - // Apply per-balance load. (Recompute raw load) - previous_load += this->per_balance_load_; - - // Apply dampening. (Recompute new raw load) - CORBA::Float result = - this->dampening_ * previous_load + (1 - this->dampening_) * new_load; - - ACE_ASSERT (this->tolerance_ != 0); - - // Compute the effective load. - result /= this->tolerance_; - - return result; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Location_Index_Map.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Location_Index_Map.h deleted file mode 100644 index a08694dd2d0..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Location_Index_Map.h +++ /dev/null @@ -1,44 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_Location_Index_Map.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_LOCATION_INDEX_MAP_H -#define TAO_LB_LOCATION_INDEX_MAP_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/PortableGroupC.h" - -#include "ace/Functor.h" -#include "ace/Hash_Map_Manager_T.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// Location index map. -typedef ACE_Hash_Map_Manager_Ex< - PortableGroup::ObjectGroupId, - CORBA::ULong, - ACE_Hash<ACE_UINT64>, - ACE_Equal_To<ACE_UINT64>, - ACE_Null_Mutex> TAO_LB_Location_Index_Map; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_LOCATION_INDEX_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.cpp deleted file mode 100644 index 31c4e10977e..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_LoadManager.h" -#include "orbsvcs/LoadBalancing/LB_MemberLocator.h" - -#include "tao/debug.h" - - -ACE_RCSID (LoadBalancing, - LB_MemberLocator, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_MemberLocator::TAO_LB_MemberLocator ( - TAO_LB_LoadManager * lm) - : load_manager_ (lm) -{ - ACE_ASSERT (lm != 0); -} - -PortableServer::Servant -TAO_LB_MemberLocator::preinvoke ( - const PortableServer::ObjectId & oid, - PortableServer::POA_ptr /* adapter */, - const char * /* operation */, - PortableServer::ServantLocator::Cookie & /* the_cookie */ - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableServer::ForwardRequest)) -{ - ACE_TRY - { - CORBA::Object_var member = - this->load_manager_->next_member (oid - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - -// ACE_DEBUG ((LM_DEBUG, "%N:%l\n")); -// ACE_DEBUG ((LM_DEBUG, -// "FORWARDED\n")); - - ACE_ASSERT (!CORBA::is_nil (member.in ())); - // Throw a forward exception to force the client to redirect its - // requests to the member chosen by the LoadBalancer. - ACE_TRY_THROW (PortableServer::ForwardRequest (member.in ())); - } - ACE_CATCH (PortableGroup::ObjectGroupNotFound, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "LoadManager::next_member()"); - } - ACE_CATCH (PortableGroup::MemberNotFound, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "LoadManager::next_member()"); - } - ACE_ENDTRY; - ACE_CHECK_RETURN (0); - - ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (), 0); -} - -void -TAO_LB_MemberLocator::postinvoke ( - const PortableServer::ObjectId & /* oid */, - PortableServer::POA_ptr /* adapter */, - const char * /* operation */, - PortableServer::ServantLocator::Cookie /* the_cookie */, - PortableServer::Servant /* the_servant */ - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.h deleted file mode 100644 index e376937f0a5..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MemberLocator.h +++ /dev/null @@ -1,92 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_MemberLocator.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_MEMBER_LOCATOR_H -#define TAO_LB_MEMBER_LOCATOR_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/PortableServer/ServantLocatorC.h" -#include "tao/LocalObject.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -// Forward declarations. -class TAO_LB_LoadManager; - -/** - * @class TAO_LB_MemberLocator - * - * @brief ServantLocator implementation for the Load Balancer. - * - * This is a Servant Locator implementation that forwards requests to - * a member returned by the Load Balancer. - */ -class TAO_LB_MemberLocator - : public virtual PortableServer::ServantLocator, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /// Constructor - TAO_LB_MemberLocator (TAO_LB_LoadManager * load_balancer); - - /** - * @name The PortableServer::ServantLocator methods. - * - * Methods required by the PortableServer::ServantLocator - * interface. - */ - //@{ - - /// Clients requests are forwarded via the - /// PortableServer::ForwardRequest exception thrown in this method. - virtual PortableServer::Servant preinvoke ( - const PortableServer::ObjectId & oid, - PortableServer::POA_ptr adapter, - const char * operation, - PortableServer::ServantLocator::Cookie & the_cookie - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableServer::ForwardRequest)); - - /// This method is no-op in this ServantLocator implementation. - virtual void postinvoke ( - const PortableServer::ObjectId &oid, - PortableServer::POA_ptr adapter, - const char * operation, - PortableServer::ServantLocator::Cookie the_cookie, - PortableServer::Servant the_servant - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - - //@} - -private: - - /// The load balancer/manager implementation. - TAO_LB_LoadManager * load_manager_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_MEMBER_LOCATOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MonitorMap.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MonitorMap.h deleted file mode 100644 index 02b8f12adeb..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_MonitorMap.h +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_MonitorMap.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_MONITOR_MAP_H -#define TAO_LB_MONITOR_MAP_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/PortableGroup/PG_Location_Hash.h" -#include "orbsvcs/PortableGroup/PG_Location_Equal_To.h" - -#include "ace/Hash_Map_Manager_T.h" - - -/// Load monitor hash map. -typedef ACE_Hash_Map_Manager_Ex< - PortableGroup::Location, - CosLoadBalancing::LoadMonitor_var, - TAO_PG_Location_Hash, - TAO_PG_Location_Equal_To, - ACE_Null_Mutex> TAO_LB_MonitorMap; - - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_MONITOR_MAP_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.cpp deleted file mode 100644 index e7e7eeb4443..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ORBInitializer.h" -#include "orbsvcs/LoadBalancing/LB_IORInterceptor.h" -#include "orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.h" - -#include "orbsvcs/CosLoadBalancingC.h" - -#include "tao/ORB_Constants.h" - -ACE_RCSID (LoadBalancing, - LB_ORBInitializer, - "$Id$") - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_ORBInitializer::TAO_LB_ORBInitializer ( - const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location) - : object_groups_ (object_groups), - repository_ids_ (repository_ids), - location_ (location), - load_alert_ () -{ -} - -void -TAO_LB_ORBInitializer::pre_init ( - PortableInterceptor::ORBInitInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ORBInitializer::post_init ( - PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CORBA::Object_var obj = - info->resolve_initial_references ("LoadManager" - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - CosLoadBalancing::LoadManager_var lm = - CosLoadBalancing::LoadManager::_narrow (obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - CORBA::String_var orbid = info->orb_id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - PortableInterceptor::IORInterceptor_ptr tmp; - ACE_NEW_THROW_EX (tmp, - TAO_LB_IORInterceptor (this->object_groups_, - this->repository_ids_, - this->location_.in (), - lm.in (), - orbid.in (), - this->load_alert_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableInterceptor::IORInterceptor_var ior_interceptor = tmp; - - info->add_ior_interceptor (ior_interceptor.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // ---------------- - - PortableInterceptor::ServerRequestInterceptor_ptr sri; - ACE_NEW_THROW_EX (sri, - TAO_LB_ServerRequestInterceptor (this->load_alert_), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK; - - PortableInterceptor::ServerRequestInterceptor_var sr_interceptor = sri; - - info->add_server_request_interceptor (sr_interceptor.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.h deleted file mode 100644 index 292e36558ab..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ORBInitializer.h +++ /dev/null @@ -1,110 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ORBInitializer.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_ORB_INITIALIZER_H -#define TAO_LB_ORB_INITIALIZER_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LoadBalancing/LB_LoadAlert.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/PI/PI.h" -#include "tao/LocalObject.h" -#include "tao/Versioned_Namespace.h" - -// This is to remove "inherits via dominance" warnings from MSVC. -// MSVC is being a little too paranoid. -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_ORBInitializer - * - * @brief ORBInitializer for the LB_Component Service_Object. - * - * This ORBInitializer simply creates and registers with the ORB the - * IORInterceptor that handles transparent object group member - * registration with the LoadManager, and registration of the - * LoadAlert object necessary for load shedding. - * - * @par - * - * It also creates and registers the ServerRequestInterceptor that - * facilitates load shedding. - */ -class TAO_LB_ORBInitializer - : public virtual PortableInterceptor::ORBInitializer, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /// Constructor. - TAO_LB_ORBInitializer (const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location); - - /** - * @name PortableInterceptor::ORBInitializer Methods - * - * Methods required by the PortableInterceptor::ORBInitializer - * interface. - */ - //@{ - virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - -private: - - /// List of stringified object group references. - const CORBA::StringSeq object_groups_; - - /// List of RepositoryIds for object that will be load - /// managed/balanced. - const CORBA::StringSeq repository_ids_; - - /// Location at which the LoadBalancing component resides. - CORBA::String_var location_; - - /// The CosLoadBalancing::LoadAlert servant to be used at this - /// location. - /** - * This is the servant supplied by TAO's Load Balancer. It is - * used out of convencience. - */ - TAO_LB_LoadAlert load_alert_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_ORB_INITIALIZER_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.cpp deleted file mode 100644 index d70b23fa4f1..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h" - -ACE_RCSID (LoadBalancing, - LB_ObjectReferenceFactory, - "$Id$") - -#include "tao/debug.h" - -#include "ace/SString.h" -#include "ace/OS_NS_strings.h" -#include "ace/OS_NS_string.h" - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -// The number of different object groups to support. -#ifndef TAO_LB_ORF_GROUP_TABLE_SIZE -const size_t TAO_LB_ORF_GROUP_TABLE_SIZE = 16; -#endif /* TAO_LB_ORF_GROUP_TABLE_SIZE */ - -TAO_LB_ObjectReferenceFactory::TAO_LB_ObjectReferenceFactory ( - PortableInterceptor::ObjectReferenceFactory * old_orf, - const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location, - CORBA::ORB_ptr orb, - CosLoadBalancing::LoadManager_ptr lm) - : old_orf_ (old_orf), - object_groups_ (object_groups), - repository_ids_ (repository_ids), - location_ (1), - table_ (TAO_LB_ORF_GROUP_TABLE_SIZE), - fcids_ (), - orb_ (CORBA::ORB::_duplicate (orb)), - lm_ (CosLoadBalancing::LoadManager::_duplicate (lm)), - registered_members_ (0) -{ - // Claim ownership of the old ObjectReferenceFactory. - CORBA::add_ref (old_orf); - - this->location_.length (1); - this->location_[0].id = CORBA::string_dup (location); - - const CORBA::ULong len = repository_ids.length (); - ACE_NEW (this->registered_members_, - CORBA::Boolean[len]); - - ACE_ASSERT (this->registered_members_ != 0); - ACE_OS::memset (this->registered_members_, - 0, - len * sizeof (CORBA::Boolean)); -} - -TAO_LB_ObjectReferenceFactory::~TAO_LB_ObjectReferenceFactory (void) -{ - // No need to call CORBA::remove_ref() on this->old_orf_. It is a - // "_var" object, meaning that will be done automatically. - - ACE_DECLARE_NEW_CORBA_ENV; - - if (!CORBA::is_nil (this->lm_.in ())) - { - const CORBA::ULong len = this->fcids_.size (); - for (CORBA::ULong i = 0; i < len; ++i) - { - ACE_TRY - { - // Clean up all object groups we created. - this->lm_->delete_object (this->fcids_[i].in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - // Ignore all exceptions. - } - ACE_ENDTRY; - } - } - - // @todo De-register LoadAlert objects. - // @todo De-register object group members. - - delete [] this->registered_members_; -} - -CORBA::Object_ptr -TAO_LB_ObjectReferenceFactory::make_object ( - const char * repository_id, - const PortableInterceptor::ObjectId & id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - if (repository_id == 0) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), CORBA::Object::_nil ()); - - CORBA::Object_var obj = - this->old_orf_->make_object (repository_id, - id - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - PortableGroup::ObjectGroup_var object_group; - - CORBA::ULong index = 0; - - const CORBA::Boolean found_group = - this->find_object_group (repository_id, - index, - object_group.out () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - if (found_group) - { - // Be careful not to attempt duplicate registrations on - // subsequent object reference creation calls. - if (!this->registered_members_[index]) - { - ACE_TRY - { - object_group = - this->lm_->add_member (object_group.in (), - this->location_, - obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCH (PortableGroup::ObjectGroupNotFound, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "TAO_LB_ObjectReferenceFactory::" - "make_object"); - - ACE_THROW_RETURN (CORBA::BAD_PARAM (), - CORBA::Object::_nil ()); - } - ACE_CATCH (PortableGroup::MemberAlreadyPresent, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "TAO_LB_ObjectReferenceFactory::" - "make_object"); - - ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (), - CORBA::Object::_nil ()); - - } - ACE_CATCH (PortableGroup::ObjectNotAdded, ex) - { - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ex, - "TAO_LB_ObjectReferenceFactory::" - "make_object"); - - ACE_THROW_RETURN (CORBA::UNKNOWN (), - CORBA::Object::_nil ()); - } - ACE_ENDTRY; - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - this->registered_members_[index] = 1; - } - - // Return the object group reference instead. - return object_group._retn (); - } - - // Not a load managed object. Simply return the object's actual - // object reference. - return obj._retn (); -} - -CORBA::Boolean -TAO_LB_ObjectReferenceFactory::find_object_group ( - const char * repository_id, - CORBA::ULong & index, - PortableGroup::ObjectGroup_out object_group - ACE_ENV_ARG_DECL) -{ - if (!this->load_managed_object (repository_id, index)) - return 0; - - PortableGroup::ObjectGroup_var group; - if (this->table_.find (repository_id, group) != 0) - { - if (ACE_OS::strcasecmp (this->object_groups_[index], - "CREATE") == 0) - { - PortableGroup::Criteria criteria (1); - criteria.length (1); - - PortableGroup::Property & property = criteria[0]; - property.nam.length (1); - - property.nam[0].id = - CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle"); - - // Configure for application-controlled membership. - PortableGroup::MembershipStyleValue msv = - PortableGroup::MEMB_APP_CTRL; - property.val <<= msv; - - PortableGroup::GenericFactory::FactoryCreationId_var fcid; - - group = - this->lm_->create_object (repository_id, - criteria, - fcid.out () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - const CORBA::ULong len = this->fcids_.size (); - this->fcids_.size (len + 1); // Incremental growth. Yuck! - this->fcids_[len] = fcid; - } - else - { - group = - this->orb_->string_to_object (this->object_groups_[index] - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - } - - if (this->table_.bind (repository_id, group) != 0) - { - if (TAO_debug_level > 0) - ACE_ERROR ((LM_ERROR, - "TAO_LB_ObjectReferenceFactory::" - "find_object_group - " - "Couldn't bind object group reference.\n")); - - ACE_THROW_RETURN (CORBA::INTERNAL (), 0); - } - - object_group = group._retn (); - } - - return 1; -} - -CORBA::Boolean -TAO_LB_ObjectReferenceFactory::load_managed_object (const char * repository_id, - CORBA::ULong & i) -{ - // @todo Make this more efficient. - - const CORBA::ULong len = this->repository_ids_.length (); - for (i = 0; i < len; ++i) - if (ACE_OS::strcmp (this->repository_ids_[i], repository_id) == 0) - return 1; - - return 0; -} - - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h deleted file mode 100644 index 81fddbe05bf..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h +++ /dev/null @@ -1,179 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ObjectReferenceFactory.h - * - * $Id$ - - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - -#ifndef TAO_LB_OBJECT_REFERENCE_FACTORY_H -#define TAO_LB_OBJECT_REFERENCE_FACTORY_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/LB_ORTC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -#include "orbsvcs/CosLoadBalancingC.h" - -#include "ace/Array_Base.h" -#include "ace/Hash_Map_Manager_T.h" -#include "ace/Null_Mutex.h" -#include "ace/SString.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_ObjectReferenceFactory - * - * @brief Implementation of the PortableInterceptor::ObjectReferenceFactory - * interface. - * - * This ObjectReferenceFactory creates an object group for a member of - * the given repository ID (if instructed to do so), creates an - * "unpublished" reference for that member, and adds it to the object - * group via the LoadManager. - */ -class TAO_LB_ObjectReferenceFactory - : public virtual CORBA::DefaultValueRefCountBase - , public virtual OBV_TAO_LB::ObjectReferenceFactory -{ - public: - - /// Constructor - TAO_LB_ObjectReferenceFactory ( - PortableInterceptor::ObjectReferenceFactory * old_orf, - const CORBA::StringSeq & object_groups, - const CORBA::StringSeq & repository_ids, - const char * location, - CORBA::ORB_ptr orb, - CosLoadBalancing::LoadManager_ptr lm); - - /** - * @name PortableInterceptor::ObjectReferenceFactory Methods - * - * Methods required by the - * PortableInterceptor::ObjectReferenceFactory interface. - */ - //@{ - virtual CORBA::Object_ptr make_object ( - const char * repository_id, - const PortableInterceptor::ObjectId & id - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - - typedef ACE_Hash_Map_Manager_Ex< - ACE_CString, - PortableGroup::ObjectGroup_var, - ACE_Hash<ACE_CString>, - ACE_Equal_To<ACE_CString>, - ACE_Null_Mutex> Table; - - typedef ACE_Array_Base< - PortableGroup::GenericFactory::FactoryCreationId_var> fcid_list; - -protected: - - /// Destructor - /** - * Protected destructor to enforce proper memory management via - * reference counting. - */ - ~TAO_LB_ObjectReferenceFactory (void); - - /// Retrieve the object group reference for objects with the given - /// RepositoryId. - CORBA::Boolean find_object_group (const char * repository_id, - CORBA::ULong & index, - PortableGroup::ObjectGroup_out object_group - ACE_ENV_ARG_DECL); - - /// Determine if object with given RepositoryId is load managed. - CORBA::Boolean load_managed_object (const char * repository_id, - CORBA::ULong & i); - -private: - - /// The old ObjectReferenceFactory used to create object references. - /** - * This ObjectReferenceFactory will be used when creating object - * references for non-load balanced objects. - */ - PortableInterceptor::ObjectReferenceFactory_var old_orf_; - - - /// List of stringified object group references. - /** - * All stringified object groups in this sequence have a one-to-one - * correspondence to the repository IDs found in the repository_ids_ - * member below. - * - * @par - * - * The special string "CREATE" denotes that creation of a new object - * group should be performed. - */ - const CORBA::StringSeq object_groups_; - - /// List of RepositoryIds for object that will be load - /// managed/balanced. - /** - * All RepositoryIds in this sequence have a one-to-one - * correspondence to the stringified object references found in the - * object_groups_ member above. - */ - const CORBA::StringSeq repository_ids_; - - /// The configured location for the server within which this - /// ObjectReferenceFactory resides. - PortableGroup::Location location_; - - /// Table that maps repository ID to (non-stringified) object group - /// reference. - Table table_; - - /// List of FactoryCreationIds that will later be used to destroy - /// object groups. - fcid_list fcids_; - - /// Pseudo-reference to the ORB. - CORBA::ORB_var orb_; - - /// Reference to the LoadManager object. - CosLoadBalancing::LoadManager_var lm_; - - /// Array of flags that denotes whether or not an object group - /// member of a given RepositoryId has been registered with the - /// LoadManager. - /** - * The values are cached here to avoid querying the LoadManager, - * which can be costly. - */ - CORBA::Boolean * registered_members_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - - -#if defined (_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_OBJECT_REFERENCE_FACTORY_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.cpp deleted file mode 100644 index 5e8cdf226ec..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_Pull_Handler.h" -#include "orbsvcs/LoadBalancing/LB_LoadManager.h" - -#include "tao/debug.h" - - -ACE_RCSID (LoadBalancing, - LB_Pull_Handler, - "$Id$") - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_Pull_Handler::TAO_LB_Pull_Handler (void) - : monitor_map_ (0), - load_manager_ (0) -{ -} - -void -TAO_LB_Pull_Handler::initialize (TAO_LB_MonitorMap * monitor_map, - TAO_LB_LoadManager * load_manager) -{ - this->monitor_map_ = monitor_map; - this->load_manager_ = load_manager; -} - -int -TAO_LB_Pull_Handler::handle_timeout ( - const ACE_Time_Value & /* current_time */, - const void * /* arg */) -{ - // @todo Fix the race condtions in this method. - - TAO_LB_MonitorMap::iterator begin = this->monitor_map_->begin (); - TAO_LB_MonitorMap::iterator end = this->monitor_map_->end (); - - if (begin == end) - return 0; // No work to be done. - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Iterate over all registered load monitors. - // - // @todo This could be potentially very slow. Improve concurrent - // operation at some point in the near future. - for (TAO_LB_MonitorMap::iterator i = begin; i != end; ++i) - { - const PortableGroup::Location & location = (*i).ext_id_; - CosLoadBalancing::LoadMonitor_var & monitor = (*i).int_id_; - - // The load monitor reference should never be nil since the - // LoadManager prevents nil load monitor references from - // being registered. - CosLoadBalancing::LoadList_var load_list = - monitor->loads (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - this->load_manager_->push_loads (location, - load_list.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - -// ACE_DEBUG ((LM_DEBUG, -// "LOCATION = %s\tLOAD = %f\n", -// location[0].id.in (), -// load_list[0].value)); - } - } - ACE_CATCHANY - { - // Catch the exception and ignore it. - - if (TAO_debug_level > 0) - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "(%P|%t) PullHandler::handle_timeout()\n"); - } - ACE_ENDTRY; - - return 0; -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.h deleted file mode 100644 index a18efd9d961..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- - -//======================================================================= -/** - * @file LB_Pull_Handler.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//======================================================================= - - -#ifndef TAO_LB_PULL_HANDLER_H -#define TAO_LB_PULL_HANDLER_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/LoadBalancing/LB_MonitorMap.h" - -#include "ace/Event_Handler.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/// Forward declarations. -class TAO_LB_LoadManager; - -/** - * @class TAO_LB_Pull_Handler - * - * @brief Event handler used when the "pull" monitoring style is - * configured. - * - * An event handler designed to pull loads from all load monitors - * registered with the load balancer. - */ -class TAO_LB_Pull_Handler : public ACE_Event_Handler -{ -public: - - /// Constructor - TAO_LB_Pull_Handler (void); - - /// Receive the timeout event. - virtual int handle_timeout (const ACE_Time_Value ¤t_time, - const void *arg); - - /// Initialize this event handler. - void initialize (TAO_LB_MonitorMap * monitor_map, - TAO_LB_LoadManager * load_manager); - -private: - - /// The table that contains all load monitors registered with the - /// load balancer. - TAO_LB_MonitorMap * monitor_map_; - - /// Pointer to the LoadManager servant. - TAO_LB_LoadManager * load_manager_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_PULL_HANDLER_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.cpp deleted file mode 100644 index 56c39655f2d..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// -*- C++ -*- - -#include "orbsvcs/LoadBalancing/LB_Random.h" - -#include "tao/ORB_Constants.h" -#include "ace/OS_NS_time.h" -#include "ace/os_include/os_netdb.h" - -ACE_RCSID (LoadBalancing, - LB_Random, - "$Id$") - -#ifdef ACE_HAS_PTHREADS_STD -static pthread_once_t tao_lb_once_control = PTHREAD_ONCE_INIT; -#endif /* ACE_HAS_PTHREADS_STD */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -extern "C" void tao_lb_random_init_routine (void) -{ - ACE_OS::srand (static_cast<unsigned int> (ACE_OS::time ())); -} - -TAO_LB_Random::TAO_LB_Random (PortableServer::POA_ptr poa) - : poa_ (PortableServer::POA::_duplicate (poa)) -{ - TAO_LB_Random::init (); -} - -char * -TAO_LB_Random::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("Random"); -} - -CosLoadBalancing::Properties * -TAO_LB_Random::get_properties (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - CosLoadBalancing::Properties * props = 0; - ACE_NEW_THROW_EX (props, - CosLoadBalancing::Properties, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (props); - - return props; -} - -void -TAO_LB_Random::push_loads ( - const PortableGroup::Location & /* the_location */, - const CosLoadBalancing::LoadList & /* loads */ - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::StrategyNotAdaptive)) -{ - ACE_THROW (CosLoadBalancing::StrategyNotAdaptive ()); -} - -CosLoadBalancing::LoadList * -TAO_LB_Random::get_loads (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0); - - return load_manager->get_loads (the_location - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Object_ptr -TAO_LB_Random::next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), CORBA::Object::_nil ()); - - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - return TAO_LB_Random::_tao_next_member (object_group, - load_manager, - locations.in () - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_Random::analyze_loads ( - PortableGroup::ObjectGroup_ptr /* object_group */, - CosLoadBalancing::LoadManager_ptr /* load_manager */ - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -PortableServer::POA_ptr -TAO_LB_Random::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - -CORBA::Object_ptr -TAO_LB_Random::_tao_next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - const CORBA::ULong len = locations.length (); - if (len == 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), - CORBA::Object::_nil ()); - - // Pick a random location in the sequence using the higher order - // bits (zero based indexing). - // - // See Numerical Recipes in C: The Art of Scientific Computing - // (William H. Press, Brian P. Flannery, Saul A. Teukolsky, - // William T. Vetterling; New York: Cambridge University Press, - // 1992 (2nd ed., p. 277)) for details on why using the lower order - // bits, as in (rand() % 10), is bad. In particular, the lower - // order bits in older rand() implementations may not be as random - // as the higher order bits. - // - // @todo It would be better to use the random() function since it - // is supposed to have a larger period than rand(), in - // addition to the fact that the lower order bits should be as - // random as the higher order bits. - - // Prevent integer arithmetic overflow. - const CORBA::Float flen = static_cast<CORBA::Float> (len); - - const CORBA::ULong i = - static_cast<CORBA::ULong> (flen * ACE_OS::rand () / (RAND_MAX + 1.0)); - - ACE_ASSERT (i < len); - -// ACE_DEBUG ((LM_DEBUG, -// "** Len = %u\t" -// "Location # %u\t" -// "Loc Name = \"%s\"\n", -// len, -// i, -// locations[i][0].id.in ())); - - return load_manager->get_member_ref (object_group, - locations[i] - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_Random::init (void) -{ -#ifdef ACE_HAS_PTHREADS_STD - (void) ::pthread_once (&::tao_lb_once_control, - ::tao_lb_random_init_routine); -#else - ::tao_lb_random_init_routine (); -#endif /* ACE_HAS_PTHREADS_STD */ -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.h deleted file mode 100644 index af5bea2b038..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Random.h +++ /dev/null @@ -1,124 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_Random.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef LB_RANDOM_H -#define LB_RANDOM_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/CosLoadBalancingS.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_Random - * - * @brief "Random" load balancing strategy - * - * This load balancing strategy is designed to select an object group - * member residing at a random location. - */ -class TAO_LB_Random - : public virtual POA_CosLoadBalancing::Strategy -{ -public: - - /// Constructor. - /** - * Seeds the OS' random number generator. - */ - TAO_LB_Random (PortableServer::POA_ptr poa); - - /** - * @name CosLoadBalancing::Strategy methods - * - * Methods required by the CosLoadBalancing::Strategy interface. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::Properties * get_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::StrategyNotAdaptive)); - - virtual CosLoadBalancing::LoadList * get_loads ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - virtual CORBA::Object_ptr next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - virtual void analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - /// Returns the default POA for this servant. - virtual PortableServer::POA_ptr _default_POA ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS - ); - - /// TAO-specific underlying implementation of this Random load - /// balancing strategy's next_member() method. - static CORBA::Object_ptr _tao_next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Locations & locations - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - /// Initialize the random load balancing strategy. - /** - * If supported by the platform, initialization code will only run - * once for a given process. - */ - static void init (void); - -private: - - /// This servant's default POA. - PortableServer::POA_var poa_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - - -#include /**/ "ace/post.h" - -#endif /* LB_RANDOM_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.cpp deleted file mode 100644 index ab865f8020e..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// -*- C++ -*- - -#include "orbsvcs/LoadBalancing/LB_RoundRobin.h" - -#include "orbsvcs/PortableGroup/PG_conf.h" - -#include "tao/debug.h" -#include "tao/ORB_Constants.h" - -ACE_RCSID (LoadBalancing, - LB_RoundRobin, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_RoundRobin::TAO_LB_RoundRobin (PortableServer::POA_ptr poa) - : poa_ (PortableServer::POA::_duplicate (poa)), - lock_ (), - location_index_map_ (TAO_PG_MAX_OBJECT_GROUPS) -{ -} - -TAO_LB_RoundRobin::~TAO_LB_RoundRobin (void) -{ -} - -char * -TAO_LB_RoundRobin::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("RoundRobin"); -} - -CosLoadBalancing::Properties * -TAO_LB_RoundRobin::get_properties (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // There are no RoundRobin properties. Return an empty property - // list. - - CosLoadBalancing::Properties * props = 0; - ACE_NEW_THROW_EX (props, - CosLoadBalancing::Properties, - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO::VMCID, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (props); - - return props; -} - -void -TAO_LB_RoundRobin::push_loads ( - const PortableGroup::Location & /* the_location */, - const CosLoadBalancing::LoadList & /* loads */ - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::StrategyNotAdaptive)) -{ - ACE_THROW (CosLoadBalancing::StrategyNotAdaptive ()); -} - -CosLoadBalancing::LoadList * -TAO_LB_RoundRobin::get_loads (CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), 0); - - return load_manager->get_loads (the_location - ACE_ENV_ARG_PARAMETER); -} - -CORBA::Object_ptr -TAO_LB_RoundRobin::next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)) -{ - if (CORBA::is_nil (load_manager)) - ACE_THROW_RETURN (CORBA::BAD_PARAM (), CORBA::Object::_nil ()); - - const PortableGroup::ObjectGroupId id = - load_manager->get_object_group_id (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - monitor, - this->lock_, - CORBA::Object::_nil ()); - - // Since this is "built-in" strategy, the LoadManager is collocated. - // There is no need to release the lock during the following - // invocation. - // - // There is a race condition here. The - PortableGroup::Locations_var locations = - load_manager->locations_of_members (object_group - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - const CORBA::ULong len = locations->length (); - - if (len == 0) - ACE_THROW_RETURN (CORBA::TRANSIENT (), - CORBA::Object::_nil ()); - - TAO_LB_Location_Index_Map::ENTRY * entry; - if (this->location_index_map_.find (id, entry) == 0) - { - CORBA::ULong & i = entry->int_id_; - - if (len <= i) - i = 0; // Reset, i.e. wrap around - - // No need to release the lock since the LoadManager is - // collocated. - CORBA::Object_var member = - load_manager->get_member_ref (object_group, - locations[i] - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - // Increment index to point to next location. - i++; - - return member._retn (); - } - - // The first time through this method. Set up for the next time - // around, and return the object reference residing at the first - // location in the "locations of members" sequence. - - // Note that it is safe to set the next_index below to 1 even if the - // length of the sequence is 1 since the above code handles the - // boundary case correctly by wrapping around. - - const CORBA::ULong index = 0; - if (this->location_index_map_.bind (id, index + 1) != 0) - ACE_THROW_RETURN (CORBA::INTERNAL (), CORBA::Object::_nil ()); - - return load_manager->get_member_ref (object_group, - locations[index] - ACE_ENV_ARG_PARAMETER); -} - -void -TAO_LB_RoundRobin::analyze_loads ( - PortableGroup::ObjectGroup_ptr /* object_group */, - CosLoadBalancing::LoadManager_ptr /* load_manager */ - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -PortableServer::POA_ptr -TAO_LB_RoundRobin::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.h deleted file mode 100644 index a96a1120223..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_RoundRobin.h +++ /dev/null @@ -1,127 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_RoundRobin.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef LB_ROUND_ROBIN_H -#define LB_ROUND_ROBIN_H - -#include /**/ "ace/pre.h" - -#include "ace/Null_Mutex.h" - -# if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -# endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/LoadBalancing/LB_Location_Index_Map.h" - -#include "orbsvcs/CosLoadBalancingS.h" - - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -/** - * @class TAO_LB_RoundRobin_Strategy - * - * @brief "Round Robin" load balancing strategy - * - * This load balancing strategy is designed to select an object group - * member residing at the next location. - */ -class TAO_LB_RoundRobin - : public virtual POA_CosLoadBalancing::Strategy -{ -public: - - /// Constructor. - TAO_LB_RoundRobin (PortableServer::POA_ptr poa); - - /** - * @name CosLoadBalancing::Strategy methods - * - * Methods required by the CosLoadBalancing::Strategy interface. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual CosLoadBalancing::Properties * get_properties ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void push_loads ( - const PortableGroup::Location & the_location, - const CosLoadBalancing::LoadList & loads - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::StrategyNotAdaptive)); - - virtual CosLoadBalancing::LoadList * get_loads ( - CosLoadBalancing::LoadManager_ptr load_manager, - const PortableGroup::Location & the_location - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - CosLoadBalancing::LocationNotFound)); - - virtual CORBA::Object_ptr next_member ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableGroup::ObjectGroupNotFound, - PortableGroup::MemberNotFound)); - - virtual void analyze_loads ( - PortableGroup::ObjectGroup_ptr object_group, - CosLoadBalancing::LoadManager_ptr load_manager - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - //@} - - /// Returns the default POA for this servant. - virtual PortableServer::POA_ptr _default_POA ( - ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS - ); - -protected: - - /// Destructor - ~TAO_LB_RoundRobin (void); - -private: - - /// This servant's default POA. - PortableServer::POA_var poa_; - - /// Lock used to ensure atomic access to state retained by this - /// class. - TAO_SYNCH_MUTEX lock_; - - /// Table that maps PortableGroup::ObjectGroupId to location - /// sequence index specific to a given object group. - /** - * The location sequence corresponds to the sequence containing the - * locations of the members of a given object group. The value - * stored in this map corresponds to the index of the next element - * in that sequence. For example, if the index stored in the map is - * 2, location[2] will be used when retrieving the object reference - * to be returned from the Strategy::next_member() method. - */ - TAO_LB_Location_Index_Map location_index_map_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* LB_ROUND_ROBIN_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.cpp b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.cpp deleted file mode 100644 index 10bb3303a39..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include "orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.h" -#include "orbsvcs/LoadBalancing/LB_LoadAlert.h" - -#include "tao/debug.h" - -#include "ace/OS_NS_string.h" - - -ACE_RCSID (LoadBalancing, - LB_ServerRequestInterceptor, - "$Id$") - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -TAO_LB_ServerRequestInterceptor::TAO_LB_ServerRequestInterceptor ( - TAO_LB_LoadAlert & load_alert) - : load_alert_ (load_alert) -{ -} - -TAO_LB_ServerRequestInterceptor::~TAO_LB_ServerRequestInterceptor (void) -{ -} - -char * -TAO_LB_ServerRequestInterceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup ("TAO_LB_ServerRequestInterceptor"); -} - -void -TAO_LB_ServerRequestInterceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ServerRequestInterceptor::receive_request_service_contexts ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ - if (this->load_alert_.alerted ()) - { - CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (ACE_OS::strcmp (op.in (), "_get_loads") == 0 // LoadMonitor - || ACE_OS::strcmp (op.in (), "disable_alert") == 0 // LoadAlert - || ACE_OS::strcmp (op.in (), "enable_alert") == 0) // LoadAlert - return; // Do not redirect. - -#if 0 - ACE_TRY - { - IOP::ServiceContext_var service_context = - ri->get_request_service_context (CosLoadBalancing::LOAD_MANAGED - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - /* - // Use TAO-specific "compiled marshaling" instead of - // standard interpretive marshaling via a CDR encapsulation - // Codec for efficiency reasons. - const char * buf = - reinterpret_cast<const char *> (service_context->context_data.get_buffer ()); - TAO_InputCDR cdr (buf, - service_context->context_data.length ()); - - CORBA::Boolean byte_order; - if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0) - ACE_TRY_THROW (CORBA::BAD_PARAM ()); - - cdr.reset_byte_order (static_cast<int> (byte_order)); - - CORBA::Object_var object_group; - if (cdr >> object_group.out ()) - ACE_TRY_THROW (PortableInterceptor::ForwardRequest (object_group.in (), - 0)); - else - ACE_TRY_THROW (CORBA::BAD_PARAM ()); - */ - - // A ServiceContext of the given ServiceId exists. This - // means that the target is load balanced. Force the client - // to try another profile since this location is currently - // overloaded. - ACE_TRY_THROW (CORBA::TRANSIENT ()); - } - ACE_CATCH (CORBA::BAD_PARAM, ex) - { - // No CosLoadBalancing::LB_GROUP_REF ServiceContext. This - // probably means that the target object is not - // LoadBalanced. - - // There is a huge DoS attack vulnerability with this load - // shedding model. The model relies on the client behaving - // correctly. In particular, it relies on the client to - // send the forward object group reference in the - // ServiceContextList. Any "misbehaving" client can avoid - // that, in which case no load will ever be shed! - - - // Make sure we get a CORBA::BAD_PARAM for the right - // reason. - if (ex.minor () != (CORBA::OMGVMCID | 26)) - ACE_RE_THROW; - } - ACE_ENDTRY; - ACE_CHECK; -#else - // Force the client to try another profile since this location - // is currently overloaded. - // - // NOTE: This applies to both load balanced and non-load - // balanced targets. - ACE_THROW (CORBA::TRANSIENT ()); -#endif /* 0 */ - } -} - -void -TAO_LB_ServerRequestInterceptor::receive_request ( - PortableInterceptor::ServerRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ -} - -void -TAO_LB_ServerRequestInterceptor::send_reply ( - PortableInterceptor::ServerRequestInfo_ptr /* ri */ - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ -} - -void -TAO_LB_ServerRequestInterceptor::send_exception ( - PortableInterceptor::ServerRequestInfo_ptr - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ - if (TAO_debug_level > 0) - { - // A CORBA::TRANSIENT is thrown when the LoadManager informs the - // LoadAlert object that its member is overloaded, for example. - - ACE_DEBUG ((LM_INFO, - ACE_TEXT ("TAO_LB_ServerRequestInterceptor -- ") - ACE_TEXT ("Exception thrown.\n"))); - } -} - -void -TAO_LB_ServerRequestInterceptor::send_other ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)) -{ - if (TAO_debug_level > 0) - { - // A location forward occurs when the LoadManager informs the - // LoadAlert object that its member is overloaded, for example. - - const PortableInterceptor::ReplyStatus status = - ri->reply_status (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (status == PortableInterceptor::LOCATION_FORWARD) - ACE_DEBUG ((LM_INFO, - ACE_TEXT ("TAO_LB_ServerRequestInterceptor -- ") - ACE_TEXT ("LOCATION FORWARDED\n"))); - } -} - -TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.h deleted file mode 100644 index a3a94008a27..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ServerRequestInterceptor.h +++ /dev/null @@ -1,125 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_ServerRequestInterceptor.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_SERVER_REQUEST_INTERCEPTOR_H -#define TAO_LB_SERVER_REQUEST_INTERCEPTOR_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#include "orbsvcs/LoadBalancing/LoadBalancing_export.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/PI_Server/PI_Server.h" -#include "tao/PortableInterceptorC.h" -#include "tao/LocalObject.h" - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -class TAO_LB_LoadAlert; - -/** - * @class TAO_LB_ServerRequestInterceptor - * - * @brief ServerRequestInterceptor that interacts with the TAO-shipped - * LoadAlert implementation. - * - * This ServerRequestInterceptor is responsible for redirecting - * requests back to the LoadManager. - */ -class TAO_LoadBalancing_Export TAO_LB_ServerRequestInterceptor - : public virtual PortableInterceptor::ServerRequestInterceptor, - public virtual TAO_Local_RefCounted_Object -{ -public: - - /// Constructor. - TAO_LB_ServerRequestInterceptor (TAO_LB_LoadAlert & load_alert); - - /** - * @name Methods Required by the ServerRequestInterceptor - * Interface - * - * These are the canonical methods required for all - * ServerRequestInterceptors. - */ - //@{ - virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void receive_request_service_contexts ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - - virtual void receive_request ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - - virtual void send_reply ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void send_exception ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - - virtual void send_other ( - PortableInterceptor::ServerRequestInfo_ptr ri - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException, - PortableInterceptor::ForwardRequest)); - //@} - -protected: - - /// Destructor. - /** - * Protected destructor to enforce correct memory management via - * reference counting. - */ - ~TAO_LB_ServerRequestInterceptor (void); - -private: - - TAO_LB_LoadAlert & load_alert_; - -}; - -TAO_END_VERSIONED_NAMESPACE_DECL - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_SERVER_REQUEST_INTERCEPTOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_conf.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_conf.h deleted file mode 100644 index 9c65aba972c..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_conf.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file LB_conf.h - * - * $Id$ - * - * @author Ossama Othman <ossama@uci.edu> - */ -//============================================================================= - - -#ifndef TAO_LB_CONF_H -#define TAO_LB_CONF_H - -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/Versioned_Namespace.h" - -TAO_BEGIN_VERSIONED_NAMESPACE_DECL - -#ifndef TAO_LB_PULL_HANDLER_INTERVAL -/// The interval in seconds the load balancer queries registered load -/// monitors for loads. -const long TAO_LB_PULL_HANDLER_INTERVAL = 5; -#endif /* TAO_LB_PULL_HANDLER_INTERVAL */ - -#ifndef TAO_LB_PULL_HANDLER_RESTART -/// The time in seconds the load balancer's "pull handler" is -/// restarted after being fired. -const long TAO_LB_PULL_HANDLER_RESTART = 5; -#endif /* TAO_LB_PULL_HANDLER_RESTART */ - -TAO_END_VERSIONED_NAMESPACE_DECL - -#include /**/ "ace/post.h" - -#endif /* TAO_LB_CONF_H */ diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/LoadBalancing_export.h b/TAO/orbsvcs/orbsvcs/LoadBalancing/LoadBalancing_export.h deleted file mode 100644 index 10ec8a56fe1..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/LoadBalancing_export.h +++ /dev/null @@ -1,40 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl -// ------------------------------ -#ifndef TAO_LOADBALANCING_EXPORT_H -#define TAO_LOADBALANCING_EXPORT_H - -#include "ace/config-all.h" - -#if defined (TAO_AS_STATIC_LIBS) -# if !defined (TAO_LOADBALANCING_HAS_DLL) -# define TAO_LOADBALANCING_HAS_DLL 0 -# endif /* ! TAO_LOADBALANCING_HAS_DLL */ -#else -# if !defined (TAO_LOADBALANCING_HAS_DLL) -# define TAO_LOADBALANCING_HAS_DLL 1 -# endif /* ! TAO_LOADBALANCING_HAS_DLL */ -#endif - -#if defined (TAO_LOADBALANCING_HAS_DLL) && (TAO_LOADBALANCING_HAS_DLL == 1) -# if defined (TAO_LOADBALANCING_BUILD_DLL) -# define TAO_LoadBalancing_Export ACE_Proper_Export_Flag -# define TAO_LOADBALANCING_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define TAO_LOADBALANCING_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* TAO_LOADBALANCING_BUILD_DLL */ -# define TAO_LoadBalancing_Export ACE_Proper_Import_Flag -# define TAO_LOADBALANCING_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define TAO_LOADBALANCING_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* TAO_LOADBALANCING_BUILD_DLL */ -#else /* TAO_LOADBALANCING_HAS_DLL == 1 */ -# define TAO_LoadBalancing_Export -# define TAO_LOADBALANCING_SINGLETON_DECLARATION(T) -# define TAO_LOADBALANCING_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* TAO_LOADBALANCING_HAS_DLL == 1 */ - -#endif /* TAO_LOADBALANCING_EXPORT_H */ - -// End of auto generated file. diff --git a/TAO/orbsvcs/orbsvcs/LoadBalancing/README b/TAO/orbsvcs/orbsvcs/LoadBalancing/README deleted file mode 100644 index 175e8e074fd..00000000000 --- a/TAO/orbsvcs/orbsvcs/LoadBalancing/README +++ /dev/null @@ -1,35 +0,0 @@ -This directory contains the implementations of the TAO Load Balancing -service, which is called as Cygnus. - -Cygnus currently implements the latest revision of the OMG Load Balancing -and Monitoring proposed specification. The features and advantages of -Cygnus include: -1. Multiple object group support. -2. Extensible load balancing strategies through IDL interface. -3. Extensible load monitoring. -4. Support for push and pull style monitoring. -5. Support for infrastructure and application controlled memberships. -6. Efficient server side transparency. -7. Default implementations of well known load balancing strategies. - -Future Work targeted: -1. Implement a distributed load balancing service. -2. Implement stateful load balancing service. -3. Implement self adaptive load balancing strategies using control -theoretical techniques. - -Papers about Cygnus: -1. Ossama Othman, Carlos O'Ryan, and Douglas C. Schmidt, The Design of an -Adaptive CORBA Load Balancing Service, IEEE Distributed Systems Online, Volume -2, Number 4, April, 2001. -2. Ossama Othman, Carlos O'Ryan, and Douglas C. Schmidt, An Efficient -Adaptive Load Balancing Service for CORBA, IEEE Distributed Systems Online, -Volume 2, Number 3, March, 2001. -3. Jaiganesh Balasubramanian, Douglas C. Schmidt, Lawrence Dowdy, and Ossama -Othman, Evaluating the Performance of Middleware Load Balancing Strategies, -Proceedings of the 8th International IEEE Enterprise Distributed Object -Computing Conference, Monterey, CA, September 2004 -4. Ossama Othman, Jaigaesh Balasubramanian, and Douglas C. Schmidt, The -Design of an Adaptive Middleware Load Balancing and Monitoring Service, Third -International Workshop on Self-Adaptive Software, Arlington, VA, USA, June -9-11, 2003 |