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 .

 ~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 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.

TAO_Persistent_Context_Indexcontext_index_
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_
const ACE_TCHARpersistence_file_name_
void * base_address_
int multicast_
 If not zero multicast is enabled.

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 flag is set) or creates one (if flag isn't set or Naming Service was not found). This class also defines the operator-> so that functions like , .. can be called directly on a 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 . 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 , and orbsvcs/Naming/README.

Definition at line 62 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 34 of file Naming_Server.cpp.

References ACE_DEFAULT_MAP_SIZE, and TAO_NAMING_BASE_ADDR.

00035   : naming_context_ (),
00036     ior_multicast_ (0),
00037     naming_service_ior_ (),
00038     context_index_ (0),
00039     ior_file_name_ (0),
00040     pid_file_name_ (0),
00041     context_size_ (ACE_DEFAULT_MAP_SIZE),
00042     persistence_file_name_ (0),
00043     base_address_ (TAO_NAMING_BASE_ADDR),
00044     multicast_ (0),
00045     use_storable_context_ (0),
00046     use_servant_activator_ (0),
00047     servant_activator_ (0),
00048     use_redundancy_(0),
00049     round_trip_timeout_ (0),
00050     use_round_trip_timeout_ (0)
00051 {
00052 }

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 is set to true. If it is false, or no Naming Service was found during a period, create the Naming Service in this process. If creating the Naming Service locally, make the root context of size , register it under the , and make the Naming Service persistent if is not 0. ( specifies name of the file to use for persistent storage, specifies the address used for memory mapping file). If is not zero then the service will respond to multicast location queries.

Definition at line 54 of file Naming_Server.cpp.

References ACE_DEFAULT_MAP_SIZE, ACE_ERROR, init(), LM_ERROR, and TAO_NAMING_BASE_ADDR.

00065   : naming_context_ (),
00066     ior_multicast_ (0),
00067     naming_service_ior_ (),
00068     context_index_ (0),
00069     ior_file_name_ (0),
00070     pid_file_name_ (0),
00071     context_size_ (ACE_DEFAULT_MAP_SIZE),
00072     persistence_file_name_ (0),
00073     base_address_ (TAO_NAMING_BASE_ADDR),
00074     multicast_ (0),
00075     use_storable_context_ (use_storable_context),
00076     use_servant_activator_ (0),
00077     servant_activator_ (0),
00078     use_redundancy_(0),
00079     round_trip_timeout_ (0),
00080     use_round_trip_timeout_ (0)
00081 {
00082   if (this->init (orb,
00083                   poa,
00084                   context_size,
00085                   timeout,
00086                   resolve_for_existing_naming_service,
00087                   persistence_location,
00088                   base_addr,
00089                   enable_multicast,
00090                   use_storable_context,
00091                   round_trip_timeout,
00092                   use_round_trip_timeout) == -1)
00093     ACE_ERROR ((LM_ERROR,
00094                 "(%P|%t) %p\n",
00095                 "TAO_Naming_Server::init"));
00096 }

TAO_Naming_Server::~TAO_Naming_Server void   ) 
 

Destructor.

Definition at line 760 of file Naming_Server.cpp.

References servant_activator_, and use_servant_activator_.

00761 {
00762 #if (TAO_HAS_MINIMUM_POA == 0)
00763   if (this->use_servant_activator_)
00764     delete this->servant_activator_;
00765 #endif /* TAO_HAS_MINIMUM_POA */
00766 }


Member Function Documentation

int TAO_Naming_Server::fini void   ) 
 

Destroy the child POA created in .

Definition at line 701 of file Naming_Server.cpp.

References ACE_CATCHANY, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_TRY_CHECK, ACE_TRY_NEW_ENV, context_index_, ior_multicast_, CORBA::is_nil(), LM_ERROR, and ns_poa_.

Referenced by TAO_Naming_Loader::fini().

00702 {
00703   // Destroy the child POA ns_poa that is created when initializing
00704   // the Naming Service
00705   ACE_TRY_NEW_ENV
00706     {
00707       this->ns_poa_->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
00708       ACE_TRY_CHECK;
00709 
00710 
00711       CORBA::Object_var table_object =
00712         this->orb_->resolve_initial_references ("IORTable"
00713                                                 ACE_ENV_ARG_PARAMETER);
00714       ACE_TRY_CHECK;
00715 
00716       IORTable::Table_var adapter =
00717         IORTable::Table::_narrow (table_object.in () ACE_ENV_ARG_PARAMETER);
00718       ACE_TRY_CHECK;
00719       if (CORBA::is_nil (adapter.in ()))
00720         {
00721           ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
00722         }
00723       else
00724         {
00725           adapter->unbind ("NameService" ACE_ENV_ARG_PARAMETER);
00726           ACE_TRY_CHECK;
00727         }
00728     }
00729   ACE_CATCHANY
00730     {
00731       // Ignore
00732     }
00733   ACE_ENDTRY;
00734 
00735 
00736   if (this->ior_multicast_ != 0)
00737     {
00738       orb_->orb_core()->reactor ()->remove_handler (this->ior_multicast_,
00739          ACE_Event_Handler::READ_MASK | ACE_Event_Handler::DONT_CALL);
00740       delete this->ior_multicast_;
00741     }
00742 
00743   delete this->context_index_;
00744 
00745   return 0;
00746 }

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 is set to true. If it is false, or no Naming Service was found during a period, create the Naming Service in this process. If creating the Naming Service locally, make the root context of size , register it under the , and make the Naming Service persistent if is not 0. ( specifies name of the file to use for persistent storage, specifies the address used for memory mapping file). If is not zero then the service will respond to multicast location queries.

