TAO_Naming_Server Class Reference

Defines a wrapper class that holds the root Naming Context. More...

#include <Naming_Server.h>

Collaboration diagram for TAO_Naming_Server:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Naming_Server (void)
 Default constructor.
 TAO_Naming_Server (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, size_t context_size=ACE_DEFAULT_MAP_SIZE, ACE_Time_Value *timeout=0, int resolve_for_existing_naming_service=1, const ACE_TCHAR *persistence_location=0, void *base_addr=TAO_NAMING_BASE_ADDR, int enable_multicast=1, int use_storable_context=0, int round_trip_timeout=0, int use_round_trip_timeout=0)
int init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, size_t context_size=ACE_DEFAULT_MAP_SIZE, ACE_Time_Value *timeout=0, int resolve_for_existing_naming_service=1, const ACE_TCHAR *persistence_location=0, void *base_addr=TAO_NAMING_BASE_ADDR, int enable_multicast=1, int use_storable_context=0, int round_trip_timeout=0, int use_round_trip_timeout=0)
int init_with_orb (int argc, ACE_TCHAR *argv[], CORBA::ORB_ptr orb)
int fini (void)
 Destroy the child POA created in <init_with_orb>.
 ~TAO_Naming_Server (void)
 Destructor.
char * naming_service_ior (void)
 Returns the IOR of the naming service.
CosNaming::NamingContext_ptr operator-> (void) const
 Returns a <NamingContext_ptr> for the root Naming Context.

Protected Member Functions

int init_new_naming (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, const ACE_TCHAR *persistence_location, void *base_addr, size_t context_size, int enable_multicast, int use_storable_context, int round_trip_timeout=0, int use_round_trip_timeout=0)
int parse_args (int argc, ACE_TCHAR *argv[])
 parses the arguments.

Protected Attributes

CosNaming::NamingContext_var naming_context_
 Root NamingContext_ptr.
TAO_IOR_Multicast * ior_multicast_
 The ior_multicast event handler.
CORBA::String_var naming_service_ior_
 The IOR string of the root naming context.
CORBA::ORB_var orb_
 The ORB.
PortableServer::POA_var root_poa_
 The Root POA.
PortableServer::POA_var ns_poa_
 The Naming Service POA.
const ACE_TCHARior_file_name_
 File to output the Naming Service IOR.
const ACE_TCHARpid_file_name_
 File to output the process id.
size_t context_size_
int multicast_
 If not zero multicast is enabled.
TAO_Persistent_Context_Indexcontext_index_
const ACE_TCHARpersistence_file_name_
void * base_address_
int use_storable_context_
 If not zero use flat file persistence.
int use_servant_activator_
TAO_Storable_Naming_Context_Activatorservant_activator_
int use_redundancy_
int round_trip_timeout_
int use_round_trip_timeout_

Detailed Description

Defines a wrapper class that holds the root Naming Context.

