summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h
blob: 6439f95212cf096c9a5db6c625d25a73365431ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// -*- C++ -*-
//=============================================================================
/**
 *  @file    PG_Object_Group.h
 *
 *  $Id$
 *
 *  Manage all information related to an object group.
 *  @@ Note: the above description is optimistic.  The hope is to eventually
 *  @@ consolidate all information related to an object group into this object.
 *  @@ however at the moment GenericFactory, ObjectGroupManager, and FT_ReplicationManager
 *  @@ have parallel collections of object group information.
 *
 *  @author Dale Wilson <wilson_d@ociweb.com>
 */
//=============================================================================

#ifndef TAO_PG_OBJECT_GROUP_H_
#define TAO_PG_OBJECT_GROUP_H_
#include /**/ <ace/pre.h>
#include <ace/ACE.h>

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

//////////////////////////////////
// Classes declared in this header
namespace TAO
{
  class PG_Object_Group;
}

/////////////////////////////////
// Includes needed by this header
#include <orbsvcs/PortableGroupC.h>
#include <tao/PortableServer/PortableServer.h>
#include <ace/Hash_Map_Manager_T.h>
#include "PG_Location_Hash.h"
#include "PG_Location_Equal_To.h"


/////////////////////
// Forward references

namespace TAO
{
  /**
   */
  class TAO_PortableGroup_Export PG_Object_Group
  {

    // Information about an object group member
    struct MemberInfo
    {
      /// Reference to the object.
      CORBA::Object_var member_;
      /// The factory that was used to create this object
      /// nil if application created.
      PortableGroup::GenericFactory_var factory_;
      /// FactoryCreationId assigned to the member. Empty if application created
      PortableGroup::GenericFactory::FactoryCreationId factory_id_;
      /// Construct an application-supplied member.
      MemberInfo (CORBA::Object_var member);
      /// Construct a infrastructure-created member.
      MemberInfo (
        CORBA::Object_var member, 
        PortableGroup::GenericFactory_var factory, 
        PortableGroup::GenericFactory::FactoryCreationId factory_id);
      ~MemberInfo();
    };

    typedef TAO_SYNCH_MUTEX MemberMapMutex;
    typedef ACE_Hash_Map_Manager_Ex <
      PortableGroup::Location, 
      MemberInfo *,
      TAO_PG_Location_Hash,
      TAO_PG_Location_Equal_To,
      MemberMapMutex>  MemberMap;
    typedef ACE_Hash_Map_Entry <PortableGroup::Location, MemberInfo *> MemberMap_Entry;
    typedef ACE_Hash_Map_Iterator_Ex <
      PortableGroup::Location, 
      MemberInfo *, 
      TAO_PG_Location_Hash,
      TAO_PG_Location_Equal_To,
      MemberMapMutex> MemberMap_Iterator;
    
  public:
    /// Constructor
    PG_Object_Group ();

    /// Constructor
    PG_Object_Group (
      PortableGroup::ObjectGroupId oid,
      const char * type_id,
      PortableGroup::Criteria the_criteria);

    /// Destructor
    ~PG_Object_Group ();

    
    /////////////////
    // public methods

  public:


    void set_oid (PortableGroup::ObjectGroupId oid);
    void set_typeid (PortableGroup::TypeId type_id);
    void set_properties (PortableGroup::Criteria the_criteria);
    /**
     *
     * @ param reference the new IOGR for this group.
     * @ distribute bool if true, distribute IOGR to all members
     */
    void set_reference (PortableGroup::ObjectGroup_ptr reference, int distribute);

    PortableGroup::ObjectGroup_ptr reference()const;

    void set_membership_style (PortableGroup::MembershipStyleValue style);
    PortableGroup::MembershipStyleValue membership_style () const;

    void initial_number_replicas (PortableGroup::InitialNumberReplicasValue count);
    PortableGroup::InitialNumberReplicasValue initial_number_replicas () const;

    void set_minimum_number_replicas (PortableGroup::MinimumNumberReplicasValue count);
    PortableGroup::MinimumNumberReplicasValue minimum_number_replicas ()const;

    void set_group_specific_factories (const PortableGroup::FactoryInfos & infos);
    /**
     * Note the caller receives a copy of the factoryinfos in the result argument.
     * inefficient, but thread safe.
     */
    void group_specific_factories (PortableGroup::FactoryInfos & result) const;

