diff options
Diffstat (limited to 'TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp')
-rw-r--r-- | TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp b/TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp index 0a4e2d99852..271e66b1c60 100644 --- a/TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp +++ b/TAO/orbsvcs/LoadBalancer/LoadBalancer.cpp @@ -2,11 +2,22 @@ // $Id$ +#include "LoadBalancer.h" +#include "ace/Get_Opt.h" + ACE_RCSID(LoadBalancer, LoadBalancer, "$Id$") TAO_LoadBalancer::TAO_LoadBalancer (void) + : interface_repository_id_ ("IDL:CORBA/Object:1.0"), + load_balancer_file_ ("lb.ior"), + balancer_ (0) +{ +} + +TAO_LoadBalancer::~TAO_LoadBalancer (void) { + // @@ } void @@ -14,7 +25,7 @@ TAO_LoadBalancer::parse_args (int argc, char *argv[], CORBA::Environment &ACE_TRY_ENV) { - ACE_Get_Opt get_opts (argc, argv, "o:h"); + ACE_Get_Opt get_opts (argc, argv, "i:o:h"); int c = 0; @@ -22,26 +33,19 @@ TAO_LoadBalancer::parse_args (int argc, { switch (c) { - case 'o': // Write the Load Balancer IOR to the specified file. - this->ior_file_ = - ACE_OS::fopen (get_opts.optarg, "w"); - - if (this->ior_file_ == 0) - { - ACE_ERROR ((LM_ERROR, - "Unable to open %s for writing: %p\n", - get_opts.optarg)); - ACE_THROW (CORBA::UNKNOWN ()); - } - + case 'i': + this->interface_repository_id_ = get_opts.optarg; + break; + case 'o': + this->load_balancer_file_ = get_opts.optarg; break; case 'h': - this->usage (); + this->usage (argv[0]); break; default: - this->usage (); + this->usage (argv[0]); ACE_THROW (CORBA::BAD_PARAM ()); } } @@ -60,21 +64,13 @@ TAO_LoadBalancer::init (int argc, this->orb_->resolve_initial_references ("RootPOA", ACE_TRY_ENV); ACE_CHECK; - if (CORBA::is_nil (poa.in ())) - { - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("(%P|%t) Unable to initialize the ") - ASYS_TEXT ("POA.\n"))); - ACE_CHECK; - } - // Get the POA object. this->root_poa_ = PortableServer::POA::_narrow (poa.in (), ACE_TRY_ENV); ACE_CHECK; // Get the POA_Manager. - PortableServer::POAManager_var poa_manager = + PortableServer::POAManager_var poa_manager = this->root_poa_->the_POAManager (ACE_TRY_ENV); ACE_CHECK; @@ -86,26 +82,31 @@ TAO_LoadBalancer::init (int argc, ACE_CHECK; // Initialize the LoadBalancer servant. - this->load_balancer_impl_.init (ACE_TRY_ENV); + ACE_NEW (this->balancer_, + LoadBalancer_Impl (this->interface_repository_id_, + &this->round_robin_)); + + CORBA::Object_var obj = + this->balancer_->_this (ACE_TRY_ENV); ACE_CHECK; - if (this->ior_output_file_ != 0) - { - CORBA::String_var str = - this->my_naming_server_.naming_service_ior (); - ACE_OS::fprintf (this->ior_output_file_, - "%s", - str.in ()); - ACE_OS::fclose (this->ior_output_file_); - } + CORBA::String_var str = + this->orb_->object_to_string (obj.in (), ACE_TRY_ENV); + ACE_CHECK; + + FILE *lb_ior = ACE_OS::fopen (this->load_balancer_file_, "w"); + ACE_OS::fprintf (lb_ior, "%s", str.in ()); + ACE_OS::fclose (lb_ior); } void -TAO_LoadBalancer::usage (void) const +TAO_LoadBalancer::usage (const char *cmd) const { ACE_DEBUG ((LM_INFO, ASYS_TEXT ("Usage: %s ") + ASYS_TEXT ("-i <interface_repo_id> ") ASYS_TEXT ("-o <ior_output_file> ") + ASYS_TEXT ("-h ") ASYS_TEXT ("\n"), - argv [0])); + cmd)); } |