This class either finds an existing Naming Service (if the <resolve_for_existing_naming_service> flag is set) or creates one (if <resolve_for_existing_naming_service> flag isn't set or Naming Service was not found). This class also defines the operator-> so that <NamingContext> functions like <bind>, <unbind> .. can be called directly on a <TAO_Naming_Server> object, and be forwareded to the root Naming Context. This class is intended to simplify programs that want to play the role of a Naming Service server. To simplify programs that want to play the role of Naming Service clients, use <TAO_Naming_Client>. If a Naming Service is created locally, a TAO_IOR_Multicast event handler is created and installed on the ORB's reactor. This event handler allows other clients on the network to discover and use this Naming Service. Event handler listens on a multicast port for messages from clients looking for a Naming Service, and sends back the ior of the root Naming Context. For more information on how this bootstraping through a multicast process works, check out orbsvcs/orbsvcs/TAO_IOR_Multicast.*, implementation of <resolve_initial_references>, and orbsvcs/Naming/README.

Definition at line 64 of file Naming_Server.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Naming_Server::TAO_Naming_Server ( void   ) 

Default constructor.

Definition at line 38 of file Naming_Server.cpp.

00039   : naming_context_ (),
00040     ior_multicast_ (0),
00041     naming_service_ior_ (),
00042     ior_file_name_ (0),
00043     pid_file_name_ (0),
00044     context_size_ (ACE_DEFAULT_MAP_SIZE),
00045     multicast_ (0),
00046 #if !defined (CORBA_E_MICRO)
00047     context_index_ (0),
00048     persistence_file_name_ (0),
00049     base_address_ (TAO_NAMING_BASE_ADDR),
00050     use_storable_context_ (0),
00051     use_servant_activator_ (false),
00052     servant_activator_ (0),
00053 #endif /* CORBA_E_MICRO */
00054     use_redundancy_(0),
00055     round_trip_timeout_ (0),
00056     use_round_trip_timeout_ (0)
00057 {
00058 }

TAO_Naming_Server::TAO_Naming_Server ( CORBA::ORB_ptr  orb,
PortableServer::POA_ptr  poa,
size_t  context_size = ACE_DEFAULT_MAP_SIZE,
ACE_Time_Value timeout = 0,
int  resolve_for_existing_naming_service = 1,
const ACE_TCHAR persistence_location = 0,
void *  base_addr = TAO_NAMING_BASE_ADDR,
int  enable_multicast = 1,
int  use_storable_context = 0,
int  round_trip_timeout = 0,
int  use_round_trip_timeout = 0 
)

Constructor. Attempts to find an existing Naming Service if <resolve_for_existing_naming_service> is set to true. If it is false, or no Naming Service was found during a <timeout> period, create the Naming Service in this process. If creating the Naming Service locally, make the root context of size <context_size>, register it under the <poa>, and make the Naming Service persistent if <persistence_location> is not 0. (<persistence_location> specifies name of the file to use for persistent storage, <base_addr> specifies the address used for memory mapping <persistent_location> file). If <enable_multicast> is not zero then the service will respond to multicast location queries.

Definition at line 60 of file Naming_Server.cpp.

References ACE_ERROR, and LM_ERROR.

00071   : naming_context_ (),
00072     ior_multicast_ (0),
00073     naming_service_ior_ (),
00074     ior_file_name_ (0),
00075     pid_file_name_ (0),
00076     context_size_ (ACE_DEFAULT_MAP_SIZE),
00077     multicast_ (0),
00078 #if !defined (CORBA_E_MICRO)
00079     context_index_ (0),
00080     persistence_file_name_ (0),
00081     base_address_ (TAO_NAMING_BASE_ADDR),
00082     use_storable_context_ (use_storable_context),
00083     use_servant_activator_ (false),
00084     servant_activator_ (0),
00085 #endif /* CORBA_E_MICRO */
00086     use_redundancy_(0),
00087     round_trip_timeout_ (0),
00088     use_round_trip_timeout_ (0)
00089 {
00090   if (this->init (orb,
00091                   poa,
00092                   context_size,
00093                   timeout,
00094                   resolve_for_existing_naming_service,
00095                   persistence_location,
00096                   base_addr,
00097                   enable_multicast,
00098                   use_storable_context,
00099                   round_trip_timeout,
00100                   use_round_trip_timeout) == -1)
00101     ACE_ERROR ((LM_ERROR,
00102                 "(%P|%t) %p\n",
00103                 "TAO_Naming_Server::init"));
00104 }

TAO_Naming_Server::~TAO_Naming_Server ( void   ) 

Destructor.

Definition at line 767 of file Naming_Server.cpp.

References servant_activator_.

00768 {
00769 #if (TAO_HAS_MINIMUM_POA == 0) && \
00770     !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00771   if (this->use_servant_activator_)
00772     delete this->servant_activator_;
00773 #endif /* TAO_HAS_MINIMUM_POA */
00774 }


Member Function Documentation

int TAO_Naming_Server::fini ( void   ) 

Destroy the child POA created in <init_with_orb>.

Definition at line 714 of file Naming_Server.cpp.

References ACE_ERROR, context_index_, ACE_Event_Handler::DONT_CALL, TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), LM_ERROR, ns_poa_, orb_, and ACE_Event_Handler::READ_MASK.

Referenced by TAO_Naming_Loader::fini().

00715 {
00716   // Destroy the child POA ns_poa that is created when initializing
00717   // the Naming Service
00718   try
00719     {
00720       this->ns_poa_->destroy (1, 1);
00721 
00722       CORBA::Object_var table_object =
00723         this->orb_->resolve_initial_references ("IORTable");
00724 
00725       IORTable::Table_var adapter =
00726         IORTable::Table::_narrow (table_object.in ());
00727       if (CORBA::is_nil (adapter.in ()))
00728         {
00729           ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
00730         }
00731       else
00732         {
00733           adapter->unbind ("NameService");
00734         }
00735     }
00736   catch (const CORBA::Exception&)
00737     {
00738       // Ignore
00739     }
00740 
00741   if (this->ior_multicast_ != 0)
00742     {
00743       orb_->orb_core()->reactor ()->remove_handler (this->ior_multicast_,
00744          ACE_Event_Handler::READ_MASK | ACE_Event_Handler::DONT_CALL);
00745       delete this->ior_multicast_;
00746     }
00747 
00748 #if !defined (CORBA_E_MICRO)
00749   delete this->context_index_;
00750 #endif /* CORBA_E_MICRO */
00751 
00752   return 0;
00753 }

int TAO_Naming_Server::init ( CORBA::ORB_ptr  orb,
PortableServer::POA_ptr  poa,
size_t  context_size = ACE_DEFAULT_MAP_SIZE,
ACE_Time_Value timeout = 0,
int  resolve_for_existing_naming_service = 1,
const ACE_TCHAR persistence_location = 0,
void *  base_addr = TAO_NAMING_BASE_ADDR,
int  enable_multicast = 1,
int  use_storable_context = 0,
int  round_trip_timeout = 0,
int  use_round_trip_timeout = 0 
)

