Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / FT_ReplicaFactory_i.h
blobc050b32ea8c1c9a631bd3cc0e68ab28a8dd382ed
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file FT_ReplicaFactory_i.h
6 * This file is part of Fault Tolerant CORBA.
7 * It declares the implementation of ReplicaFactory which
8 * creates and manages replicas as an agent for
9 * the ReplicationManager as defined in the FT CORBA specification.
11 * @author Dale Wilson <wilson_d@ociweb.com>
13 //=============================================================================
15 #ifndef FT_REPLICAFACTORY_H_
16 #define FT_REPLICAFACTORY_H_
17 #include <ace/ACE.h>
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 //////////////////////////////////
23 // Classes declared in this header
24 class FT_ReplicaFactory_i;
26 /////////////////////////////////
27 // Includes needed by this header
28 #include <ace/Vector_T.h>
29 #include "FT_TestReplicaS.h"
30 #include <ace/Thread_Manager.h>
31 #include <ace/SString.h>
32 #include <orbsvcs/FT_ReplicationManagerC.h>
34 /////////////////////
35 // Forward references
36 class TAO_ORB_Manager;
37 class FT_TestReplica_i;
39 /**
40 * Implement the GenericFactory interface.
42 class FT_ReplicaFactory_i
43 //FT_TEST::ReplicaFactory
44 : public virtual POA_PortableGroup::GenericFactory
46 typedef ACE_Vector<FT_TestReplica_i *> ReplicaVec;
47 typedef ACE_Vector<ACE_CString> StringVec;
49 //////////////////////
50 // non-CORBA interface
51 public:
52 /**
53 * Default constructor.
55 FT_ReplicaFactory_i ();
57 /**
58 * Virtual destructor.
60 virtual ~FT_ReplicaFactory_i ();
62 /**
63 * Parse command line arguments.
64 * @param argc traditional C argc
65 * @param argv traditional C argv
66 * @return zero for success; nonzero is process return code for failure.
68 int parse_args (int argc, ACE_TCHAR * argv[]);
70 /**
71 * Initialize this object.
72 * @param orb our ORB -- we keep var to it.
73 * @return zero for success; nonzero is process return code for failure.
75 int init (CORBA::ORB_ptr orb);
77 /**
78 * Prepare to exit.
79 * @return zero for success; nonzero is process return code for failure.
81 int fini (void);
83 int idle(int & result);
86 /**
87 * Identify this replica factory.
88 * @return a string to identify this object for logging/console message purposes.
90 const ACE_TCHAR * identity () const;
92 const char * location () const;
94 /**
95 * Remove pointer to individual replica; delete FT_TestReplica_i.
96 * See replica life cycle description.
97 * @param id the numerical id assigned to this replica.
98 * @param replica a pointer to the Replica object (redundant for safety.)
100 void remove_replica (CORBA::ULong id, FT_TestReplica_i * replica);
102 //////////////////
103 // CORBA interface
104 // See IDL for documentation
106 virtual void shutdown (void);
108 /////////////////////////////////////////
109 // CORBA interface GenericFactory methods
110 virtual CORBA::Object_ptr create_object (
111 const char * type_id,
112 const PortableGroup::Criteria & the_criteria,
113 PortableGroup::GenericFactory::FactoryCreationId_out factory_creation_id
116 virtual void delete_object (
117 const PortableGroup::GenericFactory::FactoryCreationId & factory_creation_id
120 //////////////////////////////////////////
121 // CORBA interface PullMonitorable methods
123 virtual CORBA::Boolean is_alive (void);
125 /////////////////////////
126 // Implementation methods
127 private:
129 * Actual replica creation happens in this method.
130 * @param name becomes part of the objects identity.
132 FT_TestReplica_i * create_replica(const char * name);
135 * Find or allocate an ID for a new replica
137 CORBA::ULong allocate_id();
140 * Write this factory's IOR to a file
142 int write_ior (const ACE_TCHAR * outputFile, const char * ior);
145 * Clean house for factory shut down.
147 void shutdown_i ();
149 ///////////////
150 // Data Members
151 private:
154 * Protect internal state.
155 * Mutex should be locked by corba methods, or by
156 * external (public) methods before calling implementation
157 * methods.
158 * Implementation methods should assume the mutex is
159 * locked if necessary.
161 TAO_SYNCH_MUTEX internals_;
164 * The orb
166 CORBA::ORB_var orb_;
169 * The POA used to activate this object.
171 PortableServer::POA_var poa_;
174 * The CORBA object id assigned to this object.
176 PortableServer::ObjectId_var object_id_;
179 * IOR of this object as assigned by poa
181 CORBA::String_var ior_;
184 * A file to which the factory's IOR should be written.
186 const ACE_TCHAR * ior_output_file_;
189 * A human-readable string to distinguish this from other Notifiers.
191 ACE_TString identity_;
194 * bool: true if we found a replication manager
196 int have_replication_manager_;
199 * The replication manager
202 ::FT::ReplicationManager_var replication_manager_;
206 * The factory registry IOR
208 const ACE_TCHAR * factory_registry_ior_;
211 * The factory registry with which to register.
213 PortableGroup::FactoryRegistry_var factory_registry_;
216 * true if registered with FactoryRegistry
218 int registered_; // bool
221 * A file to which the test replica's IOR will be written
223 const ACE_TCHAR * test_output_file_;
226 * A name to be used to register the factory with the name service.
228 ACE_CString ns_name_;
230 CosNaming::NamingContext_var naming_context_;
232 CosNaming::Name this_name_;
234 /////////////////
235 // The roles used to register types
236 StringVec roles_;
239 * the PortableGroup::Location within the domain
241 ACE_CString location_;
244 * bool: quit on idle flag.
246 int quit_on_idle_;
249 * bool: use a single call to unregister.
251 int unregister_by_location_;
254 * A vector of Replicas. Note that the Replica ID
255 * is an index into this vector.
257 ReplicaVec replicas_;
260 * count of entries in Replicas_ that have been deleted.
261 * Used to determine when the factory is idle and to avoid futile
262 * searches for empty slots.
264 size_t empty_slots_;
267 * boolean: starts false. Set to true when it's time to quit.
269 int quit_requested_;
272 * A file that use by FT_TestReplica_i object
274 const ACE_TCHAR* name_persistent_file_;
278 #endif /* FT_REPLICAFACTORY_H_ */