summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Server.h
blob: 0b80de5dd72e6170b81fef519deb7f7bc0d90e17 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    FT_Naming_Server.h
 *
 *
 *    Implement functionality necessary for fault tolerant naming service.
 *    Adds support for Object Group Manager interfaces as well.  This class
 *    extends the TAO_Naming_Server.
 *
 *  @author Kevin Stanley
 */
//=============================================================================
//

#ifndef TAO_FT_NAMING_SERVER_H
#define TAO_FT_NAMING_SERVER_H

#include "orbsvcs/Naming/Naming_Server.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Replication_Manager.h"
#include "orbsvcs/Naming/FaultTolerant/ftnaming_export.h"
#include "tao/IORManipulation/IORManip_Loader.h"
#include "orbsvcs/FT_NamingReplicationC.h"
#include "ace/Recursive_Thread_Mutex.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

class TAO_FT_Naming_Server;

class TAO_FTNS_Notifier : public ACE_Event_Handler
{
public:
  TAO_FTNS_Notifier (TAO_FT_Naming_Server &owner, bool iors);

  virtual int handle_exception (ACE_HANDLE );

  TAO_FT_Naming_Server &owner_;
  bool iors_;
};


/**
 * @class TAO_FT_Naming_Server
 *
 * @brief Defines a class derived from the TAO_Naming_Server to extend
   the functionality to support an ObjectGroupManager interface and a
   load balancing capability for objects that are bound within an object
   group within the naming service. The Naming Service will extend the
   resolve and resolve_str operations to perform load balancing on the
   objects within the object group using a specified load balancing
   strategy.
 */
class TAO_FtNaming_Export TAO_FT_Naming_Server : public TAO_Naming_Server
{
public:
  friend class TAO_FTNS_Notifier;

  TAO_FT_Naming_Server (void);

  /// Initialize the Naming Service and Object Group Manager with the command line
  /// arguments and the ORB. Overrridden from TAO_Naming_Server
  virtual int init_with_orb (int , ACE_TCHAR * [], CORBA::ORB_ptr orb);

  /**
   * Accessors and mutators for object references.
   */
  /// Returns a <NamingContext_ptr> for the root Naming Context.
  CosNaming::NamingContext_ptr my_root_context () const;
  CosNaming::NamingContext_ptr ft_root_context () const;

  /// Returns the reference for this servers local naming manager servant.
  ::FT_Naming::NamingManager_ptr my_naming_manager () const;
  ::FT_Naming::NamingManager_ptr ft_naming_manager () const;

  /// Initialize the naming manager with the ORB.
  int init_naming_manager_with_orb (int , ACE_TCHAR * [], CORBA::ORB_ptr orb);

  int init_replicator ();

  ACE_TString replica_ior_filename (bool ) const;

/// Setup pairing with peer replica.
  /// Returns 0 on successful pairing with peer.
  /// Returns 1 if peer IOR file is present, but peer is not responding
  /// Returns -1 if pairing is not possible.
  void init_replication_pairing (void);

  void no_replica (void);

  //  TAO_FTNS_Notifier &notifier (void);

  /// Overridden parse operation. Only allows options supported by the FT_Naming_Server
  /// and adds options for the object group manager
  virtual int parse_args (int argc,
                          ACE_TCHAR *argv[]);

  /// Factory method to create a naming context factory for use with
  /// the -u and -r options.
  virtual TAO_Storable_Naming_Context_Factory *
    storable_naming_context_factory (size_t context_size);

  /// Factory method to create a naming context factory for use with
  /// the -f option.
  virtual TAO_Persistent_Naming_Context_Factory *
    persistent_naming_context_factory (void);

  /// Returns the IOR of the replication manager.
  char* replicator_ior ();

  /// Returns the IOR of the naming manager.
  char * naming_manager_ior ();

  virtual int update_object_group (
    const ::FT_Naming::ObjectGroupUpdate & group_info);

  virtual int update_naming_context (
    const ::FT_Naming::NamingContextUpdate & naming_context);

  void update_ior (FT_Naming::EntityKind, const CORBA::Object_ptr);
  void combine_iors (FT_Naming::EntityKind, const CORBA::Object_ptr);

  const ACE_CString & ft_endpoint ();
  const ACE_Time_Value & ft_update_delay ();

  /// Destroy the child POAs created in @c init_with_orb,
  /// @c init_naming_manager_with_orb, and
  /// @c init_replication_manager_with_orb
  virtual int fini ();

  /// Destructor.
  virtual ~TAO_FT_Naming_Server ();

  void update_info (FT_Naming::UpdateInfoSeq &infos);
  void update_iors (const FT_Naming::ReplicaInfo & iors);
  void update_info_i ();
  void update_iors_i ();

protected:

  enum FT_IOR_Indexes {
    PEER_ROOT = 1,
    FT_ROOT,
    GROUP,
    PEER_GROUP,
    FT_GROUP,
    REPLICATOR,
    IOR_ARRAY_SIZE
  };

  int recover_iors (void);

  /// The object that implements the ObjectGroupManager, PropertyManager,
  /// and GenericFactory interfaces.
  TAO_FT_Naming_Manager naming_manager_;

  /// The object that implements the FT_Naming::Replication_Manager
  /// interface.
  TAO_FT_Naming_Replication_Manager* replicator_;

  /// The Object Group Manager POA.
  PortableServer::POA_var naming_manager_poa_;

  int use_object_group_persistence_;
  ACE_TString object_group_dir_;

  /// The role this server is supporting in the dual redundant
  /// replication scheme.
  enum ServerRole { PRIMARY, BACKUP, STANDALONE };

  /// The role this server is to take on. Controlled by the
  /// --primary or --backup command line arguments.  Defaults
  /// to STANDALONE if no role is provided in command line.
  ServerRole server_role_;

  /// Lock used to serialize access to fault tolerant extensions
  /// to Naming Service.
  TAO_SYNCH_RECURSIVE_MUTEX lock_;

  /// The endpoint used by the replicator ORB, otherwise it
  /// just picks one
  ACE_CString ft_endpoint_;

  /// The minimum amount of time to wait before issuing a new
  /// update notice to the peer. Heavily loaded systems may want
  /// to use this option to avoid overloading the peer with lots
  /// of small, possibly contradictory changes. During the delay
  /// time, the replicator will hold update notices, removing
  /// earlier ones in favor of later updates.
  ACE_Time_Value ft_update_delay_;

  bool registered_;

  TAO_FTNS_Notifier ior_notifier_;
  TAO_FTNS_Notifier info_notifier_;

  ACE_Unbounded_Queue<FT_Naming::ReplicaInfo> u_iors_;
  ACE_Unbounded_Queue<FT_Naming::UpdateInfoSeq*> u_infos_;
  TAO_SYNCH_MUTEX ior_lock_;
  TAO_SYNCH_MUTEX info_lock_;


 };

TAO_END_VERSIONED_NAMESPACE_DECL

#endif /* TAO_FT_NAMING_SERVER_H */