Initializer. Attempts to find an existing Naming Service if <resolve_for_existing_naming_service> is set to true. If it is false, or no Naming Service was found during a <timeout> period, create the Naming Service in this process. If creating the Naming Service locally, make the root context of size <context_size>, register it under the <poa>, and make the Naming Service persistent if <persistence_location> is not 0. (<persistence_location> specifies name of the file to use for persistent storage, <base_addr> specifies the address used for memory mapping <persistent_location> file). If <enable_multicast> is not zero then the service will respond to multicast location queries.

Definition at line 108 of file Naming_Server.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, TAO_Pseudo_Var_T< T >::in(), init_new_naming(), CORBA::is_nil(), LM_DEBUG, CORBA::ORB::object_to_string(), CORBA::ORB::resolve_initial_references(), and TAO_debug_level.

Referenced by init_with_orb().

00119 {
00120   if (resolve_for_existing_naming_service)
00121     {
00122       try
00123         {
00124           // Try to find an existing Naming Service.
00125           CORBA::Object_var naming_obj =
00126             orb->resolve_initial_references ("NameService", timeout);
00127 
00128           if (!CORBA::is_nil (naming_obj.in ()))
00129             {
00130               //
00131               // Success in finding a Naming Service.
00132               //
00133               if (TAO_debug_level > 0)
00134                 ACE_DEBUG ((LM_DEBUG,
00135                             "\nNameService found!\n"));
00136 
00137               this->naming_context_ =
00138                 CosNaming::NamingContext::_narrow (naming_obj.in ());
00139 
00140               this->naming_service_ior_ =
00141                 orb->object_to_string (naming_obj.in ());
00142 
00143               return 0;
00144             }
00145         }
00146       catch (const CORBA::Exception& ex)
00147         {
00148           ex._tao_print_exception ("TAO_Naming_Server::init");
00149         }
00150     }
00151 
00152   if (TAO_debug_level > 0)
00153     ACE_DEBUG ((LM_DEBUG,
00154                 "\nWe'll become a NameService\n"));
00155 
00156   // Become a Naming Service.
00157   return this->init_new_naming (orb,
00158                                 poa,
00159                                 persistence_location,
00160                                 base_addr,
00161                                 context_size,
00162                                 enable_multicast,
00163                                 use_storable_context,
00164                                 round_trip_timeout,
00165                                 use_round_trip_timeout);
00166 }

int TAO_Naming_Server::init_new_naming ( CORBA::ORB_ptr  orb,
PortableServer::POA_ptr  root_poa,
const ACE_TCHAR persistence_location,
void *  base_addr,
size_t  context_size,
int  enable_multicast,
int  use_storable_context,
int  round_trip_timeout = 0,
int  use_round_trip_timeout = 0 
) [protected]

Helper method: create Naming Service locally. Make the root context of size <context_size>, register it under the <root_poa>, and make the Naming Service persistent if <persistence_location> is not 0. (<persistence_location> specifies name of the file to use for persistent storage). If <enable_multicast> is not zero then the service will respond to multicast location queries.

Definition at line 461 of file Naming_Server.cpp.