Definition at line 100 of file Naming_Server.cpp.

References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, init_new_naming(), CORBA::is_nil(), LM_DEBUG, naming_service_ior_, and TAO_debug_level.

Referenced by init_with_orb(), and TAO_Naming_Server().

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

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 , register it under the , and make the Naming Service persistent if is not 0. ( specifies name of the file to use for persistent storage). If is not zero then the service will respond to multicast location queries.

Definition at line 441 of file Naming_Server.cpp.

References CORBA::PolicyManager::_narrow(), CORBA::Policy::_nil(), ACE_OS::access(), ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_CString, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_DEFAULT_MULTICAST_ADDR, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_NEW_RETURN, ACE_NEW_THROW_EX, ACE_PRINT_EXCEPTION, ACE_TEXT, ACE_TRY, ACE_TRY_CHECK, ACE_OS::atoi(), context_index_, ACE_Auto_Basic_Ptr< X >::get(), ACE_OS::getenv(), TAO_Persistent_Context_Index::init(), ior_multicast_, CORBA::is_nil(), TAO::unbounded_object_reference_sequence< Policy, Policy_var >::length(), LM_DEBUG, LM_ERROR, TAO_Transient_Naming_Context::make_new_context(), naming_service_ior_, ns_poa_, TAO_Persistent_Context_Index::open(), TAO_Storable_Naming_Context::recreate_all(), ACE_Reactor::register_handler(), ACE_Auto_Basic_Ptr< X >::release(), TAO_Persistent_Context_Index::root_context(), TAO_debug_level, TAO_DEFAULT_NAME_SERVER_REQUEST_PORT, TAO_ROOT_NAMING_CONTEXT, TAO_SERVICEID_NAMESERVICE, use_redundancy_, use_servant_activator_, W_OK, and X_OK.

Referenced by init().

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

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 275 of file Naming_Server.cpp.

References CORBA::ORB::_duplicate(), ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_ERROR_RETURN, ACE_PRINT_EXCEPTION, ACE_TEXT, ACE_TRY, ACE_TRY_CHECK, context_size_, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), init(), ior_file_name_, CORBA::is_nil(), TAO::unbounded_object_reference_sequence< Policy, Policy_var >::length(), LM_ERROR, multicast_, naming_service_ior(), ns_poa_, parse_args(), persistence_file_name_, round_trip_timeout_, use_round_trip_timeout_, use_servant_activator_, and use_storable_context_.

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

char * TAO_Naming_Server::naming_service_ior void   ) 
 

Returns the IOR of the naming service.

Definition at line 749 of file Naming_Server.cpp.

References CORBA::string_dup().

Referenced by init_with_orb().

00750 {
00751   return CORBA::string_dup (this->naming_service_ior_.in ());
00752 }

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

Returns a for the root Naming Context.

Definition at line 755 of file Naming_Server.cpp.

00756 {
00757   return this->naming_context_.ptr ();
00758 }

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

parses the arguments.

Definition at line 171 of file Naming_Server.cpp.

References ACE_ERROR_RETURN, ACE_INT64_FORMAT_SPECIFIER, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_OS::atoi(), context_size_, ior_file_name_, LM_ERROR, multicast_, persistence_file_name_, round_trip_timeout_, TAO_debug_level, use_redundancy_, use_round_trip_timeout_, and use_storable_context_.

Referenced by init_with_orb().

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


Member Data Documentation

void* TAO_Naming_Server::base_address_ [protected]
 

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

Definition at line 207 of file Naming_Server.h.

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 176 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 199 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 188 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

TAO_IOR_Multicast* TAO_Naming_Server::ior_multicast_ [protected]
 

The ior_multicast event handler.

Definition at line 166 of file Naming_Server.h.

Referenced by fini(), and init_new_naming().

int TAO_Naming_Server::multicast_ [protected]
 

If not zero multicast is enabled.

Definition at line 210 of file Naming_Server.h.

Referenced by init_with_orb(), and parse_args().

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.

Referenced by init(), and init_new_naming().

PortableServer::POA_var TAO_Naming_Server::ns_poa_ [protected]
 

The Naming Service POA.

Definition at line 185 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 179 of file Naming_Server.h.

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 203 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 191 of file Naming_Server.h.

PortableServer::POA_var TAO_Naming_Server::root_poa_ [protected]
 

The Root POA.

Definition at line 182 of file Naming_Server.h.

int TAO_Naming_Server::round_trip_timeout_ [protected]
 

Definition at line 232 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 224 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 229 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 233 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 218 of file Naming_Server.h.

Referenced by init_new_naming(), init_with_orb(), and ~TAO_Naming_Server().

int TAO_Naming_Server::use_storable_context_ [protected]
 

If not zero use flat file persistence.

Definition at line 213 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 Thu Nov 9 13:57:40 2006 for TAO_CosNaming by doxygen 1.3.6