00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Naming_Server.h 00006 * 00007 * Naming_Server.h,v 1.6 2006/03/14 06:14:34 jtc Exp 00008 * 00009 * Implement wrappers useful to Naming Service servers. 00010 * 00011 * 00012 * @author Nagarajan Surendran (naga@cs.wustl.edu) 00013 * @author Matt Braun <mjb2@cs.wustl.edu> 00014 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>. 00015 */ 00016 //============================================================================= 00017 00018 00019 #ifndef TAO_NAMING_SERVER_H 00020 #define TAO_NAMING_SERVER_H 00021 #include /**/ "ace/pre.h" 00022 00023 #include "tao/ORB.h" 00024 #include "orbsvcs/CosNamingC.h" 00025 #include "orbsvcs/IOR_Multicast.h" 00026 #include "orbsvcs/Naming/Naming_Context_Interface.h" 00027 #include "orbsvcs/Naming/nsconf.h" 00028 00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 // Forward decl; 00032 class TAO_Persistent_Context_Index; 00033 class TAO_Storable_Naming_Context_Activator; 00034 00035 /** 00036 * @class TAO_Naming_Server 00037 * 00038 * @brief Defines a wrapper class that holds the root Naming Context. 00039 * 00040 * This class either finds an existing Naming Service (if the 00041 * <resolve_for_existing_naming_service> flag is set) or creates 00042 * one (if <resolve_for_existing_naming_service> flag isn't set or 00043 * Naming Service was not found). This class also defines the 00044 * operator-> so that <NamingContext> functions like <bind>, 00045 * <unbind> .. can be called directly on a <TAO_Naming_Server> 00046 * object, and be forwareded to the root Naming Context. 00047 * This class is intended to simplify 00048 * programs that want to play the role of a Naming Service 00049 * server. To simplify programs that want to play the role of 00050 * Naming Service clients, use <TAO_Naming_Client>. 00051 * If a Naming Service is created locally, a TAO_IOR_Multicast 00052 * event handler is created and installed on the ORB's reactor. 00053 * This event handler allows other clients on the network to 00054 * discover and use this Naming Service. 00055 * Event handler listens on a multicast port for messages from 00056 * clients looking for a Naming Service, and sends back the ior 00057 * of the root Naming Context. For more information on how this 00058 * bootstraping through a multicast process works, check out 00059 * orbsvcs/orbsvcs/TAO_IOR_Multicast.*, implementation of 00060 * <resolve_initial_references>, and orbsvcs/Naming/README. 00061 */ 00062 class TAO_Naming_Serv_Export TAO_Naming_Server 00063 { 00064 public: 00065 /// Default constructor. 00066 TAO_Naming_Server (void); 00067 00068 /** 00069 * Constructor. Attempts to find an existing Naming Service if 00070 * <resolve_for_existing_naming_service> is set to true. If it is 00071 * false, or no Naming Service was found during a <timeout> period, 00072 * create the Naming Service in this process. If creating the 00073 * Naming Service locally, make the root context of size 00074 * <context_size>, register it under the <poa>, and make the Naming 00075 * Service persistent if <persistence_location> is not 0. 00076 * (<persistence_location> specifies name of the file to use for 00077 * persistent storage, <base_addr> specifies the address used for 00078 * memory mapping <persistent_location> file). 00079 * If <enable_multicast> is not zero then the service will respond 00080 * to multicast location queries. 00081 */ 00082 TAO_Naming_Server (CORBA::ORB_ptr orb, 00083 PortableServer::POA_ptr poa, 00084 size_t context_size = ACE_DEFAULT_MAP_SIZE, 00085 ACE_Time_Value *timeout = 0, 00086 int resolve_for_existing_naming_service = 1, 00087 const ACE_TCHAR *persistence_location = 0, 00088 void *base_addr = TAO_NAMING_BASE_ADDR, 00089 int enable_multicast = 1, 00090 int use_storable_context = 0, 00091 int round_trip_timeout = 0, 00092 int use_round_trip_timeout = 0); 00093 00094 /** 00095 * Initializer. Attempts to find an existing Naming Service if 00096 * <resolve_for_existing_naming_service> is set to true. If it is 00097 * false, or no Naming Service was found during a <timeout> period, 00098 * create the Naming Service in this process. If creating the 00099 * Naming Service locally, make the root context of size 00100 * <context_size>, register it under the <poa>, and make the Naming 00101 * Service persistent if <persistence_location> is not 0. 00102 * (<persistence_location> specifies name of the file to use for 00103 * persistent storage, <base_addr> specifies the address used for 00104 * memory mapping <persistent_location> file). 00105 * If <enable_multicast> is not zero then the service will respond 00106 * to multicast location queries. 00107 */ 00108 int init (CORBA::ORB_ptr orb, 00109 PortableServer::POA_ptr poa, 00110 size_t context_size = ACE_DEFAULT_MAP_SIZE, 00111 ACE_Time_Value *timeout = 0, 00112 int resolve_for_existing_naming_service = 1, 00113 const ACE_TCHAR *persistence_location = 0, 00114 void *base_addr = TAO_NAMING_BASE_ADDR, 00115 int enable_multicast = 1, 00116 int use_storable_context = 0, 00117 int round_trip_timeout = 0, 00118 int use_round_trip_timeout = 0); 00119 00120 /// Initialize the Naming Service with the command line arguments and 00121 /// the ORB. 00122 int init_with_orb (int argc, 00123 ACE_TCHAR *argv [], 00124 CORBA::ORB_ptr orb); 00125 00126 /// Destroy the child POA created in <init_with_orb> 00127 int fini (void); 00128 00129 /// Destructor. 00130 ~TAO_Naming_Server (void); 00131 00132 /// Returns the IOR of the naming service. 00133 char * naming_service_ior (void); 00134 00135 /// Returns a <NamingContext_ptr> for the root Naming Context. 00136 CosNaming::NamingContext_ptr operator-> (void) const; 00137 00138 protected: 00139 /** 00140 * Helper method: create Naming Service locally. 00141 * Make the root context of size 00142 * <context_size>, register it under the <root_poa>, and make the Naming 00143 * Service persistent if <persistence_location> is not 0. 00144 * (<persistence_location> specifies name of the file to use for 00145 * persistent storage). 00146 * If <enable_multicast> is not zero then the service will respond 00147 * to multicast location queries. 00148 */ 00149 int init_new_naming (CORBA::ORB_ptr orb, 00150 PortableServer::POA_ptr root_poa, 00151 const ACE_TCHAR *persistence_location, 00152 void *base_addr, 00153 size_t context_size, 00154 int enable_multicast, 00155 int use_storable_context, 00156 int round_trip_timeout = 0, 00157 int use_round_trip_timeout = 0); 00158 00159 /// parses the arguments. 00160 int parse_args (int argc, ACE_TCHAR *argv[]); 00161 00162 /// Root NamingContext_ptr. 00163 CosNaming::NamingContext_var naming_context_; 00164 00165 /// The ior_multicast event handler. 00166 TAO_IOR_Multicast *ior_multicast_; 00167 00168 /// The IOR string of the root naming context. 00169 CORBA::String_var naming_service_ior_; 00170 00171 /** 00172 * Pointer to the object used to create/initialize 00173 * the Naming Service when local persistent Naming Service is 00174 * desired. 00175 */ 00176 TAO_Persistent_Context_Index *context_index_; 00177 00178 /// The ORB 00179 CORBA::ORB_var orb_; 00180 00181 /// The Root POA. 00182 PortableServer::POA_var root_poa_; 00183 00184 /// The Naming Service POA. 00185 PortableServer::POA_var ns_poa_; 00186 00187 /// File to output the Naming Service IOR. 00188 const ACE_TCHAR *ior_file_name_; 00189 00190 /// File to output the process id. 00191 const ACE_TCHAR *pid_file_name_; 00192 00193 /** 00194 * Size of the hash_table allocated upon the creation of the Naming 00195 * Service context (if one is created). Note: all the contexts 00196 * created under the given context will use the same size for their 00197 * initial hash table allocations. 00198 */ 00199 size_t context_size_; 00200 00201 /// Path to the file to be used to store/read in Naming Service 00202 /// persistent state. 00203 const ACE_TCHAR *persistence_file_name_; 00204 00205 /// Address to be used for memory mapping Naming Service state file, 00206 /// identified by the <persistence_file_name_>. 00207 void *base_address_; 00208 00209 /// If not zero multicast is enabled. 00210 int multicast_; 00211 00212 /// If not zero use flat file persistence 00213 int use_storable_context_; 00214 00215 /** 00216 * If not zero use servant activator that uses flat file persistence. 00217 */ 00218 int use_servant_activator_; 00219 00220 /** 00221 * Need to retain the servant activator between calls to 00222 * init_with_orb() and init_new_naming(). 00223 */ 00224 TAO_Storable_Naming_Context_Activator *servant_activator_; 00225 00226 /** 00227 * If not zero support redundant naming servers. 00228 */ 00229 int use_redundancy_; 00230 00231 // If not zero use round trip timeout policy set to value specified 00232 int round_trip_timeout_; 00233 int use_round_trip_timeout_; 00234 }; 00235 00236 TAO_END_VERSIONED_NAMESPACE_DECL 00237 00238 #include /**/ "ace/post.h" 00239 #endif /* TAO_NAMING_SERVER_H */