Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / FT_ReplicaFactory_i.h
blobc584181925ac249e86e05483c6a366a818e6ec57
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 ();
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 ();
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);
115 virtual void delete_object (
116 const PortableGroup::GenericFactory::FactoryCreationId & factory_creation_id);
118 //////////////////////////////////////////
119 // CORBA interface PullMonitorable methods
121 virtual CORBA::Boolean is_alive ();
123 /////////////////////////
124 // Implementation methods
125 private:
127 * Actual replica creation happens in this method.
128 * @param name becomes part of the objects identity.
130 FT_TestReplica_i * create_replica(const char * name);
133 * Find or allocate an ID for a new replica
135 CORBA::ULong allocate_id();
138 * Write this factory's IOR to a file
140 int write_ior (const ACE_TCHAR * outputFile, const char * ior);
143 * Clean house for factory shut down.
145 void shutdown_i ();
147 ///////////////
148 // Data Members
149 private:
151 * Protect internal state.
152 * Mutex should be locked by corba methods, or by
153 * external (public) methods before calling implementation
154 * methods.
155 * Implementation methods should assume the mutex is
156 * locked if necessary.
158 TAO_SYNCH_MUTEX internals_;
161 * The orb
163 CORBA::ORB_var orb_;
166 * The POA used to activate this object.
168 PortableServer::POA_var poa_;
171 * The CORBA object id assigned to this object.
173 PortableServer::ObjectId_var object_id_;
176 * IOR of this object as assigned by poa
178 CORBA::String_var ior_;
181 * A file to which the factory's IOR should be written.
183 const ACE_TCHAR * ior_output_file_;
186 * A human-readable string to distinguish this from other Notifiers.
188 ACE_TString identity_;
191 * bool: true if we found a replication manager
193 int have_replication_manager_;
196 * The replication manager
199 ::FT::ReplicationManager_var replication_manager_;
203 * The factory registry IOR
205 const ACE_TCHAR * factory_registry_ior_;
208 * The factory registry with which to register.
210 PortableGroup::FactoryRegistry_var factory_registry_;
213 * true if registered with FactoryRegistry
215 int registered_; // bool
218 * A file to which the test replica's IOR will be written
220 const ACE_TCHAR * test_output_file_;
223 * A name to be used to register the factory with the name service.
225 ACE_CString ns_name_;
227 CosNaming::NamingContext_var naming_context_;
229 CosNaming::Name this_name_;
231 /////////////////
232 // The roles used to register types
233 StringVec roles_;
236 * the PortableGroup::Location within the domain
238 ACE_CString location_;
241 * bool: quit on idle flag.
243 int quit_on_idle_;
246 * bool: use a single call to unregister.
248 int unregister_by_location_;
251 * A vector of Replicas. Note that the Replica ID
252 * is an index into this vector.
254 ReplicaVec replicas_;
257 * count of entries in Replicas_ that have been deleted.
258 * Used to determine when the factory is idle and to avoid futile
259 * searches for empty slots.
261 size_t empty_slots_;
264 * boolean: starts false. Set to true when it's time to quit.
266 int quit_requested_;
269 * A file that use by FT_TestReplica_i object
271 const ACE_TCHAR* name_persistent_file_;
274 #endif /* FT_REPLICAFACTORY_H_ */