1 #include "Server_Info.h"
3 Server_Info::Server_Info (void)
8 Server_Info::Server_Info (const Server_Info
&other
)
14 Server_Info::operator= (const Server_Info
&other
)
18 server_id
= other
.server_id
;
19 poa_name
= other
.poa_name
;
20 is_jacorb
= other
.is_jacorb
;
21 key_name_
= other
.key_name_
;
22 activator
= other
.activator
;
23 cmdline
= other
.cmdline
;
25 activation_mode_
= other
.activation_mode_
;
26 start_limit_
= other
.start_limit_
;
27 start_count_
= other
.start_count_
;
28 partial_ior
= other
.partial_ior
;
30 last_ping
= other
.last_ping
;
31 server
= other
.server
;
32 alt_info_
= other
.alt_info_
;
34 death_notify
= other
.death_notify
;
36 env_vars
= other
.env_vars
;
41 Server_Info::Server_Info (const ACE_CString
& fqname
,
42 const ACE_CString
& aname
,
43 const ACE_CString
& cmdline
,
44 const ImplementationRepository::EnvironmentList
& env
,
45 const ACE_CString
& working_dir
,
46 ImplementationRepository::ActivationMode amode
,
48 const ACE_CString
& partial_ior
,
49 const ACE_CString
& server_ior
,
50 ImplementationRepository::ServerObject_ptr svrobj
)
59 , activation_mode_ (amode
)
62 , partial_ior (partial_ior
)
64 , server(ImplementationRepository::ServerObject::_duplicate (svrobj
))
68 , death_notify (false)
70 this->is_jacorb
= parse_id (fqname
.c_str(), this->server_id
, this->poa_name
);
71 Server_Info::gen_key (this->server_id
, this->poa_name
, this->key_name_
);
72 this->start_limit (limit
);
75 Server_Info::Server_Info (const ACE_CString
& serverId
,
76 const ACE_CString
& pname
,
79 : server_id (serverId
)
87 , activation_mode_ (ImplementationRepository::NORMAL
)
92 , server (ImplementationRepository::ServerObject::_nil())
96 , death_notify (false)
98 Server_Info::gen_key (this->server_id
, this->poa_name
, this->key_name_
);
102 Server_Info::active_info (void)
104 return this->alt_info_
.null() ? this : this->alt_info_
.get();
108 Server_Info::active_info (void) const
110 return this->alt_info_
.null() ? this : this->alt_info_
.get();
114 Server_Info::start_limit (int lim
)
116 this->active_info ()->start_limit_
= lim
< 0 ? -lim
: (lim
== 0 ? 1 : lim
);
120 Server_Info::is_mode (ImplementationRepository::ActivationMode m
) const
122 return this->active_info ()->activation_mode_
== m
;
125 ImplementationRepository::ActivationMode
126 Server_Info::mode (void) const
128 return this->active_info ()->activation_mode_
;
132 Server_Info::has_peer (const char *name
) const
134 return (this->key_name_
== name
|| this->poa_name
== name
);
138 Server_Info::is_server (const char *name
) const
140 for (CORBA::ULong i
= 0; i
< peers
.length(); i
++)
142 if (ACE_OS::strcmp (peers
[i
], name
) == 0)
149 Server_Info::is_running (void) const
151 return !CORBA::is_nil (this->server
.in()) || this->ior
.length () > 0;
155 Server_Info::start_allowed (void)
157 Server_Info
*active
= this->active_info ();
158 bool allowed
= active
->start_count_
< active
->start_limit_
;
161 active
->start_count_
++;
167 Server_Info::started (bool success
)
169 Server_Info
*active
= this->active_info ();
172 active
->start_count_
= 0;
177 Server_Info::parse_id (const char* id
,
178 ACE_CString
& server_id
,
183 size_t idx
= pname
.find (':');
184 if (idx
== ACE_CString::npos
)
188 server_id
= pname
.substr (0, idx
);
189 pname
= pname
.substr (idx
+ 1);
190 if (server_id
!= "JACORB")
194 idx
= pname
.find ('/');
195 if (idx
== ACE_CString::npos
)
201 server_id
= pname
.substr (0, idx
);
202 pname
= pname
.substr (idx
+ 1);
208 Server_Info::gen_id (const Server_Info
* si
, ACE_CString
&id
)
217 if (si
->server_id
.length() > 0)
219 id
+= si
->server_id
+ sep
;
225 Server_Info::gen_key (const ACE_CString
& serverId
,
226 const ACE_CString
& poa_name
,
229 if (serverId
.length () > 0)
231 key
= serverId
+ ":" + poa_name
;
240 Server_Info::fqname_to_key (const char * fqname
, ACE_CString
& key
)
242 ACE_CString serverId
;
243 ACE_CString poa_name
;
245 Server_Info::parse_id (fqname
, serverId
, poa_name
);
246 Server_Info::gen_key (serverId
, poa_name
, key
);
250 Server_Info::setImRInfo (ImplementationRepository::ServerInformation
* info
) const
253 Server_Info::gen_id (this, id
);
254 info
->server
= id
.c_str();
255 const Server_Info
*startup
= this->active_info ();
256 info
->startup
.command_line
= startup
->cmdline
.c_str ();
257 info
->startup
.environment
= startup
->env_vars
;
258 info
->startup
.working_directory
= startup
->dir
.c_str ();
259 info
->startup
.activation
= startup
->activation_mode_
;
260 info
->startup
.activator
= startup
->activator
.c_str ();
261 info
->startup
.start_limit
=
262 startup
->start_count_
>= startup
->start_limit_
? -startup
->start_limit_
: startup
->start_limit_
;
263 info
->partial_ior
= partial_ior
.c_str();
264 info
->activeStatus
= ImplementationRepository::ACTIVE_MAYBE
;
267 ImplementationRepository::ServerInformation
*
268 Server_Info::createImRServerInfo (void) const
270 ImplementationRepository::ServerInformation
* info
;
271 ACE_NEW_THROW_EX (info
,
272 ImplementationRepository::ServerInformation
,
273 CORBA::NO_MEMORY ());
274 this->setImRInfo (info
);
280 Server_Info::clear (void)
290 activation_mode_
= ImplementationRepository::NORMAL
;
295 last_ping
= ACE_Time_Value::zero
;
296 server
= ImplementationRepository::ServerObject::_nil ();
300 death_notify
= false;
304 Server_Info::reset_runtime (void)
306 this->partial_ior
= "";
307 Server_Info
*startup
= this->active_info ();
309 startup
->death_notify
= false;
310 startup
->last_ping
= ACE_Time_Value::zero
;
311 startup
->server
= ImplementationRepository::ServerObject::_nil ();
315 Server_Info::update_options (const ImplementationRepository::StartupOptions
&options
)
317 Server_Info
*startup
= this->active_info ();
318 startup
->activator
= options
.activator
.in ();
319 startup
->cmdline
= options
.command_line
.in ();
320 startup
->env_vars
= options
.environment
;
321 startup
->dir
= options
.working_directory
.in ();
322 startup
->activation_mode_
= options
.activation
;
323 startup
->start_limit (options
.start_limit
);
324 startup
->start_count_
= 0;
328 Server_Info::ping_id (void) const
330 return this->active_info ()->key_name_
.c_str();
334 Server_Info::set_contact (const char *pior
,
336 ImplementationRepository::ServerObject_ptr svrobj
)
338 this->partial_ior
= pior
;
339 Server_Info
*startup
= this->active_info ();
340 startup
->ior
= srv_ior
;
341 startup
->server
= ImplementationRepository::ServerObject::_duplicate (svrobj
);