References CORBA::Policy::_nil(), CORBA::Exception::_tao_print_exception(), ACE_OS::access(), ACE_DEBUG, ACE_DEFAULT_MULTICAST_ADDR, ACE_ERROR, ACE_NEW_RETURN, ACE_NEW_THROW_EX, ACE_TEXT, ACE_OS::atoi(), context_index_, CORBA::ORB::create_policy(), ACE_Auto_Basic_Ptr< X >::get(), ACE_OS::getenv(), TAO_Pseudo_Var_T< T >::in(), TAO_Persistent_Context_Index::init(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, TAO_Transient_Naming_Context::make_new_context(), TAO_ORB_Parameters::mcast_discovery_endpoint(), TAO::MCAST_NAMESERVICE, ns_poa_, CORBA::ORB::object_to_string(), CORBA::ORB::orb_core(), TAO_ORB_Core::orb_params(), TAO_ORB_Core::reactor(), ACE_Event_Handler::READ_MASK, TAO_Storable_Naming_Context::recreate_all(), ACE_Reactor::register_handler(), CORBA::ORB::register_initial_reference(), ACE_Auto_Basic_Ptr< X >::release(), CORBA::ORB::resolve_initial_references(), TAO_Persistent_Context_Index::root_context(), TAO_ORB_Parameters::service_port(), TAO_debug_level, TAO_DEFAULT_NAME_SERVER_REQUEST_PORT, TAO_ROOT_NAMING_CONTEXT, TAO_SERVICEID_NAMESERVICE, use_redundancy_, W_OK, and X_OK.

Referenced by init().

00470 {
00471   try
00472     {
00473 #if defined (CORBA_E_MICRO)
00474       ACE_UNUSED_ARG (persistence_location);
00475       ACE_UNUSED_ARG (base_addr);
00476       ACE_UNUSED_ARG (use_storable_context);
00477 #else
00478       if (use_storable_context)
00479         {
00480           // In lieu of a fully implemented service configurator version
00481           // of this Reader and Writer, let's just take something off the
00482           // command line for now.
00483           TAO_Naming_Service_Persistence_Factory* pf = 0;
00484           ACE_NEW_RETURN(pf, TAO_NS_FlatFileFactory, -1);
00485           auto_ptr<TAO_Naming_Service_Persistence_Factory> persFactory(pf);
00486           // This instance will either get deleted after recreate all or,
00487           // in the case of a servant activator's use, on destruction of the
00488           // activator.
00489 
00490           // Was a location specified?
00491           if (persistence_location == 0)
00492             {
00493               // No, assign the default location "NameService"
00494               persistence_location = ACE_TEXT("NameService");
00495             }
00496 
00497           // Now make sure this directory exists
00498           if (ACE_OS::access (persistence_location, W_OK|X_OK))
00499             {
00500               ACE_ERROR ((LM_ERROR, "Invalid persistence directory\n"));
00501               return -1;
00502             }
00503 
00504 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
00505           if (this->use_servant_activator_)
00506             {
00507               ACE_NEW_THROW_EX (this->servant_activator_,
00508                                 TAO_Storable_Naming_Context_Activator (orb,
00509                                                                        persFactory.get(),
00510                                                                        persistence_location,
00511                                                                        context_size),
00512                                 CORBA::NO_MEMORY ());
00513               this->ns_poa_->set_servant_manager(this->servant_activator_);
00514             }
00515 #endif /* TAO_HAS_MINIMUM_POA */
00516 
00517           this->naming_context_ =
00518             TAO_Storable_Naming_Context::recreate_all (orb,
00519                                                        poa,
00520                                                        TAO_ROOT_NAMING_CONTEXT,
00521                                                        context_size,
00522                                                        0,
00523                                                        persFactory.get(),
00524                                                        persistence_location,
00525                                                        use_redundancy_);
00526 
00527           if (this->use_servant_activator_)
00528             persFactory.release();
00529         }
00530       else if (persistence_location != 0)
00531         //
00532         // Initialize Persistent Naming Service.
00533         //
00534         {
00535           // Allocate and initialize Persistent Context Index.
00536           ACE_NEW_RETURN (this->context_index_,
00537                           TAO_Persistent_Context_Index (orb, poa),
00538                           -1);
00539 
00540           if (this->context_index_->open (persistence_location,
00541                                           base_addr) == -1
00542               || this->context_index_->init (context_size) == -1)
00543             {
00544               if (TAO_debug_level >0)
00545                 ACE_DEBUG ((LM_DEBUG,
00546                             "TAO_Naming_Server: context_index initialization failed\n"));
00547               return -1;
00548             }
00549 
00550           // Set the root Naming Context reference.
00551           this->naming_context_ =
00552             this->context_index_->root_context ();
00553         }
00554       else
00555 #endif /* CORBA_E_MICRO */
00556         {
00557           //
00558           // Initialize Transient Naming Service.
00559           //
00560           this->naming_context_ =
00561             TAO_Transient_Naming_Context::make_new_context (poa,
00562                                                             TAO_ROOT_NAMING_CONTEXT,
00563                                                             context_size);
00564 
00565         }
00566 
00567 #if !defined (CORBA_E_MICRO)
00568       // Register with the ORB's resolve_initial_references()
00569       // mechanism.  Primarily useful for dynamically loaded Name
00570       // Services.
00571       orb->register_initial_reference ("NameService",
00572                                        this->naming_context_.in ());
00573 #endif /* CORBA_E_MICRO */
00574 
00575       // Set the ior of the root Naming Context.
00576       this->naming_service_ior_=
00577         orb->object_to_string (this->naming_context_.in ());
00578 
00579       CORBA::Object_var table_object =
00580         orb->resolve_initial_references ("IORTable");
00581 
00582       IORTable::Table_var adapter =
00583         IORTable::Table::_narrow (table_object.in ());
00584       if (CORBA::is_nil (adapter.in ()))
00585         {
00586           ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
00587         }
00588       else
00589         {
00590           CORBA::String_var ior =
00591             orb->object_to_string (this->naming_context_.in ());
00592           adapter->bind ("NameService", ior.in ());
00593         }
00594 
00595 #if defined (ACE_HAS_IP_MULTICAST)
00596       if (enable_multicast)
00597         {
00598           // @@ Marina: is there anyway to implement this stuff
00599           // without using ORB_Core_instance()? For example can you
00600           // pass the ORB as an argument?
00601 
00602           //
00603           // Install ior multicast handler.
00604           //
00605           // Get reactor instance from TAO.
00606           ACE_Reactor *reactor = orb->orb_core()->reactor ();
00607 
00608           // See if the -ORBMulticastDiscoveryEndpoint option was specified.
00609           ACE_CString mde (orb->orb_core ()->orb_params ()->mcast_discovery_endpoint ());
00610 
00611           // First, see if the user has given us a multicast port number
00612           // on the command-line;
00613           u_short port =
00614             orb->orb_core ()->orb_params ()->service_port (TAO::MCAST_NAMESERVICE);
00615 
00616           if (port == 0)
00617             {
00618               // Check environment var. for multicast port.
00619               const char *port_number =
00620                 ACE_OS::getenv ("NameServicePort");
00621 
00622               if (port_number != 0)
00623                 port = static_cast<u_short> (ACE_OS::atoi (port_number));
00624             }
00625 
00626           // Port wasn't specified on the command-line or in environment -
00627           // use the default.
00628           if (port == 0)
00629             port = TAO_DEFAULT_NAME_SERVER_REQUEST_PORT;
00630 
00631           // Instantiate a handler which will handle client requests for
00632           // the root Naming Context ior, received on the multicast port.
00633           ACE_NEW_RETURN (this->ior_multicast_,
00634                           TAO_IOR_Multicast (),
00635                           -1);
00636 
00637           if (mde.length () != 0)
00638             {
00639               if (this->ior_multicast_->init (this->naming_service_ior_.in (),
00640                                               mde.c_str (),
00641                                               TAO_SERVICEID_NAMESERVICE) == -1)
00642                 return -1;
00643             }
00644           else
00645             {
00646               if (this->ior_multicast_->init (this->naming_service_ior_.in (),
00647                                               port,
00648 #if defined (ACE_HAS_IPV6)
00649                                               ACE_DEFAULT_MULTICASTV6_ADDR,
00650 #else
00651                                               ACE_DEFAULT_MULTICAST_ADDR,
00652 #endif /* ACE_HAS_IPV6 */
00653                                               TAO_SERVICEID_NAMESERVICE) == -1)
00654                 return -1;
00655             }
00656 
00657           // Register event handler for the ior multicast.
00658           if (reactor->register_handler (this->ior_multicast_,
00659                                          ACE_Event_Handler::READ_MASK) == -1)
00660             {
00661               if (TAO_debug_level > 0)
00662                 ACE_DEBUG ((LM_DEBUG,
00663                             "TAO_Naming_Server: cannot register Event handler\n"));
00664               return -1;
00665             }
00666 
00667           if (TAO_debug_level > 0)
00668             ACE_DEBUG ((LM_DEBUG,
00669                         "TAO_Naming_Server: The multicast server setup is done.\n"));
00670         }
00671 #else
00672   ACE_UNUSED_ARG (enable_multicast);
00673 #endif /* ACE_HAS_IP_MULTICAST */
00674 
00675 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00676       if (use_round_trip_timeout == 1)
00677       {
00678         TimeBase::TimeT roundTripTimeoutVal = round_trip_timeout;
00679         CORBA::Any anyObjectVal;
00680         anyObjectVal <<= roundTripTimeoutVal;
00681         CORBA::PolicyList polList (1);
00682         polList.length (1);
00683         polList[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
00684                                          anyObjectVal);
00685 
00686         // set a timeout on the orb
00687         //
00688         CORBA::Object_var orbPolicyManagerObj =
00689           orb->resolve_initial_references ("ORBPolicyManager");
00690 
00691         CORBA::PolicyManager_var orbPolicyManager =
00692           CORBA::PolicyManager::_narrow (orbPolicyManagerObj.in ());
00693         orbPolicyManager->set_policy_overrides (polList, CORBA::SET_OVERRIDE);
00694 
00695         polList[0]->destroy ();
00696         polList[0] = CORBA::Policy::_nil ();
00697       }
00698 #else
00699   ACE_UNUSED_ARG (use_round_trip_timeout);
00700   ACE_UNUSED_ARG (round_trip_timeout);
00701 #endif /* TAO_HAS_CORBA_MESSAGING */
00702     }
00703   catch (const CORBA::Exception& ex)
00704     {
00705       ex._tao_print_exception (
00706         "TAO_Naming_Server::init_new_naming");
00707       return -1;
00708     }
00709 
00710   return 0;
00711 }

int TAO_Naming_Server::init_with_orb ( int  argc,
ACE_TCHAR argv[],
CORBA::ORB_ptr  orb 
)

Initialize the Naming Service with the command line arguments and the ORB.

Definition at line 294 of file Naming_Server.cpp.

References CORBA::ORB::_duplicate(), CORBA::Exception::_tao_print_exception(), ACE_ERROR_RETURN, ACE_TEXT, base_address_, context_size_, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), ACE_OS::getpid(), TAO_Pseudo_Var_T< T >::in(), init(), CORBA::is_nil(), LM_ERROR, naming_service_ior(), ns_poa_, orb_, parse_args(), persistence_file_name_, CORBA::ORB::resolve_initial_references(), root_poa_, round_trip_timeout_, use_round_trip_timeout_, use_servant_activator_, and use_storable_context_.

