diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:11 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:11 +0000 |
commit | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (patch) | |
tree | da50d054f9c761c3f6a5923f6979e93306c56d68 /TAO/examples/Load_Balancing_persistent | |
parent | 0e555b9150d38e3b3473ba325b56db2642e6352b (diff) | |
download | ATCD-6b846cf03c0bcbd8c276cb0af61a181e5f98eaae.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/examples/Load_Balancing_persistent')
15 files changed, 0 insertions, 2938 deletions
diff --git a/TAO/examples/Load_Balancing_persistent/Identity.idl b/TAO/examples/Load_Balancing_persistent/Identity.idl deleted file mode 100755 index f16f5e410eb..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity.idl +++ /dev/null @@ -1,22 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = FILENAME -// Identity.idl -// -// = DESCRIPTION -// Interface for a toy CORBA service useful for -// testing/demonstrating functionality of the Load -// Balancing service defined in Load_Balancer.idl. -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ - -interface Identity -{ - void get_name (out string name); - // Obtain the name of this object. -}; diff --git a/TAO/examples/Load_Balancing_persistent/Identity_Client.cpp b/TAO/examples/Load_Balancing_persistent/Identity_Client.cpp deleted file mode 100755 index 0ffc8625639..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_Client.cpp +++ /dev/null @@ -1,274 +0,0 @@ -// $Id$ -// ============================================================================ -// -// = LIBRARY -// TAO/examples/Load_Balancing -// -// = FILENAME -// Identity_Client.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// -// ============================================================================ - -#include "Identity_Client.h" -#include "IdentityC.h" -#include "Load_BalancerC.h" -#include "tao/debug.h" -#include "ace/Get_Opt.h" -#include "ace/High_Res_Timer.h" -#include "ace/Stats.h" - -Identity_Client::Identity_Client (void) - : group_factory_ior_ (0), - number_of_invocations_ (5), - use_random_ (0), - iterations_ (0) -{ -} - -int -Identity_Client::parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opts (argc, argv, "di:n:k:r"); - int c; - - while ((c = get_opts ()) != -1) - switch (c) - { - case 'd': // debug flag. - TAO_debug_level++; - break; - case 'i': // ior of the <Object_Group_Factory> object. - this->group_factory_ior_ = get_opts.opt_arg (); - break; - case 'n': // number of times to make invocation on an <Identity> object. - this->number_of_invocations_ = ACE_OS::atoi (get_opts.opt_arg ()); - break; - case 'k': - this->iterations_ = ACE_OS::atoi (get_opts.opt_arg ()); - break; - case 'r': // flag signifying to obtain references to <Identity> - // objects from the random <Object_Group> rather than - // from the round robin one. - this->use_random_ = 1; - break; - case '?': - default: - ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s" - " [-d]" - " [-i] <Object_Group_Factory_ior>" - " [-n] <number_of_invocations>" - " [-r]" - "\n", - argv [0]), - -1); - } - - // Indicates successful parsing of command line. - return 0; -} - -int -Identity_Client::init (int argc, - char* argv[]) -{ - int result; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = this->orb_manager_.init (argc, - argv - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (result == -1) - return result; - - // Check the non-ORB arguments. - result = this->parse_args (argc, argv); - if (result < 0) - return result; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Identity_Client::init"); - return -1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (-1); - - return 0; -} - -int -Identity_Client::run (ACE_ENV_SINGLE_ARG_DECL) -{ - // Contact the <Object_Group_Factory> to obtain an <Object_Group>. - CORBA::ORB_var orb = orb_manager_.orb (); - CORBA::Object_var obj = - orb->string_to_object (this->group_factory_ior_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - if (obj.in () == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N|%l) <ERROR> [Identity_Client::run] \n") - ACE_TEXT ("factory_resolve \n")), - -1); - - Load_Balancer::Object_Group_Factory_var factory = - Load_Balancer::Object_Group_Factory::_narrow (obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - if (CORBA::is_nil (factory.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - "Identity_Client: problems using the factory ior\n"), - -1); - - const char *group_name; - if (this->use_random_) - group_name = "Random group"; - else - group_name = "Round Robin group"; - - Load_Balancer::Object_Group_var object_group; - - // We have this for the measurement that was done. -#if defined (DOORS_MEASURE_STATS) - - // Performance measurements start here - ACE_High_Res_Timer::calibrate (); - - ACE_hrtime_t throughput_base = ACE_OS::gethrtime (); - - ACE_Throughput_Stats throughput; - ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor (); - - for (int i = 0; i < this->iterations_; i++) - { - // Record current time. - ACE_hrtime_t latency_base = ACE_OS::gethrtime (); - -#endif /*TAO_MEASURE_STATS*/ - // Remote call - object_group = - factory->resolve (group_name - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - CORBA::String_var iorstring = - orb->object_to_string (object_group.in ()); - - ACE_DEBUG ((LM_DEBUG, - "The ior string is %s \n", iorstring.in ())); -#if defined (DOORS_MEASURE_STATS) - // Grab timestamp again. - ACE_hrtime_t now = ACE_OS::gethrtime (); - - // Record statistics. - throughput.sample (now - throughput_base, - now - latency_base); - - } - - ACE_OS::printf ("*=*=*=*=Aggregated result *=*=*=*=*= \n"); - throughput.dump_results ("Aggregated", gsf); -#endif /*TAO_MEASURE_STATS */ - - if (CORBA::is_nil (object_group.in ())) - { - ACE_ERROR_RETURN ((LM_ERROR, - "(%l|%d)The narrowed object is NUL:"), - -1); - } - - // List <Object_Group>'s id. - CORBA::String_var id = object_group->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - ACE_DEBUG ((LM_DEBUG, "Object Group's id is: %s\n\n", id.in ())); - - // List all <Object_Group>s members. - Load_Balancer::Member_ID_List_var id_list = - object_group->members (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - ACE_DEBUG ((LM_DEBUG, - "The group contains %d members:\n", - id_list->length ())); - for (CORBA::ULong i = 0; i < id_list->length (); ++i) - ACE_DEBUG ((LM_DEBUG, "%s\n", static_cast<char const*>(id_list[i]))); - - // Perform <number_of_invocations_> method calls on <Identity> - // objects, which are members of the <Object_Group>. Before each - // invocations, we get an <Identity> reference to use for that - // invocation from our <Object_Group>. - Identity_var identity_object; - CORBA::String_var identity; - CORBA::String_var objref; - - for (size_t ind = 0; ind < this->number_of_invocations_; ++ind) - { - objref = object_group->resolve (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - obj = orb->string_to_object (objref.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - identity_object = Identity::_narrow (obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - if (CORBA::is_nil (identity_object.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - "Identity_Client: cannot narrow an object received from" - "<Object_Group::resolve> to <Identity>\n"), - -1); - identity_object->get_name (identity.out ()); - ACE_CHECK_RETURN (-1); - - ACE_DEBUG ((LM_DEBUG, - "Invocation %s\n", - identity.in ())); - ACE_CHECK_RETURN (-1); - - } - - return 0; -} - -Identity_Client::~Identity_Client (void) -{ -} - -int -main (int argc, char *argv[]) -{ - int result = 0; - Identity_Client client; - - if (client.init (argc, argv) == -1) - return 1; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = client.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Identity_Client"); - return 1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (1); - - if (result == -1) - return 1; - else - return 0; -} diff --git a/TAO/examples/Load_Balancing_persistent/Identity_Client.h b/TAO/examples/Load_Balancing_persistent/Identity_Client.h deleted file mode 100755 index 94565ef6278..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_Client.h +++ /dev/null @@ -1,84 +0,0 @@ -// $Id$ -// -*- C++ -*- - -// ============================================================================ -// -// = LIBRARY -// TAO/examples/Load_Balancing -// -// = FILENAME -// Identity_Client.h -// -// = DESCRIPTION -// Code for Identity_Client, which is used in conjunction with -// Identity_Server to test/demonstrate the functionality of the -// Load Balancing service. -// -// = AUTHORS -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ - -#ifndef IDENTITY_CLIENT_H_ -#define IDENTITY_CLIENT_H_ - -#include "tao/Utils/ORB_Manager.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -class Identity_Client -{ - // =TITLE - // Contacts the <Object_Group_Factory> in th Load Balancing Server - // to obtain a reference to the type of the <Object_Group> - // specified on the command line. Then, queries the - // <Object_Group> for its id and members, and prints that - // information. Finally, performs <number_of_invocations_> - // <Identity::get_name> calls, performing <Object_Group::resolve> - // before each <get_name> call in order to get the <Identity> - // reference to use for the call. (This provides an example of - // fine-grained, i.e., per call, Load Balancing among all the - // <Identity> objects registered with the <Object_Group> for the - // client's <get_name> calls. - // -public: - - Identity_Client (void); - // Default constructor. - - ~Identity_Client (void); - // Destructor. - - int init (int argc, char *argv[]); - // Initializes <orb_manager_>, and parses commandline arguments. - - int run (ACE_ENV_SINGLE_ARG_DECL); - // See TITLE. - -private: - int parse_args (int argc, char *argv[]); - // Parses the commandline arguments. - - TAO_ORB_Manager orb_manager_; - // The ORB manager. - - const char *group_factory_ior_; - // The ior of the <Object_Group_Factory> object we shall use to - // to obtain an <Object_Group> object. - - size_t number_of_invocations_; - // Number of times to invoke <get_name> method on <Identity> - // objects. The default value is 5. - - size_t use_random_; - // Flag indicating which <Object_Group> to use to obtain references - // to <Identity> objects. Random group should be used if the flag - // is set to 1, and round robin group otherwise. Round robin is the - // default. - - int iterations_; -}; - -#endif /* IDENTITY_CLIENT_H_ */ diff --git a/TAO/examples/Load_Balancing_persistent/Identity_Server.cpp b/TAO/examples/Load_Balancing_persistent/Identity_Server.cpp deleted file mode 100755 index 772a2092ada..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_Server.cpp +++ /dev/null @@ -1,304 +0,0 @@ -// $Id$ - -#include "Identity_Server.h" -#include "Identity_i.h" -#include "tao/debug.h" -#include "ace/Get_Opt.h" -#include "ace/OS_NS_stdio.h" - -Identity_Server::Identity_Server (void) - : group_factory_ior_ (0), - random_objects_ (5), - rr_objects_ (5) -{ -} - -int -Identity_Server::parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opts (argc, argv, "di:a:o:"); - int c; - - while ((c = get_opts ()) != -1) - switch (c) - { - case 'd': // debug flag. - TAO_debug_level++; - break; - case 'i': // ior of the <Object_Group_Factory> object. - this->group_factory_ior_ = get_opts.opt_arg (); - break; - case 'a': // number of objects to create/register with the random group. - random_objects_ = ACE_OS::atoi (get_opts.opt_arg ()); - break; - case 'o': // number of objects to create/register with round - //robin group. - rr_objects_ = ACE_OS::atoi (get_opts.opt_arg ()); - break; - case '?': - default: - ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s" - " [-d]" - " [-i] <Object_Group_Factory_ior>" - " [-a] <number_of_objects_for_random_group>" - " [-o] <number_of_objects_for_rr_group>" - "\n", - argv [0]), - -1); - } - - // Indicates successful parsing of command line. - return 0; -} - -int -Identity_Server::init (int argc, - char* argv[]) -{ - int result; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = this->orb_manager_.init (argc, - argv - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (result == -1) - return result; - - CORBA::PolicyList policies (2); - policies.length (2); - - // Lifespan policy - policies[0] = - this->orb_manager_.root_poa()->create_lifespan_policy (PortableServer::PERSISTENT - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - policies[1] = - this->orb_manager_.root_poa()->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - this->persistent_POA_ = - this->orb_manager_.root_poa()->create_POA ("persistent_server", - this->orb_manager_.poa_manager (), - policies - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - - // Destroy policy objects - for (CORBA::ULong i = 0; - i < policies.length (); - ++i) - { - policies[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - - - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Identity_Server::init"); - return -1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (-1); - - return 0; -} - -int -Identity_Server::register_groups (ACE_ENV_SINGLE_ARG_DECL) -{ - - - - // Contact the <Object_Group_Factory> to create 2 - // <Object_Group>s, one random and one rr. - CORBA::ORB_var orb = orb_manager_.orb (); - CORBA::Object_var obj = - orb->string_to_object (this->group_factory_ior_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - Load_Balancer::Object_Group_Factory_var factory = - Load_Balancer::Object_Group_Factory::_narrow (obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - if (CORBA::is_nil (factory.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - "Identity_Server::init: " - "problems using the factory ior\n"), - -1); - - - // Unbind the previously registered random group. - ACE_TRY_EX (UNBIND_RANDOM) - { - factory->unbind_random ("Random group" - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (UNBIND_RANDOM); - } - ACE_CATCHANY - { - ACE_DEBUG ((LM_DEBUG, - "(%N | %l) <Unbind> harmless here \n")); - } - ACE_ENDTRY; - - // Unbind the previously registered round robin group - ACE_TRY_EX (UNBIND_ROUND) - { - factory->unbind_round_robin ("Round Robin group" - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (UNBIND_ROUND); - } - ACE_CATCHANY - { - ACE_DEBUG ((LM_DEBUG, - "(%N | %l) <Unbind> harmless here \n")); - } - ACE_ENDTRY; - - - // We want to make two groups Random & Round Robin. - Load_Balancer::Object_Group_var random_group = - factory->make_random ("Random group" - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - Load_Balancer::Object_Group_var rr_group = - factory->make_round_robin ("Round Robin group" - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - - // Create the requested number of <Identity> objects, and - // register them with the random and round robin - // <Object_Group>s. - this->create_objects (random_objects_, - random_group.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - - this->create_objects (rr_objects_, - rr_group.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - return 0; -} - -void -Identity_Server::create_objects (size_t number_of_objects, - Load_Balancer::Object_Group_ptr group - ACE_ENV_ARG_DECL) -{ - // Create the specified number of servants, and register each one - // with the provided <Object_Group>. - for (size_t i = 0; i < number_of_objects; ++i) - { - // Create an id for this servant. - char id[BUFSIZ]; - ACE_OS::sprintf (id, - "Identity object " ACE_SIZE_T_FORMAT_SPECIFIER, - i); - - // Create and activate a servant. - Identity_i * identity_servant; - ACE_NEW_THROW_EX (identity_servant, - Identity_i (id, this->persistent_POA_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK; - - PortableServer::ServantBase_var s = identity_servant; - this->orb_manager_.activate_poa_manager (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - CORBA::Object_var obj = identity_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - Load_Balancer::Member member; - member.id = CORBA::string_dup (id); - member.obj = - this->orb_manager_.orb ()->object_to_string (obj.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Do an unbind and then bind - ACE_TRY_EX (UNBIND) - { - group->unbind (id ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK_EX (UNBIND); - } - ACE_CATCHANY - { - ACE_DEBUG ((LM_DEBUG, - "(%N | %l) Harmless here \n")); - } - ACE_ENDTRY; - - // Bind the servant in the random <Object_Group>. - group->bind (member ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - } -} - -int - Identity_Server::run (ACE_ENV_SINGLE_ARG_DECL) -{ - int result; - - result = this->orb_manager_.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - return result; -} - -Identity_Server::~Identity_Server (void) -{ -} - -int -main (int argc, char *argv[]) -{ - int result = 0; - Identity_Server server; - - if (server.init (argc, argv) == -1) - return 1; - - // Check the non-ORB arguments. - if (server.parse_args (argc, argv) == -1) - return -1; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = server.register_groups (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - result = server.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Identity_Server"); - return 1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (1); - - if (result == -1) - return 1; - else - return 0; -} diff --git a/TAO/examples/Load_Balancing_persistent/Identity_Server.h b/TAO/examples/Load_Balancing_persistent/Identity_Server.h deleted file mode 100755 index 36cdc386f62..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_Server.h +++ /dev/null @@ -1,91 +0,0 @@ -// $Id$ -// -*- C++ -*- - -// ============================================================================ -// -// = LIBRARY -// TAO/examples/Load_Balancing -// -// = FILENAME -// Identity_Server.h -// -// = DESCRIPTION -// Driver for identity server, which is used to test/demonstrate -// the functionality of the Load Balancing service. -// -// = AUTHORS -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ - -#ifndef IDENTITY_SERVER_H_ -#define IDENTITY_SERVER_H_ - -#include "tao/Utils/ORB_Manager.h" -#include "Load_BalancerC.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -class Identity_Server -{ - // =TITLE - // Contacts the <Object_Group_Factory> in the Load Balancing Server - // to create two <Object_Group>s, one round robin and one random. - // Then, creates a number of <Identity> objects and registers them with - // the created <Object_Group>s in a manner specified by the - // commandline arguments. - // -public: - - Identity_Server (void); - // Default constructor. - - ~Identity_Server (void); - // Destructor. - - int parse_args (int argc, char *argv[]); - // Parses the commandline arguments. - - int init (int argc, char *argv[]); - // Performs all the initializations necessary before going into the - // ORB event loop. - - int register_groups (ACE_ENV_SINGLE_ARG_DECL); - - - int run (ACE_ENV_SINGLE_ARG_DECL); - // Run the server. - -private: - - - void create_objects (size_t number_of_objects, - Load_Balancer::Object_Group_ptr group - ACE_ENV_ARG_DECL); - // Creates the specified number of identity objects, and registers - // each one with the provided <Object_Group>. Identity servants are - // given names - //"Identity object 1" .... "Identity object <number_of_objects>". - - - TAO_ORB_Manager orb_manager_; - // The ORB manager. - - const char *group_factory_ior_; - // The ior of the <Object_Group_Factory> object we shall use to - // create <Object_Group>s to load balance our <Identity> objects. - - size_t random_objects_; - // Number of <Identity> objects to create for registering with - // the random <Object_Group>. The default value is 5. - - size_t rr_objects_; - // Number of <Identity> objects to create for registering with the - // round robin <Object_Group>. The default value is 5. - - PortableServer::POA_var persistent_POA_; -}; - -#endif /* IDENTITY_SERVER_H_ */ diff --git a/TAO/examples/Load_Balancing_persistent/Identity_i.cpp b/TAO/examples/Load_Balancing_persistent/Identity_i.cpp deleted file mode 100755 index 5c8d6b0b57d..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_i.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ -// ============================================================================ -// -// = FILENAME -// Identity_i.cpp -// -// = DESCRIPTION -// Implements the interface in Identity.idl. -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// -// ============================================================================ -#include "Identity_i.h" - -Identity_i::Identity_i (const char *name, - PortableServer::POA_ptr poa) - : name_ (name), - poa_ (PortableServer::POA::_duplicate (poa)) -{ -} - -Identity_i::~Identity_i (void) -{ -} - -void -Identity_i::get_name (CORBA::String_out name - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - name = this->name_.in (); -} - -PortableServer::POA_ptr -Identity_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} diff --git a/TAO/examples/Load_Balancing_persistent/Identity_i.h b/TAO/examples/Load_Balancing_persistent/Identity_i.h deleted file mode 100755 index 3712d79c9f1..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Identity_i.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ -// ============================================================================ -// -// = FILENAME -// Identity_i.h -// -// = DESCRIPTION -// Implements the interface in Identity.idl. -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ -#ifndef IDENTITY_I_H_ -#define IDENTITY_I_H_ - -#include "IdentityS.h" - -class Identity_i : - public virtual POA_Identity -{ - // = TITLE - // This class implements Identity.idl interface. -public: - - Identity_i (const char *name, - PortableServer::POA_ptr poa); - // Constructor - initializes the name of this object. - - ~Identity_i (void); - // Destructor. - - virtual void get_name (CORBA::String_out name - ACE_ENV_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Returns the name of this object. - - PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Method for the POA that will return the persistent POA_ptr stored - // in here.. - -private: - - CORBA::String_var name_; - // Stores the name of this object. - - PortableServer::POA_var poa_; -}; - -#endif /* IDENTITY_I_H_ */ diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancer.idl b/TAO/examples/Load_Balancing_persistent/Load_Balancer.idl deleted file mode 100755 index 5b7cfa3b61a..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancer.idl +++ /dev/null @@ -1,172 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = FILENAME -// Load_Balancer.idl -// -// = DESCRIPTION -// Interfaces for a simple CORBA Load Balancing service, which can -// be used in conjunction with the Naming Service or alone to -// improve distributed load balancing. See README file for a short -// discussion of other solution approaches for load balancing as -// well as use cases for this approach. -// -// = AUTHOR -// Interfaces in this file came from OrbixNames Load Balancing -// features with modifications by: -// Doug Schmidt (schmidt@cs.wustl.edu) -// Marina Spivak (marina@cs.wustl.edu) -// -// ============================================================================ - -module Load_Balancer -{ - // = TITLE - // Define a module that allows clients to treat a group - // of <Object>s, i.e., an <Object_Group>, as an equivalence class - // to improve distributed load balancing. - // - // = DESCRIPTION - // <Object_Group_Factory> is used to create <Object_Group>s. - // There are two logical types of <Object_Group>s : - // - // 1. Round Robin <Object_Group> -- This <Object_Group> resolves - // requests for arbitrary members in round robin order. - // - // 2. Random <Object_Group> -- This <Object_Group> resolves - // requests for arbitrary members in random order. - // - // Both types of <Object_Group>s have the same interface (i.e., - // <Object_Group>) but different behaviour should be provided - // in interface implementations appropriately. - - // = Module-defined exceptions. - exception no_such_member {}; - exception duplicate_member {}; - exception duplicate_group {}; - exception no_such_group {}; - - // = Module-defined types. - - typedef string Member_ID; - typedef sequence<Member_ID> Member_ID_List; - typedef string Objref; - - struct Member - { - Objref obj; - // IOR of an <Object_Group> member. - - Member_ID id; - // Each member in an <Object_Group> is identified by a unique ID. - }; - - typedef string Group_ID; - typedef sequence<Group_ID> Group_List; - - // = Forward interface decls. - interface Object_Group; - - interface Object_Group_Factory - { - // = TITLE - // A factory that creates different types of - // <Object_Group>s and keeps track of them. - // - // = DESCRIPTION - // Currently, operations for two types of <Object_Group>s are - // defined: random and round robin. - - Object_Group make_round_robin (in Group_ID id) - raises (duplicate_group); - // Creates an <Object_Group> that resolves requests for arbitrary - // members in round robin order. If an <Object_Group>, of any - // type, with Group_ID <id> has already been created by this - // factory, and hasn't been destroyed, a <duplicate_group> - // exception is thrown. - - void unbind_round_robin (in Group_ID id) - raises (no_such_group); - // Unbinds a previous incarnation of the Round Robin if any - - Object_Group make_random (in Group_ID id) - raises (duplicate_group); - // Creates an <Object_Group> that resolves requests for arbitrary - // members in random order. If an <Object_Group>, of any - // type, with Group_ID <id> has already been created by this - // factory, and hasn't been destroyed, a <duplicate_group> - // exception is thrown. - - void unbind_random (in Group_ID id) - raises (no_such_group); - // Unbinds a previous incarnation of the Random groups. - - Object_Group resolve (in Group_ID id) raises (no_such_group); - // Locates and returns an <Object_Group> by its <Group_ID>. If - // no <Object_Group> has <Group_ID> of <id>, throw a - // <no_such_group> exception. - - Group_List round_robin_groups (); - // Lists all the round robin <Object_Group>s which were created - // by this factory, and haven't been destroyed yet, i.e., return - // a sequence of <Group_ID>s of all existing round robin - // <Object_Group>s created by this factory. - - Group_List random_groups (); - // Lists all the random <Object_Group>s which were created - // by this factory, and haven't been destroyed yet, i.e., return - // a sequence of <Group_ID>s of all existing random - // <Object_Group>s created by this factory. - }; - - interface Object_Group - { - // = TITLE - // Holds references for 0 or more objects that form an - // equivalence class, and provides load balancing for those - // objects. - // - // = DESCRIPTION - // Whenever a client needs to find an object of a certain type - // or functionality, it makes a request to the appropriate - // <Object_Group>. The <Object_Group> selects one of its - // members in accordance with the implemented policy (i.e., - // random or round robin), and returnd it to the client, thus - // providing a form of load balancing for its members. - // - readonly attribute string id; - // Each Object Group has its own distinct ID. - - void bind (in Member mem) raises (duplicate_member); - // Adds a new <member> to the <Object_Group>. Note that each - // <Member_ID> in an <Object_Group> must be unique. If the - // group already contains a member with the same <Member_ID>, a - // <duplicate_member> exceptions is thrown. - - void unbind (in Member_ID id) raises (no_such_member); - // Removes a member with the specified <Member_ID> from the - // <Object_Group>. If none of the group's members have a - // Member_ID of <id>, <no_such_member> exception is thrown. - - Objref resolve () raises (no_such_member); - // Returns a member object from this <Object_Group> in accordance with - // load balancing policy it implements, i.e., ``random'' or - // ``round robin.'' If the group contains no members, <no_such_member> - // exception is thrown. - - Objref resolve_with_id (in Member_ID id) raises (no_such_member); - // Returns an object with the specified <Member_ID>. If this - // <Object_Group> contains no members with the specified - // <Member_ID>, <no_such_member> exception is thrown. - - Member_ID_List members (); - // Return a sequence of <Member_ID>s of all of its members. - - void destroy (); - // Cleanup the resources associated with this <Object_Group>. - // Subsequent calls to this <Object_Group> should fail, and its - // <id> should become available. <Object_Group_Factory> - // should no longer list this <Object_Group>. - }; -}; diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.cpp b/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.cpp deleted file mode 100755 index f5d171a3b4f..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.cpp +++ /dev/null @@ -1,1013 +0,0 @@ -// $Id$ -#include "Load_Balancer_i.h" -#include "ace/Auto_Ptr.h" -#include "ace/Hash_Map_Manager_T.h" - -const char *rr_name_bind = "RR_Group"; -// Name binding for the location of the Round Robin info in the mem pool - -const char *random_name_bind = "Random_Group"; -// Name binding for the location of the Random info in the mem pool - -const char *flags_name_bind = "FLAGS"; -// Name binding for the location of the flags info in the mem pool - -const char *dll_name_bind = "DLL_LIST"; -// Name binding for the DLL_LIst in the me_pool; - -const char *server_id_name_bind = "server_id"; -// Some cookie that is used for appending names - -Object_Group_Factory_i::Object_Group_Factory_i (CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa) - :orb_ (orb), - poa_ (PortableServer::POA::_duplicate (poa)), - random_groups_ (0), - rr_groups_ (0), - flags_ (0) -{ - ACE_MMAP_Memory_Pool::OPTIONS options (ACE_DEFAULT_BASE_ADDR); - ACE_NEW (this->mem_pool_, - ALLOCATOR ("Mem_Pool", - "Mem_Pool", - &options)); -} - -Object_Group_Factory_i::~Object_Group_Factory_i (void) -{ - delete this->mem_pool_; -} - -PortableServer::POA_ptr -Object_Group_Factory_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - - -Load_Balancer::Object_Group_ptr -Object_Group_Factory_i::make_round_robin (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)) -{ - - if (this->mem_pool_->find (rr_name_bind, - (void *&)this->rr_groups_) == -1) - { - void *hash_map = this->mem_pool_->malloc (sizeof (HASH_MAP)); - ACE_NEW_THROW_EX (this->rr_groups_, - (hash_map) HASH_MAP (this->mem_pool_), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - // Bind it in the mem pool with a name - if (this->mem_pool_->bind (rr_name_bind, - (void *)this->rr_groups_) != 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to bind \n"), - 0); - } - } - - return this->make_group (0, - id - ACE_ENV_ARG_PARAMETER); -} - -void -Object_Group_Factory_i::unbind_round_robin (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)) -{ - if (this->rr_groups_ == 0) - { - if (this->mem_pool_->find (rr_name_bind, - (void *&)this->rr_groups_) == -1) - ACE_THROW (Load_Balancer::no_such_group ()); - } - - char *int_id = 0; - - // Throw an exception if not found in the HASH MAP - if (this->rr_groups_->find (const_cast<char *> (id), - this->mem_pool_) < 0) - ACE_THROW (Load_Balancer::no_such_group ()); - - // Unbind the entry - this->rr_groups_->unbind (const_cast<char *> (id), - int_id, - this->mem_pool_); - - // Free the memory from the pool - this->mem_pool_->free (int_id - (ACE_OS::strlen (id) + 1)); - - // Change the FLAGS variable - if (this->flags_ == 0) - { - if (this->mem_pool_->find (flags_name_bind, - (void *&)this->flags_) == -1) - return; - } - - // Bump down the flags value - --this->flags_; - -} - -Load_Balancer::Object_Group_ptr -Object_Group_Factory_i::make_random (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)) -{ - - if (this->mem_pool_->find (random_name_bind, (void * &)this->random_groups_) == -1) - { - void *hash_map = this->mem_pool_->malloc (sizeof (HASH_MAP)); - - ACE_NEW_THROW_EX (this->random_groups_, - (hash_map) HASH_MAP (this->mem_pool_), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - // Bind it in the mem pool with a name - if (this->mem_pool_->bind (random_name_bind, - (void *)this->random_groups_) != 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to bind \n"), - 0); - } - } - - return this->make_group (1, - id - ACE_ENV_ARG_PARAMETER); -} - - -void -Object_Group_Factory_i::unbind_random (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)) -{ - if (this->random_groups_ == 0) - { - if (this->mem_pool_->find (random_name_bind, - (void *&)this->random_groups_) == -1) - ACE_THROW (Load_Balancer::no_such_group ()); - } - - char *int_id = 0; - - // Throw an exception if not found in the HASH MAP - if (this->random_groups_->find (const_cast<char *> (id), - this->mem_pool_) < 0) - ACE_THROW (Load_Balancer::no_such_group ()); - - // Unbind the entry - this->random_groups_->unbind (const_cast<char *> (id), - int_id, - this->mem_pool_); - - // Free the memory from the pool - this->mem_pool_->free (int_id - (ACE_OS::strlen (id) + 1)); - - // Change the FLAGS variable - if (this->flags_ == 0) - { - if (this->mem_pool_->find (flags_name_bind, - (void *&)this->flags_) == -1) - return; - } - - // Bump down the flags value - this->flags_ -= 2; -} - -Load_Balancer::Object_Group_ptr -Object_Group_Factory_i::make_group (int random, - const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)) -{ - // Store our result here for return. - Load_Balancer::Object_Group_var group; - - // Create an appropriate servant. - Object_Group_i *group_servant = 0; - - // Check to make sure we don't already have a group with the same - // <id>. - - if (random) - { - if (this->random_groups_->find (const_cast<char *> (id), - this->mem_pool_) == 0) - ACE_THROW_RETURN (Load_Balancer::duplicate_group (), - Load_Balancer::Object_Group::_nil ()); - } - else - { - if (this->rr_groups_->find (const_cast<char *> (id), - this->mem_pool_) == 0) - ACE_THROW_RETURN (Load_Balancer::duplicate_group (), - Load_Balancer::Object_Group::_nil ()); - } - - - - // As we are sure that it is not in the list go ahead and insert it - if (random) - ACE_NEW_THROW_EX (group_servant, - Random_Object_Group (id, - this->poa_.in ()), - CORBA::NO_MEMORY ()); - else - ACE_NEW_THROW_EX (group_servant, - RR_Object_Group (id, - this->poa_.in ()), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (group._retn ()); - - // Register with the poa, begin using ref. counting. - group = group_servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (group._retn ()); - - group_servant->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - CORBA::String_var ior = - this->orb_->object_to_string (group.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - - // Calculate and allocate the memory we need to store this name to - // object binding. - size_t id_len = ACE_OS::strlen (id) + 1; - size_t kind_len = ACE_OS::strlen (ior.in ()) + 1; - - char *ptr = (char *) this->mem_pool_->malloc (id_len + kind_len); - - if (ptr == 0) - ACE_THROW_RETURN (CORBA::NO_MEMORY (), - Load_Balancer::Object_Group::_nil ()); - - char * id_ptr = ptr; - char * ior_ptr = ptr + id_len; - - ACE_OS::strcpy (id_ptr, id); - ACE_OS::strcpy (ior_ptr, ior.in ()); - - // Store the results here - CORBA::Long result = 0; - - // Make an entry in appropriate map of groups. - if (random) - { - result = this->random_groups_->bind (id_ptr, - ior_ptr, - this->mem_pool_); - } - else - { - result = this->rr_groups_->bind (id_ptr, - ior_ptr, - this->mem_pool_); - } - - - - // Update the value of flags_ - this->update_flags (random - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - if (result == -1) - { - // For some reason the bind failed. Free our - // dynamically allocated memory. - this->mem_pool_->free ((void *) ptr); - ACE_THROW_RETURN (Load_Balancer::duplicate_group (), - Load_Balancer::Object_Group::_nil ()); - - } - - // Return. - ACE_DEBUG ((LM_DEBUG, "Successfully created new group: %s\n", id)); - - return group._retn (); -} - - -Load_Balancer::Object_Group_ptr -Object_Group_Factory_i::resolve (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)) -{ - - - -#if defined (DOORS_MEASURE_STATS) - // Time the calls - // Record the entry time. - ACE_hrtime_t latency_base = ACE_OS::gethrtime (); - -#endif /*DOORS_MEASURE_STATS*/ - - // It could be that the Load balancing service could have failed - // before the Client tries to invoke this call.. In such a case the - // Service should look in to the MMAP file and read in the info - // before it can resolve the ID sent by the client.. So we check - // whether the class holds the pointer.. If not we look in to the - // MMAP file for the relevant info.. - if (!this->rr_groups_) - { - if (this->mem_pool_->find (rr_name_bind, - (void *&)this->rr_groups_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N|%l) The factory does not have any references ") - ACE_TEXT ("to the group that you have sought \n\n")), - 0); - } - } - - if (!this->random_groups_) - { - if (this->mem_pool_->find (random_name_bind, - (void *&)this->random_groups_) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("(%N|%l) The factory does not have any references ") - ACE_TEXT ("to the group that you have sought \n\n")), - 0); - - } - } - - if (!this->flags_) - { - this->mem_pool_->find (flags_name_bind, - (void *&)this->flags_); - this->update_objects (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - } - - char *ior = 0; - - if (rr_groups_->find (const_cast<char *> (id), - ior, - this->mem_pool_) == -1 - && random_groups_->find (const_cast<char *> (id), - ior, - this->mem_pool_) == -1) - ACE_THROW_RETURN (Load_Balancer::no_such_group (), - 0); - - CORBA::Object_var objref = - this->orb_->string_to_object (ior - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - Load_Balancer::Object_Group_ptr - object_group = Load_Balancer::Object_Group::_narrow (objref.in () - ACE_ENV_ARG_PARAMETER); - - ACE_CHECK_RETURN (Load_Balancer::Object_Group::_nil ()); - - -#if defined (DOORS_MEASURE_STATS) - // Grab timestamp again. - ACE_hrtime_t now = ACE_OS::gethrtime (); - - this->throughput_.sample (0, - now - latency_base); - - ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor (); - ACE_OS::printf ("*=*=*=*=Aggregated result *=*=*=*=*= \n"); - this->throughput_.dump_results ("Aggregated", gsf); - -#endif /*DOORS_MEASURE_STATS*/ - - return object_group; -} - -Load_Balancer::Group_List * -Object_Group_Factory_i::list_groups (int random - ACE_ENV_ARG_DECL) -{ - Load_Balancer::Group_List * list; - - // Figure out the length of the list. - CORBA::ULong len; - if (random) - len = random_groups_->current_size (); - else - len = rr_groups_->current_size (); - - // Allocate the list of <len> length. - ACE_NEW_THROW_EX (list, - Load_Balancer::Group_List (len), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (list); - list->length (len); - - // Create an iterator for group structure to populate the list. - HASH_MAP::ITERATOR *group_iter; - HASH_MAP::ITERATOR random_iter (*(this->random_groups_)); - HASH_MAP::ITERATOR rr_iter (*(this->rr_groups_)); - if (random) - group_iter = &random_iter; - else - group_iter = &rr_iter; - - // Iterate over groups and populate the list. - HASH_MAP::ENTRY *hash_entry = 0; - for (CORBA::ULong i = 0; i < len; i++) - { - group_iter->next (hash_entry); - group_iter->advance (); - - (*list)[i] = ACE_OS::strdup (hash_entry->ext_id_); - } - - return list; -} - -Load_Balancer::Group_List * -Object_Group_Factory_i::round_robin_groups (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return list_groups (0 ACE_ENV_ARG_PARAMETER); -} - -Load_Balancer::Group_List * -Object_Group_Factory_i::random_groups (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return list_groups (1 ACE_ENV_ARG_PARAMETER); -} - - -void -Object_Group_Factory_i::update_flags (int random - ACE_ENV_ARG_DECL) -{ - //First check whether we have memory for flags_ - if (!this->flags_) - { - if (this->mem_pool_->find (flags_name_bind, - (void *&) this->flags_) == -1) - { - void *value = - this->mem_pool_->malloc (sizeof (CORBA::Short)); - ACE_NEW_THROW_EX (this->flags_, - (value) CORBA::Short (0), - CORBA::NO_MEMORY ()); - ACE_CHECK; - - // Initialize the variable - this->mem_pool_->bind (flags_name_bind, - (void *)this->flags_); - } - } - - CORBA::Short val = *(this->flags_); - switch (val) - { - case 0: - if (random) - *(this->flags_) = 2; - else - *(this->flags_) = 1; - break; - case 1: - if (random) - *(this->flags_) = 3; - break; - case 2: - if (!random) - *(this->flags_) = 3; - break; - - } -} - -void -Object_Group_Factory_i::update_objects (ACE_ENV_SINGLE_ARG_DECL) -{ - // Create an appropriate servant. - Object_Group_i * group_servant = 0; - Object_Group_i *group_servant_rep = 0; - - // Check the value of of flags_ & do the instantiation and - // registration - - switch (*(this->flags_)) - { - case 1: - ACE_NEW_THROW_EX (group_servant, - RR_Object_Group ("Round Robin group", - this->poa_.in ()), - CORBA::NO_MEMORY ()); - group_servant->_this (); - break; - - case 2: - ACE_NEW_THROW_EX (group_servant, - Random_Object_Group ("Random group", - this->poa_.in ()), - CORBA::NO_MEMORY ()); - group_servant->_this (); - break; - case 3: - ACE_NEW_THROW_EX (group_servant_rep, - Random_Object_Group ("Random group", - this->poa_.in ()), - CORBA::NO_MEMORY ()); - group_servant_rep->_this (); - - ACE_NEW_THROW_EX (group_servant, - RR_Object_Group ("Round Robin group", - this->poa_.in ()), - CORBA::NO_MEMORY ()); - group_servant->_this (); - break; - } - -} - - -Object_Group_i::Object_Group_i (const char * id, - PortableServer::POA_ptr poa) - :poa_ (PortableServer::POA::_duplicate (poa)), - member_id_list_ (0), - members_ (0), - id_ (id), - allocator_ (0) -{ - - if (!this->allocator_) - { - ACE_MMAP_Memory_Pool::OPTIONS options (ACE_DEFAULT_BASE_ADDR); - ACE_NEW (this->allocator_, - ALLOCATOR ("Mem_Pool", - "Mem_Pool", - &options)); - } -} - - -Object_Group_i::~Object_Group_i (void) -{ - // Need to delete all the items from the member_id_list, to avoid - // memory leaks. - Object_Group_i::ITERATOR iter (*member_id_list_); - - do - { - delete (iter.next ()); - } while (iter.advance ()); - - delete this->allocator_; -} - - -PortableServer::POA_ptr -Object_Group_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return PortableServer::POA::_duplicate (this->poa_.in ()); -} - - -char * -Object_Group_i::id (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return CORBA::string_dup (id_.c_str ()); -} - -void -Object_Group_i::bind (const Load_Balancer::Member & member - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_member)) -{ - - if (this->members_ == 0) - { - ACE_CString id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - id += server_id_name_bind; - - if (this->allocator_->find (id.c_str (), (void *&)this->members_) == -1) - { - void *hash_map = this->allocator_->malloc (sizeof (HASH_MAP)); - ACE_NEW_THROW_EX (this->members_, - (hash_map) HASH_MAP (this->allocator_), - CORBA::NO_MEMORY ()); - ACE_CHECK; - - // Bind it in the mem pool with a name - if (this->allocator_->bind (id.c_str (), - (void *)this->members_) != 0) - { - ACE_ERROR ((LM_ERROR, - "Unable to bind \n")); - - } - } - } - - // Check whether the element already exists.. - if (this->members_->find (const_cast<char *> ((const char *) member.id), - this->allocator_) == 0) - ACE_THROW (Load_Balancer::duplicate_member ()); - - size_t id_len = ACE_OS::strlen (member.id) + 1; - size_t ref_len = ACE_OS::strlen (member.obj) + 1; - - char *mem_alloc = (char *)this->allocator_->malloc (id_len + ref_len); - - if (mem_alloc == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - char **id_ptr = (char **)this->allocator_->malloc (sizeof (char *)); - *id_ptr = mem_alloc; - char *ior_ptr = mem_alloc + id_len; - - ACE_OS::strcpy (*id_ptr, member.id); - ACE_OS::strcpy (ior_ptr, member.obj); - - - // Insert new member into <members_> and check for duplicates/failures. - int result = this->members_->trybind (*id_ptr, - ior_ptr); - - if (result == 1) - ACE_THROW (Load_Balancer::duplicate_member ()); - else if (result == -1) - ACE_THROW (CORBA::INTERNAL ()); - - // Search the list first from the mem mapp pool and then Insert new - // member's id into <member_id_list_>. - - ACE_CString id = dll_name_bind; - id += this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - - if (this->allocator_->find (id.c_str (), - (void *&)this->member_id_list_) - == -1) - { - void *dll_list = this->allocator_->malloc (sizeof (LIST)); - ACE_NEW_THROW_EX (this->member_id_list_, - (dll_list) LIST (this->allocator_), - CORBA::NO_MEMORY ()); - ACE_CHECK; - - // Bind it in the mem pool with a name - if (this->allocator_->bind (id.c_str (), - (void *)this->member_id_list_) != 0) - { - ACE_ERROR ((LM_ERROR, - "Unable to bind \n")); - return; - } - } - - if (member_id_list_->insert_tail (id_ptr) == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // Theoretically, we should deal with memory failures more - // thoroughly. But, practically, the whole system is going to be - // hosed anyways ... -} - -void -Object_Group_i::unbind (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) -{ - // Check whether the this->member_ is NULL - if (this->members_ == 0) - { - ACE_CString id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - id += server_id_name_bind; - - if (this->allocator_->find (id.c_str (), - (void *&)this->members_) == -1) - { - ACE_THROW (Load_Balancer::no_such_member ()); - } - } - // Check to make sure we have it. - if (this->members_->find (const_cast<char *> (id), - this->allocator_) == -1) - ACE_THROW (Load_Balancer::no_such_member ()); - - // Remove all entries for this member. - this->members_->unbind (const_cast<char *> (id), - this->allocator_); - - if (this->member_id_list_ == 0) - { - ACE_CString id = dll_name_bind; - id += this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (this->allocator_->find (id.c_str (), - (void *&)this->member_id_list_) - == -1) - ACE_THROW (Load_Balancer::no_such_member ()); - - } - - - - Object_Group_i::ITERATOR iter (*(this->member_id_list_)); - - while (ACE_OS::strcmp (id,*(iter.next ()))) - iter.advance (); - - this->allocator_->free ((void *) iter.next ()); - - iter.remove (); -} - -char * -Object_Group_i::resolve_with_id (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) -{ - CORBA::String_var ior; - - - if (this->members_->find (const_cast<char *> (id), - ior.out (), this->allocator_) == -1) - ACE_THROW_RETURN (Load_Balancer::no_such_member (), - 0); - - char *retn_ptr = CORBA::string_dup (ior.in ()); - - return retn_ptr; - -} - -Load_Balancer::Member_ID_List * -Object_Group_i::members (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - Load_Balancer::Member_ID_List * list = 0; - - this->read_from_memory (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - // Figure out the length of the list. - CORBA::ULong len = this->members_->current_size (); - - // Allocate the list of <len> length. - ACE_NEW_THROW_EX (list, - Load_Balancer::Member_ID_List (len), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (list); - list->length (len); - - // Create an iterator for <member_id_list_> to populate the list. - Object_Group_i::ITERATOR id_iter (*this->member_id_list_); - - char **item = 0; - // Iterate over groups and populate the list. - for (CORBA::ULong i = 0; i < len; i++) - { - this->member_id_list_->get (item); - (*list)[i] = *(id_iter.next ()); - id_iter.advance (); - } - - return list; -} - -void -Object_Group_i::destroy (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - // Deregister with POA. - PortableServer::POA_var poa = - this->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - PortableServer::ObjectId_var id = - poa->servant_to_id (this - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - poa->deactivate_object (id.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -void -Object_Group_i::read_from_memory (ACE_ENV_SINGLE_ARG_DECL) -{ - // Sanity check needs to be done in all the places - ACE_CString id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (!this->members_) - { - id += server_id_name_bind; - - if (this->allocator_->find (id.c_str (), - (void *&)this->members_) == -1) - { - ACE_ERROR ((LM_ERROR, - "Unable to find tha HASH MAP in the MMAP file \n")); - } - } - - - if (!this->member_id_list_) - { - id = dll_name_bind; - id += this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (this->allocator_->find (id.c_str (), - (void *&)this->member_id_list_) == -1) - { - ACE_ERROR ((LM_ERROR, - "Unable to find tha HASH MAP in the MMAP file \n")); - } - } - -} - - -Random_Object_Group::Random_Object_Group (const char *id, - PortableServer::POA_ptr poa) - : Object_Group_i (id, poa) -{ - // Seed the random number generator. - ACE_OS::srand (ACE_OS::time ()); -} - -char * -Random_Object_Group::resolve (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) -{ - - this->read_from_memory (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - size_t group_size = this->members_->current_size (); - if (group_size == 0) - ACE_THROW_RETURN (Load_Balancer::no_such_member (), - 0); - - // Generate random number in the range [0, group_size - 1] - size_t member = ACE_OS::rand() % group_size; - - // Get the id of the member to return to the client. - char **id = 0; - this->member_id_list_->get (id, member); - ACE_DEBUG ((LM_DEBUG, "In Random Group resolved to: %s\n", - *id)); - - // Return the object reference corresponding to the found id to the - // client. - char *objref = 0; - this->members_->find (*id, - objref, - this->allocator_); - char *string_ptr = CORBA::string_dup (objref); - return string_ptr; -} - -RR_Object_Group::RR_Object_Group (const char *id, - PortableServer::POA_ptr poa) - : Object_Group_i (id, poa), - next_ (0) -{ -} - -char * -RR_Object_Group::resolve (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) -{ - char *objref = 0; - - this->read_from_memory (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - size_t group_size = this->members_->current_size (); - if (group_size == 0) - ACE_THROW_RETURN (Load_Balancer::no_such_member (), - 0); - - // Get the id of the member to return to the client. - char **id = 0; - this->member_id_list_->get (id, next_); - ACE_DEBUG ((LM_DEBUG, - "In RR Group resolved to: %s\n", *id)); - - // Adjust <next_> for the next invocation. - next_ = (next_ + 1) % group_size; - - - // Return the object reference corresponding to the found id to the client. - if (this->members_->find (*id, - objref, - this->allocator_) == -1) - ACE_THROW_RETURN (CORBA::INTERNAL (), - 0); - - char *retn_ptr = CORBA::string_dup (objref); - - return retn_ptr; -} - -void -RR_Object_Group::unbind (const char *id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) -{ - - if (this->members_ == 0) - { - ACE_CString id = this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - id += server_id_name_bind; - - if (this->allocator_->find (id.c_str (), - (void *&)this->members_) == -1) - { - ACE_THROW (Load_Balancer::no_such_member ()); - } - } - - // Check to make sure we have it. - if (this->members_->find (const_cast<char *> (id), - this->allocator_) == -1) - ACE_THROW (Load_Balancer::no_such_member ()); - - // Remove all entries for this member. - this->members_->unbind (const_cast<char *> (id), - this->allocator_); - - // As we remove the id from the <member_id_list>, we note the - // position of the id in the list. - if (this->member_id_list_ == 0) - { - ACE_CString id = dll_name_bind; - id += this->id (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (this->allocator_->find (id.c_str (), - (void *&)this->member_id_list_) - == -1) - ACE_THROW (Load_Balancer::no_such_member ()); - - } - - size_t position = 0; - Object_Group_i::ITERATOR iter (*member_id_list_); - while (ACE_OS::strcmp (id ,*(iter.next ()))) - { - iter.advance (); - position++; - } - this->allocator_->free (iter.next ()); - iter.remove (); - - size_t curr_size = this->members_->current_size (); - - // Update <next_> if necessary to reflect the deletion. - if (position < next_) - this->next_--; - else if (curr_size == 0) - this->next_ = 0; - else if (position == next_) - this->next_ = next_ % (this->members_->current_size ()); -} - diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.h b/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.h deleted file mode 100755 index 119c2ccb0e0..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancer_i.h +++ /dev/null @@ -1,348 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ -// ============================================================================ -// -// = FILENAME -// Load_Balancer_i.h -// -// = DESCRIPTION -// Defines classes that implement interfaces in Load_Balancer.idl -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ - -#ifndef LOAD_BALANCER_I_H_ -#define LOAD_BALANCER_I_H_ - -#include "Load_BalancerS.h" -#include "ace/Hash_Map_With_Allocator_T.h" -#include "ace/SString.h" -#include "ace/Synch.h" -#include "ace/Containers.h" -#include "ace/Stats.h" -#include "ace/High_Res_Timer.h" -#include "ace/Memory_Pool.h" -#include "ace/Malloc_T.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -typedef ACE_Allocator_Adapter <ACE_Malloc<ACE_MMAP_MEMORY_POOL, - TAO_SYNCH_MUTEX> > ALLOCATOR; - -typedef ACE_Hash_Map_With_Allocator<char *, char *> HASH_MAP; - -class Object_Group_Factory_i : - public virtual POA_Load_Balancer::Object_Group_Factory -{ - // = TITLE - // This class implements Load_Balancer::Object_Group_Factory idl - // interface. - // - // = DESCRIPTION - // This implementation uses two <ACE_Hash_Map_Manager>s - // to store <Group_ID> to <Object_Group> associations for all - // load balancing groups created by this factory (one map keeps - // track of all random groups, and the other keeps track of all - // round robin groups). - // -public: - - // = Initialization and termination methods. - - Object_Group_Factory_i (CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa); - // Constructor. - - ~Object_Group_Factory_i (void); - // Destructor. - - - PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Method for the POA that will return the persistent POA_ptr stored - // in here.. - - // = Load_Balancer::Object_Group_Factory idl methods. - - Load_Balancer::Object_Group_ptr make_round_robin (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)); - // Creates an <Object_Group> that resolves requests for arbitrary - // members in round robin order. If an <Object_Group>, of any - // type, with Group_ID <id> has already been created by this - // factory, and hasn't been destroyed, a <duplicate_group> - // exception is thrown. - - void unbind_round_robin (const char *id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)); - - - Load_Balancer::Object_Group_ptr make_random (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)); - // Creates an <Object_Group> that resolves requests for arbitrary - // members in random order. If an <Object_Group>, of any - // type, with Group_ID <id> has already been created by this - // factory, and hasn't been destroyed, a <duplicate_group> - // exception is thrown. - - void unbind_random (const char *id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)); - - Load_Balancer::Object_Group_ptr resolve (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_group)); - // Locates and returns an <Object_Group IOR> by its <Group_ID>. If - // no <Object_Group> has <Group_ID> of <id>, throw a - // <no_such_group> exception. - - Load_Balancer::Group_List * round_robin_groups (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Lists all the round robin <Object_Group>s which were created - // by this factory, and haven't been destroyed yet, i.e., return - // a sequence of <Group_ID>s of all existing round robin - // <Object_Group>s created by this factory. - - Load_Balancer::Group_List * random_groups (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Lists all the random <Object_Group>s which were created - // by this factory, and haven't been destroyed yet, i.e., return - // a sequence of <Group_ID>s of all existing random - // <Object_Group>s created by this factory. - -private: - - CORBA::ORB_var orb_; - // Our ORB - - PortableServer::POA_var poa_; - // Our POA - - // = Helper methods. - - Load_Balancer::Object_Group_ptr make_group (int random, - const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_group)); - // This function factors out common code in <make_round_robin> and - // <make_random>. Creates a random <Object_Group> if <random> parameter is - // set to 1 and round robin <Object_Group> if it is 0. - - Load_Balancer::Group_List * list_groups (int random - ACE_ENV_ARG_DECL); - // This function factors out common code in <random_groups> and - // <round_robin_groups>. Returns a sequence of its random - // groups if <random> parameter is set to 1 and a sequence of its - // round robin groups if it is 0. - - void update_flags (int random - ACE_ENV_ARG_DECL); - // The helper that updates the vlaue of the variable flags_ - - void update_objects (ACE_ENV_SINGLE_ARG_DECL); - // This rolls back the status of the objects in the POA if the - // service had failed.. - - HASH_MAP *random_groups_; - // Map containing all random <Object_Group>s created by this factory. - - HASH_MAP *rr_groups_; - // Map containing all round robin <Object_Group>s created by this factory. - - ALLOCATOR *mem_pool_; - // Memory pool that will have the data - - CORBA::Short *flags_; - // This would be kind of a hack.. As I am not able to think of - // anything at present let us live with this.. OK.. Here is how it - // works.. This value will be stored in the MMAP file. If the value - // is 1 then the Round Robin group object is registered with the - // Services POA. If the value is 2 then the Random group object is - // registered with the POA. If the value is 3 both of them are - // registered with the POA.. The initial value would be 0 when this - // object initialises and binded as "FLAGS".. - - ACE_Throughput_Stats throughput_; - -}; - -class Object_Group_i - : public virtual POA_Load_Balancer::Object_Group - -{ - // = TITLE - // This abstract class partially implements - // Load_Balancer::Object_Group idl interface. - // - // = DESCRIPTION - // <Resolve> is the only abstract method - subclasses should - // define it in order to implement an appropriate load balancing - // policy. Other methods can be overridden as needed. This class - // factors out code common to <Object_Group> implementations with - // different load balancing policies. - // -public: - - // = Initialization and termination methods. - - Object_Group_i (const char * id, - PortableServer::POA_ptr poa); - // Constructor. - - ~Object_Group_i (void); - // Destructor. - - // Persistent POA - // Method for the POA - PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - - // = Load_Balancer::Object_Group idl methods. - - char * id (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Get group's id. - - void bind (const Load_Balancer::Member & member - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::duplicate_member)); - // Adds a new <member> to the <Object_Group>. Note that each - // <Member_ID> in an <Object_Group> must be unique. If the - // group already contains a member with the same <Member_ID>, a - // <duplicate_member> exceptions is thrown. - - void unbind (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)); - // Removes a member with the specified <Member_ID> from the - // <Object_Group>. If none of the group's members have a - // Member_ID of <id>, <no_such_member> exception is thrown. - - char * resolve (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)) = 0; - // Returns a member object from this <Object_Group> in accordance with - // load balancing policy it implements, i.e., ``random'' or - // ``round robin.'' If the group contains no members, <no_such_member> - // exception is thrown. - - char * resolve_with_id (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)); - // Returns an object with the specified <Member_ID>. If this - // <Object_Group> contains no members with the specified - // <Member_ID>, <no_such_member> exception is thrown. - - Load_Balancer::Member_ID_List * members (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Return a sequence of <Member_ID>s of all of its members. - - void destroy (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)); - // Cleanup the resources associated with this <Object_Group>. - // Subsequent calls to this <Object_Group> should fail, and its - // <id> should become available. <Object_Group_Factory> - // should no longer list this <Object_Group>. - -protected: - - void read_from_memory (ACE_ENV_SINGLE_ARG_DECL_NOT_USED); - // This will replenish all the pointers that could have been lost - // because of failure - - PortableServer::POA_var poa_; - // Our POA - - typedef ACE_DLList<char *> LIST; - typedef ACE_DLList_Iterator<char *> ITERATOR; - // Typedefs for ease of use. - - LIST *member_id_list_; - // List of ids of all the members of this group. - - HASH_MAP *members_; - // Mapping of member_id to obj for all the members of this group. - - // Note, we store information redundantly in this implementation, - // i.e., both <member_id_list_> and <members_> store member ids. - // However, this redundancy eases/speeds up the implementation of - // certain operations. <member_id_list_> is useful for implementing - // variations of <resolve> method to implement different policies. - // <members_> is useful for doing id-based look-up. - - ACE_CString id_; - // This group's id. - - ALLOCATOR *allocator_; - // Pointer to the location where I can allocate memory... -}; - - -class Random_Object_Group : public Object_Group_i -{ - // = TITLE - // This class implements <Object_Group> idl interface with the - // random policy for <resolve>. - // -public: - Random_Object_Group (const char *id, - PortableServer::POA_ptr poa); - // Constructor. - - char * resolve (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)); - // Returns a member object from this <Object_Group> in accordance with - // the "random" load balancing policy. - -}; - -class RR_Object_Group: public Object_Group_i -{ - // = TITLE - // This class implements <Object_Group> idl interface with the - // round robin policy for <resolve>. - // -public: - - RR_Object_Group (const char *id, - PortableServer::POA_ptr poa); - // Constructor. - - void unbind (const char * id - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)); - // We need to override the implementation of <unbind> from - // Object_Group_i to make sure <resolve> - // works correctly. - - char * resolve (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - Load_Balancer::no_such_member)); - // Returns a member object from this <Object_Group> in accordance with - // the "round robin" load balancing policy. - -private: - - size_t next_; - // Index into the Object_Group_i::member_id_list_: keeps track of - // the member_id to return on the next invocation of <resolve>. -}; - -#endif /* LOAD_BALANCER_I_H_ */ diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.cpp b/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.cpp deleted file mode 100755 index ec94198bcc1..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// $Id$ -// ============================================================================ -// -// = LIBRARY -// TAO/examples/Load_Balancing -// -// = FILENAME -// Load_Balancing_Service.cpp -// -// = AUTHOR -// Marina Spivak <marina@cs.wustl.edu> -// -// ============================================================================ - -#include "Load_Balancing_Service.h" -#include "Load_Balancer_i.h" -#include "tao/debug.h" -#include "ace/Get_Opt.h" -#include "ace/OS_NS_stdio.h" - -Load_Balancing_Service::Load_Balancing_Service (void) - : ior_output_file_ (0) -{ -} - -int -Load_Balancing_Service::parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opts (argc, argv, "do:"); - int c; - - while ((c = get_opts ()) != -1) - switch (c) - { - case 'd': // debug flag. - TAO_debug_level++; - break; - case 'o': // outputs object ior to the specified file. - this->ior_output_file_ = - ACE_OS::fopen (get_opts.opt_arg (), "w"); - - if (this->ior_output_file_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to open %s for writing: %p\n", - get_opts.opt_arg ()), -1); - break; - case '?': - default: - ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s" - " [-d]" - " [-o] <ior_output_file>" - "\n", - argv [0]), - -1); - } - - // Indicates successful parsing of command line. - return 0; -} - -int -Load_Balancing_Service::init (int argc, - char* argv[]) -{ - int result; - CORBA::String_var ior; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = this->orb_manager_.init (argc, - argv - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (result == -1) - return result; - - // Check the non-ORB arguments. - result = this->parse_args (argc, argv); - if (result < 0) - return result; - - - CORBA::PolicyList policies (2); - policies.length (2); - - // Lifespan policy - policies[0] = - this->orb_manager_.root_poa()->create_lifespan_policy (PortableServer::PERSISTENT - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - policies[1] = - this->orb_manager_.root_poa()->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - PortableServer::POA_var persistent_POA = - this->orb_manager_.root_poa()->create_POA ("persistent", - this->orb_manager_.poa_manager (), - policies - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - - // Destroy policy objects - for (CORBA::ULong i = 0; - i < policies.length (); - ++i) - { - policies[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - - // Create, ref. count, and activate the servant. - Object_Group_Factory_i * factory_servant; - ACE_NEW_RETURN (factory_servant, - Object_Group_Factory_i (this->orb_manager_.orb (), - persistent_POA.in ()), - -1); - - // Activate the POA manager - //PortableServer::ServantBase_var s = factory_servant; - this->orb_manager_.activate_poa_manager (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - CORBA::Object_var objref = factory_servant->_this (); - - ior = this->orb_manager_.orb ()->object_to_string (objref.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - if (ior.in () == 0) - return -1; - else if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - "Object Group Factory ior: %s\n", - ior.in ())); - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Load_Balancing_Service::init"); - return -1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (-1); - - if (this->ior_output_file_ != 0) - { - ACE_OS::fprintf (this->ior_output_file_, - "%s", - ior.in ()); - ACE_OS::fclose (this->ior_output_file_); - } - return 0; -} - - - -int -Load_Balancing_Service::run (ACE_ENV_SINGLE_ARG_DECL) -{ - int result; - - result = this->orb_manager_.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - return result; -} - -Load_Balancing_Service::~Load_Balancing_Service (void) -{ -} - -int -main (int argc, char *argv[]) -{ - int result = 0; - Load_Balancing_Service factory; - - if (factory.init (argc, argv) == -1) - return 1; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - result = factory.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Load_Balancing_Service"); - return 1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (1); - - if (result == -1) - return 1; - else - return 0; -} diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.h b/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.h deleted file mode 100755 index 0ea8c460e6d..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancing_Service.h +++ /dev/null @@ -1,61 +0,0 @@ -// $Id$ -// -*- C++ -*- - -// ============================================================================ -// -// = LIBRARY -// TAO/examples/Load_Balancing -// -// = FILENAME -// Load_Balancing_Service.h -// -// = DESCRIPTION -// Driver for Load Balancing service. -// -// = AUTHORS -// Marina Spivak <marina@cs.wustl.edu> -// with modifications by Bala Natarajan <bala@cs.wustl.edu> -// ============================================================================ - -#ifndef LOAD_BALANCING_SERVICE_H_ -#define LOAD_BALANCING_SERVICE_H_ - -#include "tao/Utils/ORB_Manager.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -class Load_Balancing_Service -{ - // =TITLE - // Server, which creates and initializes a - // <Load_Balancer::Object_Group_Factory> - // object, and runs the orb loop. -public: - - Load_Balancing_Service (void); - // Default constructor. - - ~Load_Balancing_Service (void); - // Destructor. - - int init (int argc, char *argv[]); - // Initialize the <Load_Balancing_Service>: initializes the ORB, parses - // arguments, creates a servant ... - - int run (ACE_ENV_SINGLE_ARG_DECL); - // Run the server. - -private: - int parse_args (int argc, char *argv[]); - // Parses the commandline arguments. - - TAO_ORB_Manager orb_manager_; - // The ORB manager. - - FILE *ior_output_file_; - // File to output the <Object_Group_Factory> IOR. -}; - -#endif /* LOAD_BALANCING_SERVICE_H_ */ diff --git a/TAO/examples/Load_Balancing_persistent/Load_Balancing_persistent.mpc b/TAO/examples/Load_Balancing_persistent/Load_Balancing_persistent.mpc deleted file mode 100644 index 746dfa9c23a..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Load_Balancing_persistent.mpc +++ /dev/null @@ -1,58 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project(*IDL): taoidldefaults { - IDL_Files { - Identity.idl - Load_Balancer.idl - } - custom_only = 1 -} - -project(*balancer): taoexe, utils, portableserver, minimum_corba { - avoids += repo ace_for_tao - exename = load_balancer - after += *IDL - - IDL_Files { - } - - Source_Files { - Load_BalancerC.cpp - Load_BalancerS.cpp - Load_Balancer_i.cpp - Load_Balancing_Service.cpp - } -} - -project(*server): taoserver, utils, minimum_corba { - avoids += repo - exename = server - after += *IDL - - IDL_Files { - } - - Source_Files { - IdentityC.cpp - IdentityS.cpp - Load_BalancerC.cpp - Identity_Server.cpp - Identity_i.cpp - } -} - -project(*client): taoclient, utils, portableserver, minimum_corba { - avoids += repo - exename = client - after += *IDL - - IDL_Files { - } - - Source_Files { - IdentityC.cpp - Load_BalancerC.cpp - Identity_Client.cpp - } -} diff --git a/TAO/examples/Load_Balancing_persistent/Makefile.am b/TAO/examples/Load_Balancing_persistent/Makefile.am deleted file mode 100644 index f0f70c2e5a0..00000000000 --- a/TAO/examples/Load_Balancing_persistent/Makefile.am +++ /dev/null @@ -1,180 +0,0 @@ -## Process this file with automake to create Makefile.in -## -## $Id$ -## -## This file was generated by MPC. Any changes made directly to -## this file will be lost the next time it is generated. -## -## MPC Command: -## ../bin/mwc.pl -type automake -noreldefs TAO.mwc - -ACE_BUILDDIR = $(top_builddir)/.. -ACE_ROOT = $(top_srcdir)/.. -TAO_BUILDDIR = $(top_builddir) -TAO_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl -TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl -TAO_IDLFLAGS = -Ge 1 -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/gperf -TAO_ROOT = $(top_srcdir) - -noinst_PROGRAMS = - -## Makefile.Load_Balancing_Persistent_IDL.am - -BUILT_SOURCES = \ - IdentityC.cpp \ - IdentityC.h \ - IdentityC.inl \ - IdentityS.cpp \ - IdentityS.h \ - IdentityS.inl - -CLEANFILES = \ - Identity-stamp \ - IdentityC.cpp \ - IdentityC.h \ - IdentityC.inl \ - IdentityS.cpp \ - IdentityS.h \ - IdentityS.inl - -IdentityC.cpp IdentityC.h IdentityC.inl IdentityS.cpp IdentityS.h IdentityS.inl: Identity-stamp - -Identity-stamp: $(srcdir)/Identity.idl $(TAO_IDL_DEP) - $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/Identity.idl - @touch $@ - -BUILT_SOURCES += \ - Load_BalancerC.cpp \ - Load_BalancerC.h \ - Load_BalancerC.inl \ - Load_BalancerS.cpp \ - Load_BalancerS.h \ - Load_BalancerS.inl - -CLEANFILES += \ - Load_Balancer-stamp \ - Load_BalancerC.cpp \ - Load_BalancerC.h \ - Load_BalancerC.inl \ - Load_BalancerS.cpp \ - Load_BalancerS.h \ - Load_BalancerS.inl - -Load_BalancerC.cpp Load_BalancerC.h Load_BalancerC.inl Load_BalancerS.cpp Load_BalancerS.h Load_BalancerS.inl: Load_Balancer-stamp - -Load_Balancer-stamp: $(srcdir)/Load_Balancer.idl $(TAO_IDL_DEP) - $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/Load_Balancer.idl - @touch $@ - - -noinst_HEADERS = \ - Identity.idl \ - Load_Balancer.idl - -## Makefile.Load_Balancing_Persistent_Balancer.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_MINIMUM_CORBA -if !BUILD_REPO - -noinst_PROGRAMS += load_balancer - -load_balancer_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -I$(TAO_ROOT) \ - -I$(TAO_BUILDDIR) - -load_balancer_SOURCES = \ - Load_BalancerC.cpp \ - Load_BalancerS.cpp \ - Load_Balancer_i.cpp \ - Load_Balancing_Service.cpp \ - Load_Balancer_i.h \ - Load_Balancing_Service.h - -load_balancer_LDADD = \ - $(TAO_BUILDDIR)/tao/libTAO_Utils.la \ - $(TAO_BUILDDIR)/tao/libTAO_PI.la \ - $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ - $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ - $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ - $(TAO_BUILDDIR)/tao/libTAO.la \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_REPO -endif !BUILD_MINIMUM_CORBA -endif !BUILD_ACE_FOR_TAO - -## Makefile.Load_Balancing_Persistent_Client.am - -if !BUILD_MINIMUM_CORBA -if !BUILD_REPO - -noinst_PROGRAMS += client - -client_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -I$(TAO_ROOT) \ - -I$(TAO_BUILDDIR) - -client_SOURCES = \ - IdentityC.cpp \ - Identity_Client.cpp \ - Load_BalancerC.cpp \ - Identity_Client.h - -client_LDADD = \ - $(TAO_BUILDDIR)/tao/libTAO_Utils.la \ - $(TAO_BUILDDIR)/tao/libTAO_PI.la \ - $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ - $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ - $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ - $(TAO_BUILDDIR)/tao/libTAO.la \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_REPO -endif !BUILD_MINIMUM_CORBA - -## Makefile.Load_Balancing_Persistent_Server.am - -if !BUILD_MINIMUM_CORBA -if !BUILD_REPO - -noinst_PROGRAMS += server - -server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -I$(TAO_ROOT) \ - -I$(TAO_BUILDDIR) - -server_SOURCES = \ - IdentityC.cpp \ - IdentityS.cpp \ - Identity_Server.cpp \ - Identity_i.cpp \ - Load_BalancerC.cpp \ - Identity_Server.h \ - Identity_i.h - -server_LDADD = \ - $(TAO_BUILDDIR)/tao/libTAO_Utils.la \ - $(TAO_BUILDDIR)/tao/libTAO_PI.la \ - $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ - $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ - $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ - $(TAO_BUILDDIR)/tao/libTAO.la \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_REPO -endif !BUILD_MINIMUM_CORBA - -## Clean up template repositories, etc. -clean-local: - -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* - -rm -f gcctemp.c gcctemp so_locations *.ics - -rm -rf cxx_repository ptrepository ti_files - -rm -rf templateregistry ir.out - -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/TAO/examples/Load_Balancing_persistent/README b/TAO/examples/Load_Balancing_persistent/README deleted file mode 100755 index df36a00bb81..00000000000 --- a/TAO/examples/Load_Balancing_persistent/README +++ /dev/null @@ -1,35 +0,0 @@ -AIM: ---- - -This is an extension of the Load_Balancing_Service example in -$TAO_ROOT/examples/Load_Balancing. The aim of this example is to show -a methodology to preserve the state of the service. Here, the service -stores the object reference of multiple copies of servers registered, -so that load can be balanced among the registered servers. If the load -balancing service fails, the references of the servers registered, is -read from the persistent storage and can be used to satisfy the -clients request. The core functionality is not much different from -that of the normal Load_Balancing_Service in -$TAO_ROOT/examples/Load_Balancing. - -Usage: ------ -The service is started as follows - -$./load_balancer -ORBEndPoint iiop://localhost:10016 -o filename - -The server is started as follows - -$./server -i file://filename -ORBEndPoint iiop://localhost:10007 - -and the client is started as follows - -$./client -i file://filename [-r] - -Now, the user can kill the service & restart the service. If the -client is restarted, everything should work fine as before. - -PS: -The code contains some MACROS like DOORS_MEASURE_STATS. They have been -added for the performance measurements that were performed on this -application. |