CosNotify_Service.cpp

Go to the documentation of this file.
00001 // CosNotify_Service.cpp,v 1.18 2006/03/16 15:53:36 sjiang Exp
00002 
00003 #include "orbsvcs/Notify/CosNotify_Service.h"
00004 #include "orbsvcs/Notify/Properties.h"
00005 #include "orbsvcs/Notify/Default_Factory.h"
00006 #include "orbsvcs/Notify/Builder.h"
00007 #include "ace/Sched_Params.h"
00008 #include "ace/Arg_Shifter.h"
00009 #include "ace/Dynamic_Service.h"
00010 #include "tao/ORB_Core.h"
00011 #include "orbsvcs/NotifyExtC.h"
00012 #include "tao/debug.h"
00013 
00014 ACE_RCSID (Notify,
00015            TAO_CosNotify_Service,
00016            "CosNotify_Service.cpp,v 1.18 2006/03/16 15:53:36 sjiang Exp")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 TAO_CosNotify_Service::TAO_CosNotify_Service (void)
00021 {
00022 }
00023 
00024 TAO_CosNotify_Service::~TAO_CosNotify_Service ()
00025 {
00026 }
00027 
00028 int
00029 TAO_CosNotify_Service::init (int argc, ACE_TCHAR *argv[])
00030 {
00031   ACE_Arg_Shifter arg_shifter (argc, argv);
00032 
00033   const ACE_TCHAR *current_arg = 0;
00034 
00035   // Default to an all reactive system.
00036   int ec_threads = 0;
00037   int consumer_threads = 0;
00038   int supplier_threads = 0;
00039 
00040   int task_per_proxy = 0;
00041 
00042   TAO_Notify_Properties *properties = TAO_Notify_PROPERTIES::instance();
00043 
00044   while (arg_shifter.is_anything_left ())
00045     {
00046       if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-MTDispatching")) == 0)
00047         {
00048           arg_shifter.consume_arg ();
00049           ACE_DEBUG ((LM_DEBUG,
00050                       ACE_TEXT ("(%P|%t) The -MTDispatching option has been deprecated, use -DispatchingThreads \n")));
00051         }
00052       else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-DispatchingThreads"))))
00053         {
00054           consumer_threads += ACE_OS::atoi (current_arg);
00055           arg_shifter.consume_arg ();
00056         }
00057       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-MTSourceEval")) == 0)
00058         {
00059           arg_shifter.consume_arg ();
00060           ACE_DEBUG ((LM_DEBUG,
00061                       ACE_TEXT ("(%P|%t) The -MTSourceEval option has been deprecated, use -SourceThreads \n")));
00062         }
00063       else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-SourceThreads"))))
00064         {
00065           supplier_threads += ACE_OS::atoi (current_arg);
00066           arg_shifter.consume_arg ();
00067         }
00068       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-MTLookup")) == 0)
00069         {
00070           arg_shifter.consume_arg ();
00071           ACE_DEBUG ((LM_DEBUG,
00072                       ACE_TEXT ("(%P|%t) The -MTLookup option has been deprecated, use -SourceThreads \n")));
00073         }
00074       else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-LookupThreads"))))
00075         {
00076           supplier_threads += ACE_OS::atoi (current_arg);
00077           arg_shifter.consume_arg ();
00078           ACE_DEBUG ((LM_DEBUG,
00079                       ACE_TEXT ("(%P|%t) The -LookupThreads option has been deprecated, use -SourceThreads \n")));
00080         }
00081       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-MTListenerEval")) == 0)
00082         {
00083           arg_shifter.consume_arg ();
00084           ACE_DEBUG ((LM_DEBUG,
00085                       ACE_TEXT ("(%P|%t) The -MTListenerEval option has been deprecated, use -DispatchingThreads \n")));
00086         }
00087       else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ListenerThreads"))))
00088         {
00089           // Since this option is always added to consumer_threads, we'll
00090           // deprecate it in favor of that option.
00091           ACE_DEBUG ((LM_DEBUG,
00092                       ACE_TEXT ("(%P|%t) The -ListenerThreads option has been deprecated, use -DispatchingThreads \n")));
00093           consumer_threads += ACE_OS::atoi (current_arg);
00094           arg_shifter.consume_arg ();
00095         }
00096       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-AsynchUpdates")) == 0)
00097         {
00098           arg_shifter.consume_arg ();
00099 
00100           properties->asynch_updates (1);
00101         }
00102       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-NoUpdates")) == 0)
00103         {
00104           arg_shifter.consume_arg ();
00105 
00106           properties->updates (0);
00107         }
00108       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-AllocateTaskperProxy")) == 0)
00109         {
00110           task_per_proxy = 1;
00111           arg_shifter.consume_arg ();
00112         }
00113       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-AllowReconnect")) == 0)
00114       {
00115         arg_shifter.consume_arg ();
00116         TAO_Notify_PROPERTIES::instance()->allow_reconnect (true);
00117       }
00118       else
00119       {
00120         ACE_ERROR ((LM_ERROR,
00121                     ACE_TEXT ("(%P|%t) Ignoring unknown option for Notify Factory: %s\n"),
00122                     arg_shifter.get_current()
00123           ));
00124         arg_shifter.consume_arg ();
00125       }
00126     }
00127 
00128   // Init the EC QoS
00129   {
00130     CosNotification::QoSProperties qos;
00131     this->set_threads (qos, ec_threads);
00132     properties->default_event_channel_qos_properties (qos);
00133   }
00134 
00135   if (task_per_proxy == 0)
00136     {
00137       // Set the per ConsumerAdmin QoS
00138       {
00139         if (consumer_threads > 0)
00140           ACE_DEBUG((LM_DEBUG, "Using %d threads for each ConsumerAdmin.\n", consumer_threads));
00141         CosNotification::QoSProperties qos;
00142         this->set_threads (qos, consumer_threads);
00143         properties->default_consumer_admin_qos_properties (qos);
00144       }
00145 
00146       // Set the per SupplierAdmin QoS
00147       {
00148         if (supplier_threads > 0)
00149           ACE_DEBUG((LM_DEBUG, "Using %d threads for each SupplierAdmin.\n", supplier_threads));
00150         CosNotification::QoSProperties qos;
00151         this->set_threads (qos, supplier_threads);
00152         properties->default_supplier_admin_qos_properties (qos);
00153       }
00154     }
00155   else
00156     {
00157       // Set the per ProxyConsumer QoS
00158       {
00159         if (supplier_threads > 0)
00160           ACE_DEBUG((LM_DEBUG, "Using %d threads for each Supplier.\n", supplier_threads));
00161         CosNotification::QoSProperties qos;
00162         this->set_threads (qos, supplier_threads); // lookup thread per proxy doesn't make sense.
00163         properties->default_proxy_consumer_qos_properties (qos);
00164       }
00165 
00166       // Set the per ProxySupplier QoS
00167       {
00168         if (consumer_threads > 0)
00169           ACE_DEBUG((LM_DEBUG, "Using %d threads for each Consumer.\n", consumer_threads));
00170         CosNotification::QoSProperties qos;
00171         this->set_threads (qos, consumer_threads);
00172         properties->default_proxy_supplier_qos_properties (qos);
00173       }
00174     }
00175 
00176   return 0;
00177 }
00178 
00179 void
00180 TAO_CosNotify_Service::set_threads (CosNotification::QoSProperties &qos, int threads)
00181 {
00182   NotifyExt::ThreadPoolParams tp_params =
00183     {NotifyExt::CLIENT_PROPAGATED, 0, 0, (unsigned)threads, 0, 0, 0, 0, 0 };
00184 
00185   qos.length (1);
00186   qos[0].name = CORBA::string_dup (NotifyExt::ThreadPool);
00187   qos[0].value <<= tp_params;
00188 }
00189 
00190 int
00191 TAO_CosNotify_Service::fini (void)
00192 {
00193   return 0;
00194 }
00195 
00196 void
00197 TAO_CosNotify_Service::init_service (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL)
00198 {
00199   ACE_DEBUG ((LM_DEBUG, "Loading the Cos Notification Service...\n"));
00200 
00201   this->init_i (orb ACE_ENV_ARG_PARAMETER);
00202   ACE_CHECK;
00203 }
00204 
00205 void
00206 TAO_CosNotify_Service::init_i (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL)
00207 {
00208   // Obtain the Root POA
00209   CORBA::Object_var object  =
00210     orb->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER);
00211   ACE_CHECK;
00212 
00213   if (CORBA::is_nil (object.in ()))
00214     ACE_ERROR ((LM_ERROR,
00215                 " (%P|%t) Unable to resolve the RootPOA.\n"));
00216 
00217   PortableServer::POA_var default_poa = PortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
00218   ACE_CHECK;
00219 
00220   /// Set the properties
00221     TAO_Notify_Properties* properties = TAO_Notify_PROPERTIES::instance();
00222 
00223     properties->orb (orb);
00224     properties->default_poa (default_poa.in ());
00225 
00226     // Init the factory
00227     this->factory_.reset (this->create_factory (ACE_ENV_SINGLE_ARG_PARAMETER));
00228     ACE_CHECK;
00229     ACE_ASSERT( this->factory_.get() != 0 );
00230     TAO_Notify_PROPERTIES::instance()->factory (this->factory_.get());
00231 
00232     this->builder_.reset (this->create_builder (ACE_ENV_SINGLE_ARG_PARAMETER));
00233     ACE_CHECK;
00234     ACE_ASSERT( this->builder_.get() != 0 );
00235     TAO_Notify_PROPERTIES::instance()->builder (this->builder_.get());
00236 }
00237 
00238 TAO_Notify_Factory*
00239 TAO_CosNotify_Service::create_factory (ACE_ENV_SINGLE_ARG_DECL)
00240 {
00241   TAO_Notify_Factory* factory = ACE_Dynamic_Service<TAO_Notify_Factory>::instance ("TAO_Notify_Factory");
00242   if (factory == 0)
00243     {
00244        ACE_NEW_THROW_EX (factory,
00245                          TAO_Notify_Default_Factory (),
00246                          CORBA::NO_MEMORY ());
00247        ACE_CHECK_RETURN (0);
00248     }
00249   return factory;
00250 }
00251 
00252 TAO_Notify_Builder*
00253 TAO_CosNotify_Service::create_builder (ACE_ENV_SINGLE_ARG_DECL)
00254 {
00255   TAO_Notify_Builder* builder = 0;
00256   ACE_NEW_THROW_EX (builder,
00257                     TAO_Notify_Builder (),
00258                     CORBA::NO_MEMORY ());
00259   ACE_CHECK_RETURN (0);
00260 
00261   return builder;
00262 }
00263 
00264 CosNotifyChannelAdmin::EventChannelFactory_ptr
00265 TAO_CosNotify_Service::create (PortableServer::POA_ptr poa ACE_ENV_ARG_DECL)
00266 {
00267   return this->builder().build_event_channel_factory (poa ACE_ENV_ARG_PARAMETER);
00268 }
00269 
00270 void
00271 TAO_CosNotify_Service::remove (TAO_Notify_EventChannelFactory* /*ecf*/ ACE_ENV_ARG_DECL_NOT_USED)
00272 {
00273   // NOP.
00274 }
00275 
00276 TAO_Notify_Factory&
00277 TAO_CosNotify_Service::factory (void)
00278 {
00279   ACE_ASSERT( this->factory_.get() != 0 );
00280   return *this->factory_;
00281 }
00282 
00283 TAO_Notify_Builder&
00284 TAO_CosNotify_Service::builder (void)
00285 {
00286   ACE_ASSERT( this->builder_.get() != 0 );
00287   return *this->builder_;
00288 }
00289 
00290 TAO_END_VERSIONED_NAMESPACE_DECL
00291 
00292 
00293 /*********************************************************************************************************************/
00294 
00295 ACE_STATIC_SVC_DEFINE (TAO_Notify_Default_EMO_Factory_OLD,
00296                        ACE_TEXT (TAO_NOTIFY_DEF_EMO_FACTORY_NAME),
00297                        ACE_SVC_OBJ_T,
00298                        &ACE_SVC_NAME (TAO_CosNotify_Service),
00299                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00300                        0)
00301 
00302 /*********************************************************************************************************************/
00303 
00304 ACE_STATIC_SVC_DEFINE (TAO_CosNotify_Service,
00305                        ACE_TEXT (TAO_COS_NOTIFICATION_SERVICE_NAME),
00306                        ACE_SVC_OBJ_T,
00307                        &ACE_SVC_NAME (TAO_CosNotify_Service),
00308                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00309                        0)
00310 
00311 
00312 ACE_FACTORY_DEFINE (TAO_Notify_Serv, TAO_CosNotify_Service)
00313 
00314 /*********************************************************************************************************************/

Generated on Thu Nov 9 13:24:09 2006 for TAO_CosNotification by doxygen 1.3.6