Referenced by TAO_Naming_Loader::create_object().

00297 {
00298   int result;
00299 
00300   try
00301     {
00302       // Duplicate the ORB
00303       this->orb_ = CORBA::ORB::_duplicate (orb);
00304 
00305       // Get the POA from the ORB.
00306       CORBA::Object_var poa_object =
00307         orb->resolve_initial_references ("RootPOA");
00308 
00309       if (CORBA::is_nil (poa_object.in ()))
00310         {
00311           ACE_ERROR_RETURN ((LM_ERROR,
00312                              ACE_TEXT(" (%P|%t) Unable to initialize the POA.\n")),
00313                             -1);
00314         }
00315 
00316       // Check the non-ORB arguments.  this needs to come before we
00317       // initialize my_naming_server so that we can pass on some of
00318       // the command-line arguments.
00319       result = this->parse_args (argc, argv);
00320 
00321       if (result < 0)
00322         return result;
00323 
00324       // Get the POA object.
00325       this->root_poa_ = PortableServer::POA::_narrow (poa_object.in ());
00326 
00327       // Get the POA_Manager.
00328       PortableServer::POAManager_var poa_manager =
00329         this->root_poa_->the_POAManager ();
00330 
00331       poa_manager->activate ();
00332 
00333 #if defined (CORBA_E_MICRO)
00334       this->ns_poa_ = PortableServer::POA::_duplicate (this->root_poa_);
00335 #else
00336       int numPolicies = 2;
00337 #if (TAO_HAS_MINIMUM_POA == 0)
00338       if (this->use_storable_context_)
00339         {
00340           this->use_servant_activator_ = true;
00341         }
00342 
00343       if (this->use_servant_activator_) {
00344         numPolicies += 2;
00345       }
00346 #endif /* TAO_HAS_MINIMUM_POA */
00347 
00348       CORBA::PolicyList policies (numPolicies);
00349       policies.length (numPolicies);
00350 
00351       // Id Assignment policy
00352       policies[0] =
00353         this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);
00354 
00355       // Lifespan policy
00356       policies[1] =
00357         this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);
00358 
00359 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
00360       if (this->use_servant_activator_)
00361         {
00362           // Request Processing Policy
00363           policies[2] =
00364             this->root_poa_->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
00365 
00366           // Servant Retention Policy
00367           policies[3] =
00368             this->root_poa_->create_servant_retention_policy (PortableServer::RETAIN);
00369         }
00370 #endif /* TAO_HAS_MINIMUM_POA */
00371 
00372       // We use a different POA, otherwise the user would have to change
00373       // the object key each time it invokes the server.
00374       this->ns_poa_ = this->root_poa_->create_POA ("NameService",
00375                                                    poa_manager.in (),
00376                                                    policies);
00377       // Warning!  If create_POA fails, then the policies won't be
00378       // destroyed and there will be hell to pay in memory leaks!
00379 
00380       // Creation of the new POAs over, so destroy the Policy_ptr's.
00381       for (CORBA::ULong i = 0;
00382            i < policies.length ();
00383            ++i)
00384         {
00385           CORBA::Policy_ptr policy = policies[i];
00386           policy->destroy ();
00387         }
00388 #endif /* CORBA_E_MICRO */
00389 
00390 #if defined (CORBA_E_MICRO)
00391       result = this->init (orb,
00392                            this->ns_poa_.in (),
00393                            this->context_size_,
00394                            0,
00395                            0,
00396                            0,
00397                            0,
00398                            this->multicast_,
00399                            false,
00400                            this->round_trip_timeout_,
00401                            this->use_round_trip_timeout_);
00402 #else
00403       result = this->init (orb,
00404                            this->ns_poa_.in (),
00405                            this->context_size_,
00406                            0,
00407                            0,
00408                            this->persistence_file_name_,
00409                            this->base_address_,
00410                            this->multicast_,
00411                            this->use_storable_context_,
00412                            this->round_trip_timeout_,
00413                            this->use_round_trip_timeout_);
00414 #endif /* CORBA_E_MICRO */
00415 
00416       if (result == -1)
00417         return result;
00418     }
00419   catch (const CORBA::Exception& ex)
00420     {
00421       ex._tao_print_exception (
00422         "TAO_Naming_Server::init_with_orb");
00423       return -1;
00424     }
00425 
00426   if (this->ior_file_name_ != 0)
00427     {
00428       FILE *iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w"));
00429       if (iorf == 0)
00430         {
00431           ACE_ERROR_RETURN ((LM_ERROR,
00432                              ACE_TEXT("Unable to open %s for writing:(%u) %p\n"),
00433                              this->ior_file_name_,
00434                              errno,
00435                              ACE_TEXT("TAO_Naming_Server::init_with_orb")),
00436                             -1);
00437         }
00438 
00439       CORBA::String_var str = this->naming_service_ior ();
00440 
00441       ACE_OS::fprintf (iorf, "%s\n", str.in ());
00442       ACE_OS::fclose (iorf);
00443     }
00444 
00445   if (this->pid_file_name_ != 0)
00446     {
00447       FILE *pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w"));
00448       if (pidf != 0)
00449         {
00450           ACE_OS::fprintf (pidf,
00451                            "%ld\n",
00452                            static_cast<long> (ACE_OS::getpid ()));
00453           ACE_OS::fclose (pidf);
00454         }
00455     }
00456 
00457   return 0;
00458 }