    // Note: primary location is a concept from FT CORBA.
    // It doesn't hurt other PortableGroup-based services to 
    // have these two metods and the underlying member.
    void set_primary_location (PortableGroup::Location & primary_location_);
    const PortableGroup::Location & primary_location() const;

    /**
     * returns a duplicate
     * caller must release
     */
    PortableGroup::TypeId get_type_id ()const;

    void get_properties (PortableGroup::Properties_var & result) const;

    /////////////////////////////////////////////
    // Applicable ObjectGroupManager(OGM) methods
    // The following methods in OGM all have an object group as the
    // first parameter.  The OGM should implement these methods by finding
    // the corresponding TAO_PG_Object_Group and delegating to these methods.
#ifdef NOT_IMPLEMENTED
    void create_member (
        const PortableGroup::Location & the_location,
        const char * type_id,
        const PortableGroup::Criteria & the_criteria
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((
        CORBA::SystemException,
        PortableGroup::MemberAlreadyPresent,
        PortableGroup::ObjectNotCreated,
        PortableGroup::InvalidCriteria,
        PortableGroup::CannotMeetCriteria));
#endif

    void add_member (
        const PortableGroup::Location & the_location,
        CORBA::Object_ptr member
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((
        CORBA::SystemException,
        PortableGroup::MemberAlreadyPresent,
        PortableGroup::ObjectNotAdded));

#ifdef NOT_IMPLEMENTED
    void remove_member (
        const PortableGroup::Location & the_location
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((
        CORBA::SystemException,
        PortableGroup::MemberNotFound));
#endif

#ifdef NOT_IMPLEMENTED
    void locations_of_members (
        PortableGroup::Locations & locations
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((CORBA::SystemException));
#endif

    PortableGroup::ObjectGroupId  get_object_group_id () const;

#ifdef NOT_IMPLEMENTED
    CORBA::Object_ptr get_member_ref (
        const PortableGroup::Location & loc
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((
        CORBA::SystemException,
        PortableGroup::MemberNotFound));
#endif

#ifdef NOT_IMPLEMENTED
    void set_properties_dynamically (
        const PortableGroup::Properties & overrides
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       PortableGroup::InvalidProperty,
                       PortableGroup::UnsupportedProperty));

#endif

    /////////////////////////
    // Implementation methods
  private:

    /////////////////////////
    // Forbidden methods
  private:
    PG_Object_Group (const PG_Object_Group & rhs);
    PG_Object_Group & operator = (const PG_Object_Group & rhs);
  

    /////////////////
    // Static Methods
  public:
    /**
     * Set the poa to be used to manage object groups
     * Note: this is NOT the poa used to create object group members.
     * @param poa a reference to a var to avoid reference count confusion.
     */
    void set_poa (PortableServer::POA_var & poa);

    ///////////////
    // Static Data
  private:
    /**
     * The POA used to manage object groups
     */
    static PortableServer::POA_var poa_;


    ///////////////
    // Data Members
  private:

    /**
     * Protect internal state.
     * Implementation methods should assume the mutex is
     * locked if necessary.
     */
    ACE_SYNCH_MUTEX internals_;
    typedef ACE_Guard<ACE_SYNCH_MUTEX> InternalGuard;

    ACE_CString role_;
    PortableGroup::TypeId type_id_;
    PortableGroup::ObjectGroupId group_id_;
    /**
     * the reference (IOGR) to this group
     */
    PortableGroup::ObjectGroup_var reference_;

    /**
     * The CORBA object id assigned to this object group
     */
    PortableServer::ObjectId_var object_id_;

    // group members
    MemberMap members_;

    PortableGroup::Location primary_location_;

    // Cached property information

    PortableGroup::MembershipStyleValue membership_style_;
    PortableGroup::InitialNumberReplicasValue initial_number_replicas_;
    PortableGroup::MinimumNumberReplicasValue minimum_number_replicas_;
    PortableGroup::FactoryInfos group_specific_factories_;

    // Miscellaneous properties passed to create_object when this group
    // was initially created.  To be used to create new replicas.
    PortableGroup::Properties properties_;

  };
} // namespace TAO

#include /**/ <ace/post.h>

#endif // TAO_PG_OBJECT_GROUP_H_