00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Naming_Server.h 00006 * 00007 * $Id: Naming_Server.h 76880 2007-02-02 16:22:17Z johnnyw $ 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, ACE_TCHAR *argv [], CORBA::ORB_ptr orb); 00123 00124 /// Destroy the child POA created in <init_with_orb> 00125 int fini (void); 00126 00127 /// Destructor. 00128 ~TAO_Naming_Server (void); 00129 00130 /// Returns the IOR of the naming service. 00131 char * naming_service_ior (void); 00132 00133 /// Returns a <NamingContext_ptr> for the root Naming Context. 00134 CosNaming::NamingContext_ptr operator-> (void) const; 00135 00136 protected: 00137 /** 00138 * Helper method: create Naming Service locally. 00139 * Make the root context of size 00140 * <context_size>, register it under the <root_poa>, and make the Naming 00141 * Service persistent if <persistence_location> is not 0. 00142 * (<persistence_location> specifies name of the file to use for 00143 * persistent storage). 00144 * If <enable_multicast> is not zero then the service will respond 00145 * to multicast location queries. 00146 */ 00147 int init_new_naming (CORBA::ORB_ptr orb, 00148 PortableServer::POA_ptr root_poa, 00149 const ACE_TCHAR *persistence_location, 00150 void *base_addr, 00151 size_t context_size, 00152 int enable_multicast, 00153 int use_storable_context, 00154 int round_trip_timeout = 0, 00155 int use_round_trip_timeout = 0); 00156 00157 /// parses the arguments. 00158 int parse_args (int argc, ACE_TCHAR *argv[]); 00159 00160 /// Root NamingContext_ptr. 00161 CosNaming::NamingContext_var naming_context_; 00162 00163 /// The ior_multicast event handler. 00164 TAO_IOR_Multicast *ior_multicast_; 00165 00166 /// The IOR string of the root naming context. 00167 CORBA::String_var naming_service_ior_; 00168 00169 /** 00170 * Pointer to the object used to create/initialize 00171 * the Naming Service when local persistent Naming Service is 00172 * desired. 00173 */ 00174 TAO_Persistent_Context_Index *context_index_; 00175 00176 /// The ORB 00177 CORBA::ORB_var orb_; 00178 00179 /// The Root POA. 00180 PortableServer::POA_var root_poa_; 00181 00182 /// The Naming Service POA. 00183 PortableServer::POA_var ns_poa_; 00184 00185 /// File to output the Naming Service IOR. 00186 const ACE_TCHAR *ior_file_name_; 00187 00188 /// File to output the process id. 00189 const ACE_TCHAR *pid_file_name_; 00190 00191 /** 00192 * Size of the hash_table allocated upon the creation of the Naming 00193 * Service context (if one is created). Note: all the contexts 00194 * created under the given context will use the same size for their 00195 * initial hash table allocations. 00196 */ 00197 size_t context_size_; 00198 00199 /// Path to the file to be used to store/read in Naming Service 00200 /// persistent state. 00201 const ACE_TCHAR *persistence_file_name_; 00202 00203 /// Address to be used for memory mapping Naming Service state file, 00204 /// identified by the <persistence_file_name_>. 00205 void *base_address_; 00206 00207 /// If not zero multicast is enabled. 00208 int multicast_; 00209 00210 /// If not zero use flat file persistence 00211 int use_storable_context_; 00212 00213 /** 00214 * If not zero use servant activator that uses flat file persistence. 00215 */ 00216 int use_servant_activator_; 00217 00218 /** 00219 * Need to retain the servant activator between calls to 00220 * init_with_orb() and init_new_naming(). 00221 */ 00222 TAO_Storable_Naming_Context_Activator *servant_activator_; 00223 00224 /** 00225 * If not zero support redundant naming servers. 00226 */ 00227 int use_redundancy_; 00228 00229 // If not zero use round trip timeout policy set to value specified 00230 int round_trip_timeout_; 00231 int use_round_trip_timeout_; 00232 }; 00233 00234 TAO_END_VERSIONED_NAMESPACE_DECL 00235 00236 #include /**/ "ace/post.h" 00237 #endif /* TAO_NAMING_SERVER_H */