char * TAO_Naming_Server::naming_service_ior ( void   ) 

Returns the IOR of the naming service.

Definition at line 756 of file Naming_Server.cpp.

References CORBA::string_dup().

Referenced by init_with_orb().

00757 {
00758   return CORBA::string_dup (this->naming_service_ior_.in ());
00759 }

CosNaming::NamingContext_ptr TAO_Naming_Server::operator-> ( void   )  const

Returns a <NamingContext_ptr> for the root Naming Context.

Definition at line 762 of file Naming_Server.cpp.

00763 {
00764   return this->naming_context_.ptr ();
00765 }

int TAO_Naming_Server::parse_args ( int  argc,
ACE_TCHAR argv[] 
) [protected]

parses the arguments.

Definition at line 169 of file Naming_Server.cpp.

References ACE_ERROR_RETURN, ACE_INT64_FORMAT_SPECIFIER, ACE_SIZEOF_LONG_LONG, ACE_SIZEOF_VOID_P, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_OS::atoi(), base_address_, context_size_, LM_ERROR, ACE_Get_Opt::opt_arg(), persistence_file_name_, round_trip_timeout_, TAO_debug_level, use_redundancy_, use_round_trip_timeout_, and use_storable_context_.

Referenced by init_with_orb().

00171 {
00172 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
00173   ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("b:do:p:s:f:m:u:r:z:"));
00174 #else
00175   ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("b:do:p:s:f:m:z:"));
00176 #endif /* TAO_HAS_MINIMUM_POA */
00177 
00178   int c;
00179   int size;
00180 #if !defined (CORBA_E_MICRO)
00181   int result;
00182 
00183   // This is declared this way to avoid warnings from
00184   // some compilers that complain about mismatching types
00185   // in the sscanf.
00186 #if ACE_SIZEOF_VOID_P == ACE_SIZEOF_LONG_LONG
00187   ptrdiff_t address;
00188 #else
00189   long int address;
00190 #endif /* ACE_SIZEOF_VOID_P */
00191 #endif /* CORBA_E_MICRO */
00192 
00193   // Make sure only one persistence option is specified
00194   int f_opt_used = 0;
00195   int u_opt_used = 0;
00196   int r_opt_used = 0;
00197 
00198   while ((c = get_opts ()) != -1)
00199     switch (c)
00200       {
00201       case 'd':  // debug flag.
00202         ++TAO_debug_level;
00203         break;
00204       case 'o': // outputs the naming service ior to a file.
00205         this->ior_file_name_ = get_opts.opt_arg ();
00206         break;
00207       case 'p':
00208         this->pid_file_name_ = get_opts.opt_arg ();
00209         break;
00210       case 's':
00211         size = ACE_OS::atoi (get_opts.opt_arg ());
00212         if (size >= 0)
00213           this->context_size_ = size;
00214         break;
00215       case 'm':
00216         this->multicast_ = ACE_OS::atoi(get_opts.opt_arg ());
00217         break;
00218 #if !defined (CORBA_E_MICRO)
00219       case 'b':
00220         result = ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts.opt_arg ()),
00221 #if ACE_SIZEOF_VOID_P == ACE_SIZEOF_LONG_LONG
00222                            ACE_INT64_FORMAT_SPECIFIER,
00223 #else
00224                            "%ld",
00225 #endif /* ACE_SIZEOF_VOID_P */
00226                            &address);
00227         if (result == 0 || result == EOF)
00228           ACE_ERROR_RETURN ((LM_ERROR,
00229                              "Unable to process <-b> option"),
00230                             -1);
00231         this->base_address_ = (void *) address;
00232         break;
00233       case 'f':
00234         this->persistence_file_name_ = get_opts.opt_arg ();
00235         f_opt_used = 1;
00236         break;
00237 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
00238       case 'r':
00239         this->use_redundancy_ = 1;
00240         this->use_storable_context_ = 1;
00241         this->persistence_file_name_ = get_opts.opt_arg ();
00242         r_opt_used = 1;
00243         break;
00244       case 'u':
00245         this->use_storable_context_ = 1;
00246         this->persistence_file_name_ = get_opts.opt_arg ();
00247         u_opt_used = 1;
00248         break;
00249 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00250 #endif /* !CORBA_E_MICRO */
00251       case 'z':
00252         this->use_round_trip_timeout_ = 1;
00253         this->round_trip_timeout_ = (int)1.0e7 * ACE_OS::atoi (get_opts.opt_arg ());
00254         break;
00255       case '?':
00256       default:
00257 #if !defined (ACE_NLOGGING)
00258         const ACE_TCHAR *reqNonMinCorba=
00259 #if !defined (CORBA_E_MICRO)
00260           ACE_TEXT ("-f <persistence_file_name> ")
00261 #endif /* CORBA_E_MICRO */
00262 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_MICRO)
00263           ACE_TEXT ("-u <storable_persistence_directory (not used with -f)> ")
00264           ACE_TEXT ("-r <redundant_persistence_directory> ");
00265 #else
00266           ACE_TEXT ("");
00267 #endif /* TAO_HAS_MINIMUM_POA && !CORBA_E_MICRO */
00268 #endif /* !ACE_NLOGGING */
00269         ACE_ERROR_RETURN ((LM_ERROR,
00270                            ACE_TEXT ("usage:  %s ")
00271                            ACE_TEXT ("-d ")
00272                            ACE_TEXT ("-o <ior_output_file> ")
00273                            ACE_TEXT ("-p <pid_file_name> ")
00274                            ACE_TEXT ("-s <context_size> ")
00275                            ACE_TEXT ("-b <base_address> ")
00276                            ACE_TEXT ("-m <1=enable multicast, 0=disable multicast(default) ")
00277                            ACE_TEXT ("%s")
00278                            ACE_TEXT ("-z <relative round trip timeout> ")
00279                            ACE_TEXT ("\n"),
00280                            argv [0], reqNonMinCorba),
00281                           -1);
00282       }
00283 
00284   if (f_opt_used + u_opt_used + r_opt_used > 1)
00285     ACE_ERROR_RETURN ((LM_ERROR,
00286                        ACE_TEXT ("Only one persistence option can be passed")
00287                        ACE_TEXT ("\n")),
00288                       -1);
00289 
00290   return 0;
00291 }


