summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Locator_Repository.cpp
blob: 1ebdadd4612ff01cd51b65995741d51e353cec1f (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
// $Id$

#include "Locator_Repository.h"
#include "utils.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_ctype.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Vector_T.h"

Locator_Repository::Locator_Repository ()
: debug_ (0)
{
}

ACE_CString
Locator_Repository::lcase (const ACE_CString& s)
{
  ACE_CString ret(s);
  for (size_t i = 0; i < ret.length (); ++i)
    {
      ret[i] = static_cast<char>(ACE_OS::ace_tolower (s[i]));
    }
  return ret;
}

int
Locator_Repository::unregister_if_address_reused (
  const ACE_CString& server_id,
  const ACE_CString& name,
  const char* partial_ior)
{
  if (this->debug_ > 0)
  {
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)ImR: checking reuse address ")
      ACE_TEXT ("for server \"%C %C\" ior \"%C\"\n"),
      server_id.c_str(), name.c_str (), partial_ior));
  }

  ACE_Vector<ACE_CString> srvs;

  Locator_Repository::SIMap::ENTRY* sientry = 0;
  Locator_Repository::SIMap::ITERATOR siit (servers ());
  for (; siit.next (sientry); siit.advance() )
  {
    Server_Info_Ptr& info = sientry->int_id_;

    if (this->debug_)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)ImR: iterating - registered server")
        ACE_TEXT ("\"%C %C\" ior \"%C\"\n"), info->server_id.c_str(),
        info->name.c_str (), info->partial_ior.c_str ()));
    }

    if (info->partial_ior == partial_ior
      && name != info->name
      && info->server_id != server_id)
    {
      if (this->debug_)
      {
        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)ImR: reuse address %C so remove")
          ACE_TEXT ("server %C \n"), info->partial_ior.c_str (), info->name.c_str ()));
      }
      if (! info->name.empty ())
      {
        srvs.push_back (info->name);
      }
    }
  }

  int err = 0;
  for (size_t i = 0; i < srvs.size (); ++i)
  {

    if (this->remove_server (srvs[i]) != 0)
    {
      err = -1;
    }
  }

  return err;
}

int
Locator_Repository::add_server (const ACE_CString& server_id,
                        const ACE_CString& name,
                        const ACE_CString& aname,
                        const ACE_CString& startup_command,
                        const ImplementationRepository::EnvironmentList& env_vars,
                        const ACE_CString& working_dir,
                        ImplementationRepository::ActivationMode activation,
                        int start_limit,
                        const ACE_CString& partial_ior,
                        const ACE_CString& ior,
                        ImplementationRepository::ServerObject_ptr svrobj)
{
  int err = sync_load (name, SYNC_ADD, false);
  if (err != 0)
    {
      return err;
    }

  int limit = start_limit < 1 ? 1 : start_limit;
  Server_Info_Ptr info(new Server_Info (server_id, name, aname, startup_command,
    env_vars, working_dir, activation, limit, partial_ior, ior, svrobj));

  err = servers ().bind (name, info);
  if (err != 0)
    {
      return err;
    }
  this->persistent_update(info);
  return 0;
}

int
Locator_Repository::add_activator (const ACE_CString& name,
                        const CORBA::Long token,
                        const ACE_CString& ior,
                        ImplementationRepository::Activator_ptr act)
{
  int err = sync_load (name, SYNC_ADD, true);
  if (err != 0)
    {
      return err;
    }

  Activator_Info_Ptr info (new Activator_Info (name, token, ior, act));

  err = activators ().bind (lcase (name), info);
  if (err != 0)
    {
      return err;
    }
  this->persistent_update(info);
  return 0;
}

int
Locator_Repository::update_server (const Server_Info_Ptr& info)
{
  return this->persistent_update(info);
}

int
Locator_Repository::update_activator (const Activator_Info_Ptr& info)
{
  return this->persistent_update(info);
}

Server_Info_Ptr
Locator_Repository::get_server (const ACE_CString& name)
{
  Server_Info_Ptr server (0);
  servers ().find (name, server);
  return server;
}

Activator_Info_Ptr
Locator_Repository::get_activator (const ACE_CString& name)
{
  Activator_Info_Ptr activator (0);
  activators ().find (lcase (name), activator);
  return activator;
}

bool
Locator_Repository::has_activator (const ACE_CString& name)
{
  Activator_Info_Ptr activator (0);
  return activators().find (lcase (name), activator) == 0;
}

int
Locator_Repository::remove_server (const ACE_CString& name)
{
  int err = sync_load (name, SYNC_REMOVE, false);
  if (err != 0)
    {
      return err;
    }

  int ret = this->servers().unbind (name);
  if (ret != 0)
    {
      return ret;
    }

  return persistent_remove(name, false);
}

int
Locator_Repository::remove_activator (const ACE_CString& name)
{
  int err = sync_load (name, SYNC_REMOVE, true);
  if (err != 0)
    {
      return err;
    }

  int ret = activators().unbind (lcase(name));
  if (ret != 0)
    {
      return ret;
    }

  return persistent_remove(name, true);
}

Locator_Repository::SIMap&
Locator_Repository::servers (void)
{
  return server_infos_;
}

Locator_Repository::AIMap&
Locator_Repository::activators (void)
{
  return activator_infos_;
}

void
Locator_Repository::debug(int debug)
{
  this->debug_ = debug;
}

int
Locator_Repository::persistent_load ()
{
  // nothing more to do for default load
  return 0;
}

int
Locator_Repository::sync_load (const ACE_CString& , SyncOp , bool )
{
  // nothing more to do for default server/activator load
  return 0;
}

int
Locator_Repository::persistent_update (const Server_Info_Ptr& )
{
  // nothing more to do for default update
  return 0;
}

int
Locator_Repository::persistent_update(const Activator_Info_Ptr& )
{
  // nothing more to do for default update
  return 0;
}

int
Locator_Repository::persistent_remove(const ACE_CString& , bool )
{
  // nothing more to do for default update
  return 0;
}

No_Backing_Store::~No_Backing_Store()
{
}

const char*
No_Backing_Store::repo_mode() const
{
  return "Disabled";
}