Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / ImplRepo_Service / Shared_Backing_Store.h
blobf4c6ecc082e72dbd12bc56b632437a8eea00ee1f
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Shared_Backing_Store.h
7 * This class defines an implementation of the backing store as multiple XML files
8 * shared between multiple Locators.
10 * @author Darrell Brunsch <brunsch@cs.wustl.edu>
11 * @author Priyanka Gontla <gontla_p@ociweb.com>
13 //=============================================================================
15 #ifndef SHARED_BACKING_STORE_H
16 #define SHARED_BACKING_STORE_H
18 #include "ace/config-lite.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "XML_Backing_Store.h"
25 #include "Replicator.h"
26 #include "ace/Bound_Ptr.h"
27 #include "ace/Vector_T.h"
28 #include "ACEXML/common/DefaultHandler.h"
30 #include <set>
32 namespace {
33 class Lockable_File;
36 /**
37 * @class Shared_Backing_Store
39 * @brief XML backing store containing all ImR persistent information in
40 * multiple files shared between multiple Locators
43 class Shared_Backing_Store : public XML_Backing_Store
45 public:
46 typedef ImplementationRepository::UpdatePushNotification_var Replica_var;
47 typedef ImplementationRepository::UpdatePushNotification_ptr Replica_ptr;
48 struct UniqueId
50 Options::ImrType repo_type;
51 unsigned int repo_id;
52 ACE_TString repo_type_str;
53 ACE_TString repo_id_str;
54 ACE_TString unique_filename;
56 typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
57 UniqueId,
58 ACE_Hash<ACE_CString>,
59 ACE_Equal_To<ACE_CString>,
60 ACE_Null_Mutex> UniqueIdMap;
62 enum ExtraParams { REPO_TYPE = 0, REPO_ID = 1 };
64 Shared_Backing_Store (const Options& opts,
65 CORBA::ORB_ptr orb,
66 ImR_Locator_i *loc_impl);
68 virtual ~Shared_Backing_Store();
70 virtual void shutdown (void);
72 /// indicate the persistence mode for the repository
73 virtual const ACE_TCHAR* repo_mode() const;
75 /// enum to indicate whether the repo is in-sync, individual
76 /// server and/or activator files need to be sync-ed or if
77 /// a full sync of servers and activators is needed
78 enum SyncType { NO_SYNC, INC_SYNC, FULL_SYNC };
80 /// recover a persisted Server_Info object
81 /// @param info points to a newly created Server_Info object
82 /// @param server_started indicates if the server object
83 /// existed when data was persisted
84 /// @param extra_params extra name value pairs that
85 /// were reported for the server
86 virtual void load_server (Server_Info *info,
87 bool server_started,
88 const NameValues& extra_params);
90 /// create the Activator_Info activator object
91 /// @param activator_name the Activator_Info name
92 /// @param token the Activator_Info token
93 /// @param ior the Activator_Info ior
94 /// @param extra_params extra name value pairs that
95 /// were reported for the activator
96 virtual void load_activator (const ACE_CString& activator_name,
97 long token,
98 const ACE_CString& ior,
99 const NameValues& extra_params);
101 virtual void notify_remote_access (const char * id,
102 ImplementationRepository::AAM_Status s);
104 /// calls Locator_Repository::report_ior with the Fault Tolerant ImR
105 /// Locator's IOR if available, otherwise reporting the ior is delayed
106 /// until the peer replica registers with this replica
107 virtual int report_ior(PortableServer::POA_ptr imr_poa);
109 void gen_ior (char*& ft_imr_ior);
110 void updates_available (const ImplementationRepository::UpdateInfoSeq& info,
111 bool missed);
112 void process_updates (void);
114 protected:
115 /// perform shared backing store specific initialization
116 /// (activates this Shared_Backing_Store as the "ImR_Replica",
117 /// trys to connect to the peer replica, unless it is a
118 /// STANDALONE_IMR, clears out the persisted store if needed,
119 /// and loads the repo from the persisted store)
120 virtual int init_repo(PortableServer::POA_ptr imr_poa);
122 /// perform server persistent update
123 virtual int persistent_update(const Server_Info_Ptr& info, bool add);
125 /// perform activator persistent update
126 virtual int persistent_update(const Activator_Info_Ptr& info, bool add);
128 /// perform persistent remove
129 virtual int persistent_remove(const ACE_CString& name, bool activator);
131 /// perform sync of repo with backing store
132 /// uses sync_needed_ and sync_files_ to determine what to update
133 virtual int sync_load ();
135 /// create the Fault Tolerant ImR Locator IOR, using the peer_ior and
136 /// this ImR Locator's IOR
137 char* locator_service_ior(const char* peer_ior) const;
139 int connect_replicas (void);
141 private:
142 /// map management helper functions
143 void bind_unique_id (const ACE_CString& key,
144 UniqueIdMap& unique_ids,
145 const UniqueId& id);
147 void find_unique_id (const ACE_CString &key,
148 UniqueIdMap &unique_ids,
149 UniqueId &uid);
151 void update_unique_id (const ACE_CString &key,
152 UniqueIdMap& unique_ids,
153 Options::ImrType& entry_repo_type,
154 unsigned int& entry_repo_id,
155 UniqueId& uid);
157 void verify_unique_id (const ACE_CString& key,
158 const XML_Backing_Store::NameValues& extra_params,
159 UniqueIdMap& unique_ids);
161 private:
163 * Callback SAX XML Handler for parsing the imr_listings.xml file.
165 class LocatorListings_XMLHandler : public ACEXML_DefaultHandler
167 public:
168 /// constructor
169 /// @param dir the directory path to add to the server or activator
170 /// filename
171 LocatorListings_XMLHandler(const ACE_TString& dir);
173 /// constructor for tracking only changes to what servers and activators
174 /// are currently in the repo
175 /// @param dir the directory path to add to the server or activator
176 /// filename
177 /// @param servers a map of servers currently in the repo
178 /// @param activators a map of activators currently in the repo
179 LocatorListings_XMLHandler(const ACE_TString& dir,
180 const Locator_Repository::SIMap& servers,
181 const Locator_Repository::AIMap& activators);
183 /// provide implementation for handling a new XML element
184 virtual void startElement (const ACEXML_Char* namespaceURI,
185 const ACEXML_Char* localName,
186 const ACEXML_Char* qName,
187 ACEXML_Attributes* attrs);
189 /// provide implementation for handling terminating an XML element
190 virtual void endElement (const ACEXML_Char* namespaceURI,
191 const ACEXML_Char* localName,
192 const ACEXML_Char* qName);
194 /// remove the servers and activators that were in the repo but not
195 /// in the listings file (this does nothing if existing servers and
196 /// activators were not provided in constructor)
197 void remove_unmatched(Locator_Repository& repo);
199 /// the filenames identified in the listings file, if tracking changes
200 /// only then only the filenames of the new servers and activators
201 const ACE_Vector<ACE_TString>& filenames() const;
203 private:
204 /// the directory to add to the listings file relative filenames
205 const ACE_TString& dir_;
206 /// the filenames identified in the listings file (or the new filenames)
207 ACE_Vector<ACE_TString> filenames_;
208 /// the existing servers in the repo that were not present in the
209 /// listings file
210 Locator_Repository::SIMap unmatched_servers_;
211 /// the existing activators in the repo that were not present in the
212 /// listings file
213 Locator_Repository::AIMap unmatched_activators_;
214 /// indicates if only changes should be tracked
215 const bool only_changes_;
217 typedef ACE_Strong_Bound_Ptr
218 <LocatorListings_XMLHandler, ACE_Null_Mutex> XMLHandler_Ptr;
220 /// determine the filename where the replica ior is reported
221 /// @param peer_ior_file if this is the filename for the peer
222 /// replica or this replica
223 ACE_CString replica_ior_filename(bool peer_ior_file) const;
225 /// get the listings file contents
226 /// @param listing_lf a Lockable_File for the listings file
227 /// that will be locked when the function returns
228 /// @param only_changes if only changes to the repo should be
229 /// reported
230 /// @return a pointer to the LocatorListings_XMLHandler
231 XMLHandler_Ptr get_listings(Lockable_File& listing_lf,
232 bool only_changes) const;
234 /// perform a persistent load from the backing store
235 /// @param only_changes if only changes to the repo should be
236 /// loaded
237 int persistent_load(bool only_changes);
239 /// persistent the listings file
240 /// @param listing_lf a Lockable_File for the listings file
241 /// that will be locked when the function returns
242 int persist_listings(Lockable_File& listing_lf);
244 /// write content to the listings file and optionally its backup
245 /// @param list File pointer to write to. Can be primary or backup.
246 void write_listing(FILE *list);
248 /// connect this replica to its peer replica
249 /// @param this_replica a pointer to this Replica object
250 int connect_replicas(Replica_ptr this_replica);
252 /// the path and filename for the listings file
253 const ACE_TString listing_file_;
254 /// the imr type of this Shared_Backing_Store
255 const Options::ImrType imr_type_;
256 /// the current type of sync needed by the repo
257 SyncType sync_needed_;
258 /// the server and activator files that need to be updated for
259 /// sync_needed_ == INC_SYNC
260 std::set<ACE_TString> sync_files_;
261 /// the ior for just this ImR Locator
262 CORBA::String_var non_ft_imr_ior_;
263 /// an array associating ImrType with the appropriate name
264 const char* IMR_REPLICA[3];
265 /// map for server unique ids
266 UniqueIdMap server_uids_;
267 /// map for activator unique ids
268 UniqueIdMap activator_uids_;
269 /// next unique repo id
270 unsigned int repo_id_;
271 /// extra parameters for XML
272 XML_Backing_Store::NameValues repo_values_;
273 /// reference to the locator implmentation
274 ImR_Locator_i *loc_impl_;
276 /* TAO_SYNCH_MUTEX sync_lock_; */
278 Replicator replicator_;
280 ImplementationRepository::UpdateInfoSeq updates_;
282 bool notified_;
284 class Update_Handler : public ACE_Event_Handler
286 public :
287 Shared_Backing_Store *owner_;
288 Update_Handler (Shared_Backing_Store *owner) : owner_ (owner) {}
289 int handle_exception (ACE_HANDLE);
290 } update_handler_;
294 #endif /* SHARED_BACKING_STORE_H */