Member Data Documentation

void* TAO_Naming_Server::base_address_ [protected]

Address to be used for memory mapping Naming Service state file, identified by the <persistence_file_name_>.

Definition at line 211 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

TAO_Persistent_Context_Index* TAO_Naming_Server::context_index_ [protected]

Pointer to the object used to create/initialize the Naming Service when local persistent Naming Service is desired.

Definition at line 203 of file Naming_Server.h.

Referenced by fini(), and init_new_naming().

size_t TAO_Naming_Server::context_size_ [protected]

Size of the hash_table allocated upon the creation of the Naming Service context (if one is created). Note: all the contexts created under the given context will use the same size for their initial hash table allocations.

Definition at line 192 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

const ACE_TCHAR* TAO_Naming_Server::ior_file_name_ [protected]

File to output the Naming Service IOR.

Definition at line 181 of file Naming_Server.h.

TAO_IOR_Multicast* TAO_Naming_Server::ior_multicast_ [protected]

The ior_multicast event handler.

Definition at line 166 of file Naming_Server.h.

int TAO_Naming_Server::multicast_ [protected]

If not zero multicast is enabled.

Definition at line 195 of file Naming_Server.h.

CosNaming::NamingContext_var TAO_Naming_Server::naming_context_ [protected]

Root NamingContext_ptr.

