summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ObjectReferenceFactory.h
blob: 6ca2b5b8597b72d545d98ed43bf48c977985807a (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
// -*- C++ -*-

//=============================================================================
/**
 * @file LB_ObjectReferenceFactory.h
 *
 * $Id$

 * @author Ossama Othman <ossama@uci.edu>
 */
//=============================================================================

#ifndef TAO_LB_OBJECT_REFERENCE_FACTORY_H
#define TAO_LB_OBJECT_REFERENCE_FACTORY_H

#include /**/ "ace/pre.h"

#include "orbsvcs/orbsvcs/LB_ORTC.h"

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

#if defined(_MSC_VER)
#if (_MSC_VER >= 1200)
#pragma warning(push)
#endif /* _MSC_VER >= 1200 */
#pragma warning(disable:4250)
#endif /* _MSC_VER */

#include "orbsvcs/orbsvcs/CosLoadBalancingC.h"

#include "ace/Array_Base.h"
#include "ace/Hash_Map_Manager_T.h"
#include "ace/Null_Mutex.h"

/**
 * @class TAO_LB_ObjectReferenceFactory
 *
 * @brief Implementation of the PortableInterceptor::ObjectReferenceFactory
 *        interface.
 *
 * This ObjectReferenceFactory creates an object group for a member of
 * the given repository ID (if instructed to do so), creates an
 * "unpublished" reference for that member, and adds it to the object
 * group via the LoadManager.
 */
class TAO_LB_ObjectReferenceFactory
  : public virtual CORBA::DefaultValueRefCountBase
  , public virtual OBV_TAO_LB::ObjectReferenceFactory
{
 public:

  /// Constructor
  TAO_LB_ObjectReferenceFactory (
    PortableInterceptor::ObjectReferenceFactory * old_orf,
    const CORBA::StringSeq & object_groups,
    const CORBA::StringSeq & repository_ids,
    const char * location,
    CORBA::ORB_ptr orb,
    CosLoadBalancing::LoadManager_ptr lm);

  /**
   * @name PortableInterceptor::ObjectReferenceFactory Methods
   *
   * Methods required by the
   * PortableInterceptor::ObjectReferenceFactory interface.
   */
  //@{
  virtual CORBA::Object_ptr make_object (
      const char * repository_id,
      const PortableInterceptor::ObjectId & id
      ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException));
  //@}


  typedef ACE_Hash_Map_Manager_Ex<
    ACE_CString,
    PortableGroup::ObjectGroup_var,
    ACE_Hash<ACE_CString>,
    ACE_Equal_To<ACE_CString>,
    ACE_Null_Mutex> Table;

  typedef ACE_Array_Base<
    PortableGroup::GenericFactory::FactoryCreationId_var> fcid_list;

protected:

  /// Destructor
  /**
   * Protected destructor to enforce proper memory management via
   * reference counting.
   */
  ~TAO_LB_ObjectReferenceFactory (void);

  /// Retrieve the object group reference for objects with the given
  /// RepositoryId.
  CORBA::Boolean find_object_group (const char * repository_id,
                                    CORBA::ULong & index,
                                    PortableGroup::ObjectGroup_out object_group
                                    ACE_ENV_ARG_DECL);

  /// Determine if object with given RepositoryId is load managed.
  CORBA::Boolean load_managed_object (const char * repository_id,
                                      CORBA::ULong & i);

private:

  /// The old ObjectReferenceFactory used to create object references.
  /**
   * This ObjectReferenceFactory will be used when creating object
   * references for non-load balanced objects.
   */
  PortableInterceptor::ObjectReferenceFactory_var old_orf_;


  /// List of stringified object group references.
  /**
   * All stringified object groups in this sequence have a one-to-one
   * correspondence to the repository IDs found in the repository_ids_
   * member below.
   *
   * @par
   *
   * The special string "CREATE" denotes that creation of a new object
   * group should be performed.
   */
  const CORBA::StringSeq object_groups_;

  /// List of RepositoryIds for object that will be load
  /// managed/balanced.
  /**
   * All RepositoryIds in this sequence have a one-to-one
   * correspondence to the stringified object references found in the
   * object_groups_ member above.
   */
  const CORBA::StringSeq repository_ids_;

  /// The configured location for the server within which this
  /// ObjectReferenceFactory resides.
  PortableGroup::Location location_;

  /// Table that maps repository ID to (non-stringified) object group
  /// reference.
  Table table_;

  /// List of FactoryCreationIds that will later be used to destroy
  /// object groups.
  fcid_list fcids_;

  /// Pseudo-reference to the ORB.
  CORBA::ORB_var orb_;

  /// Reference to the LoadManager object.
  CosLoadBalancing::LoadManager_var lm_;

  /// Array of flags that denotes whether or not an object group
  /// member of a given RepositoryId has been registered with the
  /// LoadManager.
  /**
   * The values are cached here to avoid querying the LoadManager,
   * which can be costly.
   */
  CORBA::Boolean * registered_members_;

};


#if defined (_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif /* _MSC_VER */

#include /**/ "ace/post.h"

#endif  /* TAO_LB_OBJECT_REFERENCE_FACTORY_H */