Definition at line 163 of file Naming_Server.h.

CORBA::String_var TAO_Naming_Server::naming_service_ior_ [protected]

The IOR string of the root naming context.

Definition at line 169 of file Naming_Server.h.

PortableServer::POA_var TAO_Naming_Server::ns_poa_ [protected]

The Naming Service POA.

Definition at line 178 of file Naming_Server.h.

Referenced by fini(), init_new_naming(), and init_with_orb().

CORBA::ORB_var TAO_Naming_Server::orb_ [protected]

The ORB.

Definition at line 172 of file Naming_Server.h.

Referenced by fini(), and init_with_orb().

const ACE_TCHAR* TAO_Naming_Server::persistence_file_name_ [protected]

Path to the file to be used to store/read in Naming Service persistent state.

Definition at line 207 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

const ACE_TCHAR* TAO_Naming_Server::pid_file_name_ [protected]

File to output the process id.

Definition at line 184 of file Naming_Server.h.

PortableServer::POA_var TAO_Naming_Server::root_poa_ [protected]

The Root POA.

Definition at line 175 of file Naming_Server.h.

Referenced by init_with_orb().

int TAO_Naming_Server::round_trip_timeout_ [protected]

Definition at line 234 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

TAO_Storable_Naming_Context_Activator* TAO_Naming_Server::servant_activator_ [protected]

Need to retain the servant activator between calls to init_with_orb() and init_new_naming().

Definition at line 225 of file Naming_Server.h.

Referenced by ~TAO_Naming_Server().

int TAO_Naming_Server::use_redundancy_ [protected]

If not zero support redundant naming servers.

Definition at line 231 of file Naming_Server.h.

Referenced by init_new_naming(), and parse_args().

int TAO_Naming_Server::use_round_trip_timeout_ [protected]

Definition at line 235 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

int TAO_Naming_Server::use_servant_activator_ [protected]

If not zero use servant activator that uses flat file persistence.

Definition at line 219 of file Naming_Server.h.

Referenced by init_with_orb().

int TAO_Naming_Server::use_storable_context_ [protected]

If not zero use flat file persistence.

Definition at line 214 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:49:10 2010 for TAO_CosNaming by  doxygen 1.4.7