| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Diagnostics; |
| | | 4 | | using System.Globalization; |
| | | 5 | | using System.Text; |
| | | 6 | | |
| | | 7 | | namespace Ice.Internal; |
| | | 8 | | |
| | | 9 | | public sealed class BufSizeWarnInfo |
| | | 10 | | { |
| | | 11 | | // Whether send size warning has been emitted |
| | | 12 | | public bool sndWarn; |
| | | 13 | | |
| | | 14 | | // The send size for which the warning was emitted |
| | | 15 | | public int sndSize; |
| | | 16 | | |
| | | 17 | | // Whether receive size warning has been emitted |
| | | 18 | | public bool rcvWarn; |
| | | 19 | | |
| | | 20 | | // The receive size for which the warning was emitted |
| | | 21 | | public int rcvSize; |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | public sealed class Instance |
| | | 25 | | { |
| | | 26 | | private class ObserverUpdaterI : Ice.Instrumentation.ObserverUpdater |
| | | 27 | | { |
| | 1 | 28 | | public ObserverUpdaterI(Instance instance) => _instance = instance; |
| | | 29 | | |
| | 1 | 30 | | public void updateConnectionObservers() => _instance.updateConnectionObservers(); |
| | | 31 | | |
| | 1 | 32 | | public void updateThreadObservers() => _instance.updateThreadObservers(); |
| | | 33 | | |
| | | 34 | | private readonly Instance _instance; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public Ice.InitializationData initializationData() => |
| | | 38 | | // |
| | | 39 | | // No check for destruction. It must be possible to access the |
| | | 40 | | // initialization data after destruction. |
| | | 41 | | // |
| | | 42 | | // No mutex lock, immutable. |
| | | 43 | | // |
| | | 44 | | _initData; |
| | | 45 | | |
| | | 46 | | public TraceLevels traceLevels() |
| | | 47 | | { |
| | | 48 | | // No mutex lock, immutable. |
| | | 49 | | Debug.Assert(_traceLevels != null); |
| | | 50 | | return _traceLevels; |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public DefaultsAndOverrides defaultsAndOverrides() |
| | | 54 | | { |
| | | 55 | | // No mutex lock, immutable. |
| | | 56 | | Debug.Assert(_defaultsAndOverrides != null); |
| | | 57 | | return _defaultsAndOverrides; |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | public RouterManager routerManager() |
| | | 61 | | { |
| | | 62 | | lock (_mutex) |
| | | 63 | | { |
| | | 64 | | if (_state == StateDestroyed) |
| | | 65 | | { |
| | | 66 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 67 | | } |
| | | 68 | | |
| | | 69 | | Debug.Assert(_routerManager != null); |
| | | 70 | | return _routerManager; |
| | | 71 | | } |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | public LocatorManager locatorManager() |
| | | 75 | | { |
| | | 76 | | lock (_mutex) |
| | | 77 | | { |
| | | 78 | | if (_state == StateDestroyed) |
| | | 79 | | { |
| | | 80 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | Debug.Assert(_locatorManager != null); |
| | | 84 | | return _locatorManager; |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | internal ReferenceFactory referenceFactory() |
| | | 89 | | { |
| | | 90 | | lock (_mutex) |
| | | 91 | | { |
| | | 92 | | if (_state == StateDestroyed) |
| | | 93 | | { |
| | | 94 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | Debug.Assert(_referenceFactory != null); |
| | | 98 | | return _referenceFactory; |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | internal OutgoingConnectionFactory outgoingConnectionFactory() |
| | | 103 | | { |
| | | 104 | | lock (_mutex) |
| | | 105 | | { |
| | | 106 | | if (_state == StateDestroyed) |
| | | 107 | | { |
| | | 108 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | Debug.Assert(_outgoingConnectionFactory != null); |
| | | 112 | | return _outgoingConnectionFactory; |
| | | 113 | | } |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | public ObjectAdapterFactory objectAdapterFactory() |
| | | 117 | | { |
| | | 118 | | lock (_mutex) |
| | | 119 | | { |
| | | 120 | | if (_state == StateDestroyed) |
| | | 121 | | { |
| | | 122 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | Debug.Assert(_objectAdapterFactory != null); |
| | | 126 | | return _objectAdapterFactory; |
| | | 127 | | } |
| | | 128 | | } |
| | | 129 | | |
| | | 130 | | public int protocolSupport() => _protocolSupport; |
| | | 131 | | |
| | | 132 | | public bool preferIPv6() => _preferIPv6; |
| | | 133 | | |
| | | 134 | | public NetworkProxy networkProxy() => _networkProxy; |
| | | 135 | | |
| | | 136 | | public ThreadPool clientThreadPool() |
| | | 137 | | { |
| | | 138 | | lock (_mutex) |
| | | 139 | | { |
| | | 140 | | if (_state == StateDestroyed) |
| | | 141 | | { |
| | | 142 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 143 | | } |
| | | 144 | | |
| | | 145 | | Debug.Assert(_clientThreadPool != null); |
| | | 146 | | return _clientThreadPool; |
| | | 147 | | } |
| | | 148 | | } |
| | | 149 | | |
| | | 150 | | public ThreadPool serverThreadPool() |
| | | 151 | | { |
| | | 152 | | lock (_mutex) |
| | | 153 | | { |
| | | 154 | | if (_state == StateDestroyed) |
| | | 155 | | { |
| | | 156 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 157 | | } |
| | | 158 | | |
| | | 159 | | if (_serverThreadPool == null) // Lazy initialization. |
| | | 160 | | { |
| | | 161 | | if (_state == StateDestroyInProgress) |
| | | 162 | | { |
| | | 163 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 164 | | } |
| | | 165 | | int timeout = _initData.properties.getIcePropertyAsInt("Ice.ServerIdleTime"); |
| | | 166 | | _serverThreadPool = new ThreadPool(this, "Ice.ThreadPool.Server", timeout); |
| | | 167 | | } |
| | | 168 | | |
| | | 169 | | return _serverThreadPool; |
| | | 170 | | } |
| | | 171 | | } |
| | | 172 | | |
| | | 173 | | public EndpointHostResolver endpointHostResolver() |
| | | 174 | | { |
| | | 175 | | lock (_mutex) |
| | | 176 | | { |
| | | 177 | | if (_state == StateDestroyed) |
| | | 178 | | { |
| | | 179 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 180 | | } |
| | | 181 | | |
| | | 182 | | Debug.Assert(_endpointHostResolver != null); |
| | | 183 | | return _endpointHostResolver; |
| | | 184 | | } |
| | | 185 | | } |
| | | 186 | | |
| | | 187 | | public RetryQueue |
| | | 188 | | retryQueue() |
| | | 189 | | { |
| | | 190 | | lock (_mutex) |
| | | 191 | | { |
| | | 192 | | if (_state == StateDestroyed) |
| | | 193 | | { |
| | | 194 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 195 | | } |
| | | 196 | | |
| | | 197 | | Debug.Assert(_retryQueue != null); |
| | | 198 | | return _retryQueue; |
| | | 199 | | } |
| | | 200 | | } |
| | | 201 | | |
| | | 202 | | public Timer |
| | | 203 | | timer() |
| | | 204 | | { |
| | | 205 | | lock (_mutex) |
| | | 206 | | { |
| | | 207 | | if (_state == StateDestroyed) |
| | | 208 | | { |
| | | 209 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 210 | | } |
| | | 211 | | |
| | | 212 | | Debug.Assert(_timer != null); |
| | | 213 | | return _timer; |
| | | 214 | | } |
| | | 215 | | } |
| | | 216 | | |
| | | 217 | | public EndpointFactoryManager endpointFactoryManager() |
| | | 218 | | { |
| | | 219 | | lock (_mutex) |
| | | 220 | | { |
| | | 221 | | if (_state == StateDestroyed) |
| | | 222 | | { |
| | | 223 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 224 | | } |
| | | 225 | | |
| | | 226 | | Debug.Assert(_endpointFactoryManager != null); |
| | | 227 | | return _endpointFactoryManager; |
| | | 228 | | } |
| | | 229 | | } |
| | | 230 | | |
| | | 231 | | public Ice.PluginManager pluginManager() |
| | | 232 | | { |
| | | 233 | | lock (_mutex) |
| | | 234 | | { |
| | | 235 | | if (_state == StateDestroyed) |
| | | 236 | | { |
| | | 237 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 238 | | } |
| | | 239 | | |
| | | 240 | | Debug.Assert(_pluginManager != null); |
| | | 241 | | return _pluginManager; |
| | | 242 | | } |
| | | 243 | | } |
| | | 244 | | |
| | | 245 | | public int messageSizeMax() => |
| | | 246 | | // No mutex lock, immutable. |
| | | 247 | | _messageSizeMax; |
| | | 248 | | |
| | | 249 | | public int batchAutoFlushSize() => |
| | | 250 | | // No mutex lock, immutable. |
| | | 251 | | _batchAutoFlushSize; |
| | | 252 | | |
| | | 253 | | public int classGraphDepthMax() => |
| | | 254 | | // No mutex lock, immutable. |
| | | 255 | | _classGraphDepthMax; |
| | | 256 | | |
| | | 257 | | public Ice.ToStringMode |
| | | 258 | | toStringMode() => |
| | | 259 | | // No mutex lock, immutable |
| | | 260 | | _toStringMode; |
| | | 261 | | |
| | | 262 | | public int cacheMessageBuffers() => |
| | | 263 | | // No mutex lock, immutable. |
| | | 264 | | _cacheMessageBuffers; |
| | | 265 | | |
| | | 266 | | public Ice.ImplicitContextI getImplicitContext() => _implicitContext; |
| | | 267 | | |
| | | 268 | | public Ice.ObjectPrx createAdmin(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity) |
| | | 269 | | { |
| | | 270 | | bool createAdapter = adminAdapter == null; |
| | | 271 | | |
| | | 272 | | lock (_mutex) |
| | | 273 | | { |
| | | 274 | | if (_state == StateDestroyed) |
| | | 275 | | { |
| | | 276 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 277 | | } |
| | | 278 | | |
| | | 279 | | if (adminIdentity == null || adminIdentity.name.Length == 0) |
| | | 280 | | { |
| | | 281 | | throw new ArgumentException("The admin identity is not valid", nameof(adminIdentity)); |
| | | 282 | | } |
| | | 283 | | |
| | | 284 | | if (_adminAdapter != null) |
| | | 285 | | { |
| | | 286 | | throw new Ice.InitializationException("Admin already created"); |
| | | 287 | | } |
| | | 288 | | |
| | | 289 | | if (!_adminEnabled) |
| | | 290 | | { |
| | | 291 | | throw new Ice.InitializationException("Admin is disabled"); |
| | | 292 | | } |
| | | 293 | | |
| | | 294 | | if (createAdapter) |
| | | 295 | | { |
| | | 296 | | if (_initData.properties.getIceProperty("Ice.Admin.Endpoints").Length > 0) |
| | | 297 | | { |
| | | 298 | | adminAdapter = _objectAdapterFactory.createObjectAdapter( |
| | | 299 | | "Ice.Admin", |
| | | 300 | | router: null, |
| | | 301 | | serverAuthenticationOptions: null); |
| | | 302 | | } |
| | | 303 | | else |
| | | 304 | | { |
| | | 305 | | throw new Ice.InitializationException("Ice.Admin.Endpoints is not set"); |
| | | 306 | | } |
| | | 307 | | } |
| | | 308 | | |
| | | 309 | | _adminIdentity = adminIdentity; |
| | | 310 | | _adminAdapter = adminAdapter; |
| | | 311 | | addAllAdminFacets(); |
| | | 312 | | } |
| | | 313 | | |
| | | 314 | | if (createAdapter) |
| | | 315 | | { |
| | | 316 | | try |
| | | 317 | | { |
| | | 318 | | adminAdapter.activate(); |
| | | 319 | | } |
| | | 320 | | catch (Ice.LocalException) |
| | | 321 | | { |
| | | 322 | | // |
| | | 323 | | // We cleanup _adminAdapter, however this error is not recoverable |
| | | 324 | | // (can't call again getAdmin() after fixing the problem) |
| | | 325 | | // since all the facets (servants) in the adapter are lost |
| | | 326 | | // |
| | | 327 | | adminAdapter.destroy(); |
| | | 328 | | lock (_mutex) |
| | | 329 | | { |
| | | 330 | | _adminAdapter = null; |
| | | 331 | | } |
| | | 332 | | throw; |
| | | 333 | | } |
| | | 334 | | } |
| | | 335 | | setServerProcessProxy(adminAdapter, adminIdentity); |
| | | 336 | | return adminAdapter.createProxy(adminIdentity); |
| | | 337 | | } |
| | | 338 | | |
| | | 339 | | public Ice.ObjectPrx |
| | | 340 | | getAdmin() |
| | | 341 | | { |
| | | 342 | | Ice.ObjectAdapter adminAdapter; |
| | | 343 | | Ice.Identity adminIdentity; |
| | | 344 | | |
| | | 345 | | lock (_mutex) |
| | | 346 | | { |
| | | 347 | | if (_state == StateDestroyed) |
| | | 348 | | { |
| | | 349 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | if (_adminAdapter != null) |
| | | 353 | | { |
| | | 354 | | return _adminAdapter.createProxy(_adminIdentity); |
| | | 355 | | } |
| | | 356 | | else if (_adminEnabled) |
| | | 357 | | { |
| | | 358 | | if (_initData.properties.getIceProperty("Ice.Admin.Endpoints").Length > 0) |
| | | 359 | | { |
| | | 360 | | adminAdapter = _objectAdapterFactory.createObjectAdapter( |
| | | 361 | | "Ice.Admin", |
| | | 362 | | router: null, |
| | | 363 | | serverAuthenticationOptions: null); |
| | | 364 | | } |
| | | 365 | | else |
| | | 366 | | { |
| | | 367 | | return null; |
| | | 368 | | } |
| | | 369 | | adminIdentity = new Ice.Identity( |
| | | 370 | | "admin", |
| | | 371 | | _initData.properties.getIceProperty("Ice.Admin.InstanceName")); |
| | | 372 | | if (adminIdentity.category.Length == 0) |
| | | 373 | | { |
| | | 374 | | adminIdentity.category = System.Guid.NewGuid().ToString(); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | _adminIdentity = adminIdentity; |
| | | 378 | | _adminAdapter = adminAdapter; |
| | | 379 | | addAllAdminFacets(); |
| | | 380 | | // continue below outside synchronization |
| | | 381 | | } |
| | | 382 | | else |
| | | 383 | | { |
| | | 384 | | return null; |
| | | 385 | | } |
| | | 386 | | } |
| | | 387 | | |
| | | 388 | | try |
| | | 389 | | { |
| | | 390 | | adminAdapter.activate(); |
| | | 391 | | } |
| | | 392 | | catch (Ice.LocalException) |
| | | 393 | | { |
| | | 394 | | // |
| | | 395 | | // We cleanup _adminAdapter, however this error is not recoverable |
| | | 396 | | // (can't call again getAdmin() after fixing the problem) |
| | | 397 | | // since all the facets (servants) in the adapter are lost |
| | | 398 | | // |
| | | 399 | | adminAdapter.destroy(); |
| | | 400 | | lock (_mutex) |
| | | 401 | | { |
| | | 402 | | _adminAdapter = null; |
| | | 403 | | } |
| | | 404 | | throw; |
| | | 405 | | } |
| | | 406 | | |
| | | 407 | | setServerProcessProxy(adminAdapter, adminIdentity); |
| | | 408 | | return adminAdapter.createProxy(adminIdentity); |
| | | 409 | | } |
| | | 410 | | |
| | | 411 | | public void |
| | | 412 | | addAdminFacet(Ice.Object servant, string facet) |
| | | 413 | | { |
| | | 414 | | lock (_mutex) |
| | | 415 | | { |
| | | 416 | | if (_state == StateDestroyed) |
| | | 417 | | { |
| | | 418 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 419 | | } |
| | | 420 | | |
| | | 421 | | if (_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet))) |
| | | 422 | | { |
| | | 423 | | if (_adminFacets.ContainsKey(facet)) |
| | | 424 | | { |
| | | 425 | | throw new Ice.AlreadyRegisteredException("facet", facet); |
| | | 426 | | } |
| | | 427 | | _adminFacets.Add(facet, servant); |
| | | 428 | | } |
| | | 429 | | else |
| | | 430 | | { |
| | | 431 | | _adminAdapter.addFacet(servant, _adminIdentity, facet); |
| | | 432 | | } |
| | | 433 | | } |
| | | 434 | | } |
| | | 435 | | |
| | | 436 | | public Ice.Object |
| | | 437 | | removeAdminFacet(string facet) |
| | | 438 | | { |
| | | 439 | | lock (_mutex) |
| | | 440 | | { |
| | | 441 | | if (_state == StateDestroyed) |
| | | 442 | | { |
| | | 443 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 444 | | } |
| | | 445 | | |
| | | 446 | | Ice.Object result = null; |
| | | 447 | | if (_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet))) |
| | | 448 | | { |
| | | 449 | | try |
| | | 450 | | { |
| | | 451 | | result = _adminFacets[facet]; |
| | | 452 | | } |
| | | 453 | | catch (KeyNotFoundException) |
| | | 454 | | { |
| | | 455 | | throw new Ice.NotRegisteredException("facet", facet); |
| | | 456 | | } |
| | | 457 | | |
| | | 458 | | _adminFacets.Remove(facet); |
| | | 459 | | } |
| | | 460 | | else |
| | | 461 | | { |
| | | 462 | | result = _adminAdapter.removeFacet(_adminIdentity, facet); |
| | | 463 | | } |
| | | 464 | | return result; |
| | | 465 | | } |
| | | 466 | | } |
| | | 467 | | |
| | | 468 | | public Ice.Object |
| | | 469 | | findAdminFacet(string facet) |
| | | 470 | | { |
| | | 471 | | lock (_mutex) |
| | | 472 | | { |
| | | 473 | | if (_state == StateDestroyed) |
| | | 474 | | { |
| | | 475 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 476 | | } |
| | | 477 | | |
| | | 478 | | Ice.Object result = null; |
| | | 479 | | if (_adminAdapter == null || (_adminFacetFilter.Count > 0 && !_adminFacetFilter.Contains(facet))) |
| | | 480 | | { |
| | | 481 | | try |
| | | 482 | | { |
| | | 483 | | result = _adminFacets[facet]; |
| | | 484 | | } |
| | | 485 | | catch (KeyNotFoundException) |
| | | 486 | | { |
| | | 487 | | } |
| | | 488 | | } |
| | | 489 | | else |
| | | 490 | | { |
| | | 491 | | result = _adminAdapter.findFacet(_adminIdentity, facet); |
| | | 492 | | } |
| | | 493 | | return result; |
| | | 494 | | } |
| | | 495 | | } |
| | | 496 | | |
| | | 497 | | public Dictionary<string, Ice.Object> |
| | | 498 | | findAllAdminFacets() |
| | | 499 | | { |
| | | 500 | | lock (_mutex) |
| | | 501 | | { |
| | | 502 | | if (_state == StateDestroyed) |
| | | 503 | | { |
| | | 504 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 505 | | } |
| | | 506 | | |
| | | 507 | | if (_adminAdapter == null) |
| | | 508 | | { |
| | | 509 | | return new Dictionary<string, Ice.Object>(_adminFacets); |
| | | 510 | | } |
| | | 511 | | else |
| | | 512 | | { |
| | | 513 | | Dictionary<string, Ice.Object> result = _adminAdapter.findAllFacets(_adminIdentity); |
| | | 514 | | if (_adminFacets.Count > 0) |
| | | 515 | | { |
| | | 516 | | foreach (KeyValuePair<string, Ice.Object> p in _adminFacets) |
| | | 517 | | { |
| | | 518 | | result.Add(p.Key, p.Value); |
| | | 519 | | } |
| | | 520 | | } |
| | | 521 | | return result; |
| | | 522 | | } |
| | | 523 | | } |
| | | 524 | | } |
| | | 525 | | |
| | | 526 | | public void |
| | | 527 | | setDefaultLocator(Ice.LocatorPrx locator) |
| | | 528 | | { |
| | | 529 | | lock (_mutex) |
| | | 530 | | { |
| | | 531 | | if (_state == StateDestroyed) |
| | | 532 | | { |
| | | 533 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 534 | | } |
| | | 535 | | |
| | | 536 | | _referenceFactory = _referenceFactory.setDefaultLocator(locator); |
| | | 537 | | } |
| | | 538 | | } |
| | | 539 | | |
| | | 540 | | public void |
| | | 541 | | setDefaultRouter(Ice.RouterPrx router) |
| | | 542 | | { |
| | | 543 | | lock (_mutex) |
| | | 544 | | { |
| | | 545 | | if (_state == StateDestroyed) |
| | | 546 | | { |
| | | 547 | | throw new Ice.CommunicatorDestroyedException(); |
| | | 548 | | } |
| | | 549 | | |
| | | 550 | | _referenceFactory = _referenceFactory.setDefaultRouter(router); |
| | | 551 | | } |
| | | 552 | | } |
| | | 553 | | |
| | | 554 | | internal void setLogger(Logger logger) |
| | | 555 | | { |
| | | 556 | | // Only called by the LoggerPlugin constructor, so no need to lock. |
| | | 557 | | if (_ownLogger) |
| | | 558 | | { |
| | | 559 | | _initData.logger!.Dispose(); |
| | | 560 | | } |
| | | 561 | | _initData.logger = logger; |
| | | 562 | | _ownLogger = true; |
| | | 563 | | } |
| | | 564 | | |
| | | 565 | | public void |
| | | 566 | | setThreadHook(System.Action threadStart, System.Action threadStop) |
| | | 567 | | { |
| | | 568 | | // |
| | | 569 | | // No locking, as it can only be called during plug-in loading |
| | | 570 | | // |
| | | 571 | | _initData.threadStart = threadStart; |
| | | 572 | | _initData.threadStop = threadStop; |
| | | 573 | | } |
| | | 574 | | |
| | | 575 | | internal void addSliceLoader(SliceLoader loader) => _applicationSliceLoader.add(loader); |
| | | 576 | | |
| | | 577 | | // |
| | | 578 | | // Only for use by Ice.Communicator |
| | | 579 | | // |
| | | 580 | | internal void initialize(Ice.Communicator communicator, Ice.InitializationData initData) |
| | | 581 | | { |
| | | 582 | | _state = StateActive; |
| | | 583 | | _initData = initData; |
| | | 584 | | |
| | | 585 | | try |
| | | 586 | | { |
| | | 587 | | _initData.properties ??= new Properties(); |
| | | 588 | | |
| | | 589 | | string programName = _initData.properties.getIceProperty("Ice.ProgramName"); |
| | | 590 | | if (programName.Length == 0) |
| | | 591 | | { |
| | | 592 | | _initData.properties.setProperty("Ice.ProgramName", AppDomain.CurrentDomain.FriendlyName); |
| | | 593 | | // Re-read it to mark it as used. |
| | | 594 | | programName = _initData.properties.getIceProperty("Ice.ProgramName"); |
| | | 595 | | } |
| | | 596 | | |
| | | 597 | | lock (_staticLock) |
| | | 598 | | { |
| | | 599 | | if (!_oneOffDone) |
| | | 600 | | { |
| | | 601 | | string stdOut = _initData.properties.getIceProperty("Ice.StdOut"); |
| | | 602 | | string stdErr = _initData.properties.getIceProperty("Ice.StdErr"); |
| | | 603 | | |
| | | 604 | | System.IO.StreamWriter outStream = null; |
| | | 605 | | |
| | | 606 | | if (stdOut.Length > 0) |
| | | 607 | | { |
| | | 608 | | try |
| | | 609 | | { |
| | | 610 | | outStream = System.IO.File.AppendText(stdOut); |
| | | 611 | | } |
| | | 612 | | catch (IOException ex) |
| | | 613 | | { |
| | | 614 | | throw new FileException($"Cannot append to '{stdOut}'", ex); |
| | | 615 | | } |
| | | 616 | | outStream.AutoFlush = true; |
| | | 617 | | Console.Out.Close(); |
| | | 618 | | Console.SetOut(outStream); |
| | | 619 | | } |
| | | 620 | | if (stdErr.Length > 0) |
| | | 621 | | { |
| | | 622 | | if (stdErr.Equals(stdOut, StringComparison.Ordinal)) |
| | | 623 | | { |
| | | 624 | | Console.SetError(outStream); |
| | | 625 | | } |
| | | 626 | | else |
| | | 627 | | { |
| | | 628 | | System.IO.StreamWriter errStream = null; |
| | | 629 | | try |
| | | 630 | | { |
| | | 631 | | errStream = System.IO.File.AppendText(stdErr); |
| | | 632 | | } |
| | | 633 | | catch (IOException ex) |
| | | 634 | | { |
| | | 635 | | throw new FileException($"Cannot append to '{stdErr}'", ex); |
| | | 636 | | } |
| | | 637 | | errStream.AutoFlush = true; |
| | | 638 | | Console.Error.Close(); |
| | | 639 | | Console.SetError(errStream); |
| | | 640 | | } |
| | | 641 | | } |
| | | 642 | | |
| | | 643 | | _oneOffDone = true; |
| | | 644 | | } |
| | | 645 | | } |
| | | 646 | | |
| | | 647 | | if (_initData.logger is null) |
| | | 648 | | { |
| | | 649 | | string logfile = _initData.properties.getIceProperty("Ice.LogFile"); |
| | | 650 | | if (logfile.Length != 0) |
| | | 651 | | { |
| | | 652 | | _initData.logger = new FileLoggerI(programName, logfile); |
| | | 653 | | _ownLogger = true; |
| | | 654 | | } |
| | | 655 | | else if (Ice.Util.getProcessLogger() is LoggerI) |
| | | 656 | | { |
| | | 657 | | // |
| | | 658 | | // Ice.ConsoleListener is enabled by default. |
| | | 659 | | // |
| | | 660 | | bool console = _initData.properties.getIcePropertyAsInt("Ice.ConsoleListener") > 0; |
| | | 661 | | _initData.logger = new TraceLoggerI(programName, console); |
| | | 662 | | _ownLogger = true; |
| | | 663 | | } |
| | | 664 | | else |
| | | 665 | | { |
| | | 666 | | _initData.logger = Ice.Util.getProcessLogger(); |
| | | 667 | | // _ownLogger remains false |
| | | 668 | | } |
| | | 669 | | } |
| | | 670 | | // else _ownLogger remains false |
| | | 671 | | |
| | | 672 | | _traceLevels = new TraceLevels(_initData.properties); |
| | | 673 | | |
| | | 674 | | _defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties, _initData.logger); |
| | | 675 | | |
| | | 676 | | clientConnectionOptions = readConnectionOptions("Ice.Connection.Client"); |
| | | 677 | | _serverConnectionOptions = readConnectionOptions("Ice.Connection.Server"); |
| | | 678 | | |
| | | 679 | | // The maximum size of an Ice protocol message in bytes. This is limited to 0x7fffffff, which corresponds to |
| | | 680 | | // the maximum value of a 32-bit signed integer (int). |
| | | 681 | | const int messageSizeMaxUpperLimit = int.MaxValue; |
| | | 682 | | int messageSizeMax = _initData.properties.getIcePropertyAsInt("Ice.MessageSizeMax"); |
| | | 683 | | if (messageSizeMax > messageSizeMaxUpperLimit / 1024) |
| | | 684 | | { |
| | | 685 | | throw new Ice.InitializationException( |
| | | 686 | | $"Ice.MessageSizeMax '{messageSizeMax}' is too large, it must be less than or equal to '{messageSize |
| | | 687 | | } |
| | | 688 | | else if (messageSizeMax < 1) |
| | | 689 | | { |
| | | 690 | | _messageSizeMax = messageSizeMaxUpperLimit; |
| | | 691 | | } |
| | | 692 | | else |
| | | 693 | | { |
| | | 694 | | // The property is specified in kibibytes (KiB); _messageSizeMax is stored in bytes. |
| | | 695 | | _messageSizeMax = messageSizeMax * 1024; |
| | | 696 | | } |
| | | 697 | | |
| | | 698 | | int batchAutoFlushSize = _initData.properties.getIcePropertyAsInt("Ice.BatchAutoFlushSize"); |
| | | 699 | | if (batchAutoFlushSize > messageSizeMaxUpperLimit / 1024) |
| | | 700 | | { |
| | | 701 | | throw new Ice.InitializationException( |
| | | 702 | | $"Ice.BatchAutoFlushSize '{batchAutoFlushSize}' is too large, it must be less than or equal to '{mes |
| | | 703 | | } |
| | | 704 | | else if (batchAutoFlushSize < 1) |
| | | 705 | | { |
| | | 706 | | _batchAutoFlushSize = messageSizeMaxUpperLimit; |
| | | 707 | | } |
| | | 708 | | else |
| | | 709 | | { |
| | | 710 | | // The property is specified in kibibytes (KiB); _batchAutoFlushSize is stored in bytes. |
| | | 711 | | _batchAutoFlushSize = batchAutoFlushSize * 1024; |
| | | 712 | | } |
| | | 713 | | |
| | | 714 | | int classGraphDepthMax = _initData.properties.getIcePropertyAsInt("Ice.ClassGraphDepthMax"); |
| | | 715 | | if (classGraphDepthMax < 1) |
| | | 716 | | { |
| | | 717 | | _classGraphDepthMax = 0x7fffffff; |
| | | 718 | | } |
| | | 719 | | else |
| | | 720 | | { |
| | | 721 | | _classGraphDepthMax = classGraphDepthMax; |
| | | 722 | | } |
| | | 723 | | |
| | | 724 | | // Update _initData.sliceLoader |
| | | 725 | | |
| | | 726 | | if (_initData.sliceLoader is not null) |
| | | 727 | | { |
| | | 728 | | _applicationSliceLoader.add(_initData.sliceLoader); |
| | | 729 | | } |
| | | 730 | | |
| | | 731 | | // We create a lazy Slice loader that searches assemblies the first time we unmarshal a class or |
| | | 732 | | // exception. At that time, all the assemblies should have been loaded. |
| | | 733 | | var lazySliceLoader = new LazySliceLoader( |
| | | 734 | | () => SliceLoader.fromAssemblies(AppDomain.CurrentDomain.GetAssemblies())); |
| | | 735 | | |
| | | 736 | | _initData.sliceLoader = new CompositeSliceLoader(_applicationSliceLoader, lazySliceLoader); |
| | | 737 | | |
| | | 738 | | string toStringModeStr = _initData.properties.getIceProperty("Ice.ToStringMode"); |
| | | 739 | | if (toStringModeStr == "Unicode") |
| | | 740 | | { |
| | | 741 | | _toStringMode = Ice.ToStringMode.Unicode; |
| | | 742 | | } |
| | | 743 | | else if (toStringModeStr == "ASCII") |
| | | 744 | | { |
| | | 745 | | _toStringMode = Ice.ToStringMode.ASCII; |
| | | 746 | | } |
| | | 747 | | else if (toStringModeStr == "Compat") |
| | | 748 | | { |
| | | 749 | | _toStringMode = Ice.ToStringMode.Compat; |
| | | 750 | | } |
| | | 751 | | else |
| | | 752 | | { |
| | | 753 | | throw new Ice.InitializationException( |
| | | 754 | | "The value for Ice.ToStringMode must be Unicode, ASCII or Compat"); |
| | | 755 | | } |
| | | 756 | | |
| | | 757 | | _cacheMessageBuffers = _initData.properties.getIcePropertyAsInt("Ice.CacheMessageBuffers"); |
| | | 758 | | |
| | | 759 | | _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getIceProperty("Ice.ImplicitContext")); |
| | | 760 | | _routerManager = new RouterManager(); |
| | | 761 | | |
| | | 762 | | _locatorManager = new LocatorManager(_initData.properties); |
| | | 763 | | |
| | | 764 | | _referenceFactory = new ReferenceFactory(this, communicator); |
| | | 765 | | |
| | | 766 | | bool isIPv6Supported = Network.isIPv6Supported(); |
| | | 767 | | bool ipv4 = _initData.properties.getIcePropertyAsInt("Ice.IPv4") > 0; |
| | | 768 | | bool ipv6 = isIPv6Supported && _initData.properties.getIcePropertyAsInt("Ice.IPv6") > 0; |
| | | 769 | | if (!ipv4 && !ipv6) |
| | | 770 | | { |
| | | 771 | | throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled."); |
| | | 772 | | } |
| | | 773 | | else if (ipv4 && ipv6) |
| | | 774 | | { |
| | | 775 | | _protocolSupport = Network.EnableBoth; |
| | | 776 | | } |
| | | 777 | | else if (ipv4) |
| | | 778 | | { |
| | | 779 | | _protocolSupport = Network.EnableIPv4; |
| | | 780 | | } |
| | | 781 | | else |
| | | 782 | | { |
| | | 783 | | _protocolSupport = Network.EnableIPv6; |
| | | 784 | | } |
| | | 785 | | _preferIPv6 = _initData.properties.getIcePropertyAsInt("Ice.PreferIPv6Address") > 0; |
| | | 786 | | |
| | | 787 | | _networkProxy = createNetworkProxy(_initData.properties, _protocolSupport); |
| | | 788 | | |
| | | 789 | | _sslEngine = new Ice.SSL.SSLEngine(communicator); |
| | | 790 | | |
| | | 791 | | _endpointFactoryManager = new EndpointFactoryManager(this); |
| | | 792 | | |
| | | 793 | | var tcpInstance = new ProtocolInstance(this, Ice.TCPEndpointType.value, "tcp", false); |
| | | 794 | | _endpointFactoryManager.add(new TcpEndpointFactory(tcpInstance)); |
| | | 795 | | |
| | | 796 | | var udpInstance = new ProtocolInstance(this, Ice.UDPEndpointType.value, "udp", false); |
| | | 797 | | _endpointFactoryManager.add(new UdpEndpointFactory(udpInstance)); |
| | | 798 | | |
| | | 799 | | var wsInstance = new ProtocolInstance(this, Ice.WSEndpointType.value, "ws", false); |
| | | 800 | | _endpointFactoryManager.add(new WSEndpointFactory(wsInstance, Ice.TCPEndpointType.value)); |
| | | 801 | | |
| | | 802 | | var sslInstance = new Ice.SSL.Instance(_sslEngine, Ice.SSLEndpointType.value, "ssl"); |
| | | 803 | | _endpointFactoryManager.add(new Ice.SSL.EndpointFactoryI(sslInstance, Ice.TCPEndpointType.value)); |
| | | 804 | | |
| | | 805 | | var wssInstance = new ProtocolInstance(this, Ice.WSSEndpointType.value, "wss", true); |
| | | 806 | | _endpointFactoryManager.add(new WSEndpointFactory(wssInstance, Ice.SSLEndpointType.value)); |
| | | 807 | | |
| | | 808 | | _pluginManager = new Ice.PluginManagerI(communicator); |
| | | 809 | | |
| | | 810 | | _outgoingConnectionFactory = new OutgoingConnectionFactory(this); |
| | | 811 | | |
| | | 812 | | _objectAdapterFactory = new ObjectAdapterFactory(this, communicator); |
| | | 813 | | |
| | | 814 | | _retryQueue = new RetryQueue(this); |
| | | 815 | | |
| | | 816 | | string[] retryValues = _initData.properties.getIcePropertyAsList("Ice.RetryIntervals"); |
| | | 817 | | if (retryValues.Length == 0) |
| | | 818 | | { |
| | | 819 | | retryIntervals = [0]; |
| | | 820 | | } |
| | | 821 | | else |
| | | 822 | | { |
| | | 823 | | retryIntervals = new int[retryValues.Length]; |
| | | 824 | | |
| | | 825 | | for (int i = 0; i < retryValues.Length; i++) |
| | | 826 | | { |
| | | 827 | | int v; |
| | | 828 | | |
| | | 829 | | try |
| | | 830 | | { |
| | | 831 | | v = int.Parse(retryValues[i], CultureInfo.InvariantCulture); |
| | | 832 | | } |
| | | 833 | | catch (System.FormatException) |
| | | 834 | | { |
| | | 835 | | v = 0; |
| | | 836 | | } |
| | | 837 | | |
| | | 838 | | // |
| | | 839 | | // If -1 is the first value, no retry and wait intervals. |
| | | 840 | | // |
| | | 841 | | if (i == 0 && v == -1) |
| | | 842 | | { |
| | | 843 | | retryIntervals = []; |
| | | 844 | | break; |
| | | 845 | | } |
| | | 846 | | |
| | | 847 | | retryIntervals[i] = v > 0 ? v : 0; |
| | | 848 | | } |
| | | 849 | | } |
| | | 850 | | |
| | | 851 | | if (_initData.properties.getIcePropertyAsInt("Ice.PreloadAssemblies") > 0) |
| | | 852 | | { |
| | | 853 | | AssemblyUtil.preloadAssemblies(); |
| | | 854 | | } |
| | | 855 | | } |
| | | 856 | | catch (Ice.LocalException) |
| | | 857 | | { |
| | | 858 | | destroy(); |
| | | 859 | | throw; |
| | | 860 | | } |
| | | 861 | | } |
| | | 862 | | |
| | | 863 | | internal void finishSetup(Communicator communicator) |
| | | 864 | | { |
| | | 865 | | // |
| | | 866 | | // Load plug-ins. |
| | | 867 | | // |
| | | 868 | | Debug.Assert(_serverThreadPool == null); |
| | | 869 | | var pluginManagerImpl = (Ice.PluginManagerI)_pluginManager; |
| | | 870 | | pluginManagerImpl.loadPlugins(); |
| | | 871 | | |
| | | 872 | | // |
| | | 873 | | // Initialize the endpoint factories once all the plugins are loaded. This gives |
| | | 874 | | // the opportunity for the endpoint factories to find underlying factories. |
| | | 875 | | // |
| | | 876 | | _endpointFactoryManager.initialize(); |
| | | 877 | | |
| | | 878 | | // |
| | | 879 | | // Create Admin facets, if enabled. |
| | | 880 | | // |
| | | 881 | | // Note that any logger-dependent admin facet must be created after we load all plugins, |
| | | 882 | | // since one of these plugins can be a Logger plugin that sets a new logger during loading |
| | | 883 | | // |
| | | 884 | | |
| | | 885 | | if (_initData.properties.getIceProperty("Ice.Admin.Enabled").Length == 0) |
| | | 886 | | { |
| | | 887 | | _adminEnabled = _initData.properties.getIceProperty("Ice.Admin.Endpoints").Length > 0; |
| | | 888 | | } |
| | | 889 | | else |
| | | 890 | | { |
| | | 891 | | _adminEnabled = _initData.properties.getIcePropertyAsInt("Ice.Admin.Enabled") > 0; |
| | | 892 | | } |
| | | 893 | | |
| | | 894 | | string[] facetFilter = _initData.properties.getIcePropertyAsList("Ice.Admin.Facets"); |
| | | 895 | | if (facetFilter.Length > 0) |
| | | 896 | | { |
| | | 897 | | foreach (string s in facetFilter) |
| | | 898 | | { |
| | | 899 | | _adminFacetFilter.Add(s); |
| | | 900 | | } |
| | | 901 | | } |
| | | 902 | | |
| | | 903 | | if (_adminEnabled) |
| | | 904 | | { |
| | | 905 | | // |
| | | 906 | | // Process facet |
| | | 907 | | // |
| | | 908 | | string processFacetName = "Process"; |
| | | 909 | | if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(processFacetName)) |
| | | 910 | | { |
| | | 911 | | _adminFacets.Add(processFacetName, new ProcessI(communicator)); |
| | | 912 | | } |
| | | 913 | | |
| | | 914 | | // |
| | | 915 | | // Logger facet |
| | | 916 | | // |
| | | 917 | | string loggerFacetName = "Logger"; |
| | | 918 | | if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(loggerFacetName)) |
| | | 919 | | { |
| | | 920 | | LoggerAdminLogger logger = new LoggerAdminLoggerI(_initData.properties, _initData.logger); |
| | | 921 | | // Decorate the existing logger, and don't change _ownLogger. |
| | | 922 | | _initData.logger = logger; |
| | | 923 | | _adminFacets.Add(loggerFacetName, logger.getFacet()); |
| | | 924 | | } |
| | | 925 | | |
| | | 926 | | // |
| | | 927 | | // Properties facet |
| | | 928 | | // |
| | | 929 | | string propertiesFacetName = "Properties"; |
| | | 930 | | NativePropertiesAdmin propsAdmin = null; |
| | | 931 | | if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(propertiesFacetName)) |
| | | 932 | | { |
| | | 933 | | propsAdmin = new NativePropertiesAdmin(this); |
| | | 934 | | _adminFacets.Add(propertiesFacetName, propsAdmin); |
| | | 935 | | } |
| | | 936 | | |
| | | 937 | | // |
| | | 938 | | // Metrics facet |
| | | 939 | | // |
| | | 940 | | string metricsFacetName = "Metrics"; |
| | | 941 | | if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(metricsFacetName)) |
| | | 942 | | { |
| | | 943 | | var observer = new CommunicatorObserverI(_initData); |
| | | 944 | | _initData.observer = observer; |
| | | 945 | | _adminFacets.Add(metricsFacetName, observer.getFacet()); |
| | | 946 | | |
| | | 947 | | // |
| | | 948 | | // Make sure the admin plugin receives property updates. |
| | | 949 | | // |
| | | 950 | | propsAdmin?.addUpdateCallback(observer.getFacet().updated); |
| | | 951 | | } |
| | | 952 | | } |
| | | 953 | | |
| | | 954 | | // |
| | | 955 | | // Set observer updater |
| | | 956 | | // |
| | | 957 | | _initData.observer?.setObserverUpdater(new ObserverUpdaterI(this)); |
| | | 958 | | |
| | | 959 | | // |
| | | 960 | | // Create threads. |
| | | 961 | | // |
| | | 962 | | try |
| | | 963 | | { |
| | | 964 | | _timer = new Timer(this, Util.stringToThreadPriority( |
| | | 965 | | initializationData().properties.getIceProperty("Ice.ThreadPriority"))); |
| | | 966 | | } |
| | | 967 | | catch (System.Exception ex) |
| | | 968 | | { |
| | | 969 | | string s = "cannot create thread for timer:\n" + ex; |
| | | 970 | | _initData.logger.error(s); |
| | | 971 | | throw; |
| | | 972 | | } |
| | | 973 | | |
| | | 974 | | try |
| | | 975 | | { |
| | | 976 | | _endpointHostResolver = new EndpointHostResolver(this); |
| | | 977 | | } |
| | | 978 | | catch (System.Exception ex) |
| | | 979 | | { |
| | | 980 | | string s = "cannot create thread for endpoint host resolver:\n" + ex; |
| | | 981 | | _initData.logger.error(s); |
| | | 982 | | throw; |
| | | 983 | | } |
| | | 984 | | _clientThreadPool = new ThreadPool(this, "Ice.ThreadPool.Client", 0); |
| | | 985 | | |
| | | 986 | | // |
| | | 987 | | // The default router/locator may have been set during the loading of plugins. |
| | | 988 | | // Therefore we make sure it is not already set before checking the property. |
| | | 989 | | // |
| | | 990 | | if (_referenceFactory.getDefaultRouter() == null) |
| | | 991 | | { |
| | | 992 | | Ice.RouterPrx r = Ice.RouterPrxHelper.uncheckedCast( |
| | | 993 | | communicator.propertyToProxy("Ice.Default.Router")); |
| | | 994 | | if (r != null) |
| | | 995 | | { |
| | | 996 | | _referenceFactory = _referenceFactory.setDefaultRouter(r); |
| | | 997 | | } |
| | | 998 | | } |
| | | 999 | | |
| | | 1000 | | if (_referenceFactory.getDefaultLocator() == null) |
| | | 1001 | | { |
| | | 1002 | | Ice.LocatorPrx l = Ice.LocatorPrxHelper.uncheckedCast( |
| | | 1003 | | communicator.propertyToProxy("Ice.Default.Locator")); |
| | | 1004 | | if (l != null) |
| | | 1005 | | { |
| | | 1006 | | _referenceFactory = _referenceFactory.setDefaultLocator(l); |
| | | 1007 | | } |
| | | 1008 | | } |
| | | 1009 | | |
| | | 1010 | | // |
| | | 1011 | | // Show process id if requested (but only once). |
| | | 1012 | | // |
| | | 1013 | | lock (_mutex) |
| | | 1014 | | { |
| | | 1015 | | if (!_printProcessIdDone && _initData.properties.getIcePropertyAsInt("Ice.PrintProcessId") > 0) |
| | | 1016 | | { |
| | | 1017 | | using var p = System.Diagnostics.Process.GetCurrentProcess(); |
| | | 1018 | | Console.WriteLine(p.Id); |
| | | 1019 | | _printProcessIdDone = true; |
| | | 1020 | | } |
| | | 1021 | | } |
| | | 1022 | | |
| | | 1023 | | // SslEngine initialization |
| | | 1024 | | _sslEngine.initialize(); |
| | | 1025 | | |
| | | 1026 | | // |
| | | 1027 | | // Server thread pool initialization is lazy in serverThreadPool(). |
| | | 1028 | | // |
| | | 1029 | | |
| | | 1030 | | // |
| | | 1031 | | // An application can set Ice.InitPlugins=0 if it wants to postpone |
| | | 1032 | | // initialization until after it has interacted directly with the |
| | | 1033 | | // plug-ins. |
| | | 1034 | | // |
| | | 1035 | | if (_initData.properties.getIcePropertyAsInt("Ice.InitPlugins") > 0) |
| | | 1036 | | { |
| | | 1037 | | pluginManagerImpl.initializePlugins(); |
| | | 1038 | | } |
| | | 1039 | | |
| | | 1040 | | // |
| | | 1041 | | // This must be done last as this call creates the Ice.Admin object adapter |
| | | 1042 | | // and eventually registers a process proxy with the Ice locator (allowing |
| | | 1043 | | // remote clients to invoke on Ice.Admin facets as soon as it's registered). |
| | | 1044 | | // |
| | | 1045 | | if (_initData.properties.getIcePropertyAsInt("Ice.Admin.DelayCreation") <= 0) |
| | | 1046 | | { |
| | | 1047 | | getAdmin(); |
| | | 1048 | | } |
| | | 1049 | | } |
| | | 1050 | | |
| | | 1051 | | // |
| | | 1052 | | // Only for use by Ice.Communicator |
| | | 1053 | | // |
| | | 1054 | | public void destroy() |
| | | 1055 | | { |
| | | 1056 | | lock (_mutex) |
| | | 1057 | | { |
| | | 1058 | | // |
| | | 1059 | | // If destroy is in progress, wait for it to be done. This |
| | | 1060 | | // is necessary in case destroy() is called concurrently |
| | | 1061 | | // by multiple threads. |
| | | 1062 | | // |
| | | 1063 | | while (_state == StateDestroyInProgress) |
| | | 1064 | | { |
| | | 1065 | | Monitor.Wait(_mutex); |
| | | 1066 | | } |
| | | 1067 | | |
| | | 1068 | | if (_state == StateDestroyed) |
| | | 1069 | | { |
| | | 1070 | | return; |
| | | 1071 | | } |
| | | 1072 | | _state = StateDestroyInProgress; |
| | | 1073 | | } |
| | | 1074 | | |
| | | 1075 | | // |
| | | 1076 | | // Shutdown and destroy all the incoming and outgoing Ice |
| | | 1077 | | // connections and wait for the connections to be finished. |
| | | 1078 | | // |
| | | 1079 | | _objectAdapterFactory?.shutdown(); |
| | | 1080 | | |
| | | 1081 | | _outgoingConnectionFactory?.destroy(); |
| | | 1082 | | |
| | | 1083 | | _objectAdapterFactory?.destroy(); |
| | | 1084 | | |
| | | 1085 | | _outgoingConnectionFactory?.waitUntilFinished(); |
| | | 1086 | | |
| | | 1087 | | _retryQueue?.destroy(); // Must be called before destroying thread pools. |
| | | 1088 | | |
| | | 1089 | | _initData.observer?.setObserverUpdater(null); |
| | | 1090 | | |
| | | 1091 | | if (_initData.logger is LoggerAdminLogger loggerAdminLogger) |
| | | 1092 | | { |
| | | 1093 | | // In effect, remove the decorator. |
| | | 1094 | | loggerAdminLogger.detach(); |
| | | 1095 | | } |
| | | 1096 | | |
| | | 1097 | | // |
| | | 1098 | | // Now, destroy the thread pools. This must be done *only* after |
| | | 1099 | | // all the connections are finished (the connections destruction |
| | | 1100 | | // can require invoking callbacks with the thread pools). |
| | | 1101 | | // |
| | | 1102 | | _serverThreadPool?.destroy(); |
| | | 1103 | | _clientThreadPool?.destroy(); |
| | | 1104 | | _endpointHostResolver?.destroy(); |
| | | 1105 | | |
| | | 1106 | | // |
| | | 1107 | | // Wait for all the threads to be finished. |
| | | 1108 | | // |
| | | 1109 | | _timer?.destroy(); |
| | | 1110 | | _clientThreadPool?.joinWithAllThreads(); |
| | | 1111 | | _serverThreadPool?.joinWithAllThreads(); |
| | | 1112 | | _endpointHostResolver?.joinWithThread(); |
| | | 1113 | | |
| | | 1114 | | _routerManager?.destroy(); |
| | | 1115 | | |
| | | 1116 | | _locatorManager?.destroy(); |
| | | 1117 | | |
| | | 1118 | | if (_initData.properties.getIcePropertyAsInt("Ice.Warn.UnusedProperties") > 0) |
| | | 1119 | | { |
| | | 1120 | | List<string> unusedProperties = _initData.properties.getUnusedProperties(); |
| | | 1121 | | if (unusedProperties.Count != 0) |
| | | 1122 | | { |
| | | 1123 | | var message = new StringBuilder("The following properties were set but never read:"); |
| | | 1124 | | foreach (string s in unusedProperties) |
| | | 1125 | | { |
| | | 1126 | | message.Append("\n "); |
| | | 1127 | | message.Append(s); |
| | | 1128 | | } |
| | | 1129 | | _initData.logger.warning(message.ToString()); |
| | | 1130 | | } |
| | | 1131 | | } |
| | | 1132 | | |
| | | 1133 | | // |
| | | 1134 | | // Destroy last so that a Logger plugin can receive all log/traces before its destruction. |
| | | 1135 | | // |
| | | 1136 | | _pluginManager?.destroy(); |
| | | 1137 | | |
| | | 1138 | | lock (_mutex) |
| | | 1139 | | { |
| | | 1140 | | _objectAdapterFactory = null; |
| | | 1141 | | _outgoingConnectionFactory = null; |
| | | 1142 | | _retryQueue = null; |
| | | 1143 | | |
| | | 1144 | | _serverThreadPool = null; |
| | | 1145 | | _clientThreadPool = null; |
| | | 1146 | | _endpointHostResolver = null; |
| | | 1147 | | _timer = null; |
| | | 1148 | | |
| | | 1149 | | _referenceFactory = null; |
| | | 1150 | | _routerManager = null; |
| | | 1151 | | _locatorManager = null; |
| | | 1152 | | _endpointFactoryManager = null; |
| | | 1153 | | _pluginManager = null; |
| | | 1154 | | |
| | | 1155 | | _adminAdapter = null; |
| | | 1156 | | _adminFacets.Clear(); |
| | | 1157 | | |
| | | 1158 | | _state = StateDestroyed; |
| | | 1159 | | Monitor.PulseAll(_mutex); |
| | | 1160 | | } |
| | | 1161 | | |
| | | 1162 | | if (_ownLogger) |
| | | 1163 | | { |
| | | 1164 | | _initData.logger!.Dispose(); |
| | | 1165 | | } |
| | | 1166 | | } |
| | | 1167 | | |
| | | 1168 | | public BufSizeWarnInfo getBufSizeWarn(short type) |
| | | 1169 | | { |
| | | 1170 | | lock (_setBufSizeWarn) |
| | | 1171 | | { |
| | | 1172 | | BufSizeWarnInfo info; |
| | | 1173 | | if (!_setBufSizeWarn.TryGetValue(type, out BufSizeWarnInfo value)) |
| | | 1174 | | { |
| | | 1175 | | info = new BufSizeWarnInfo(); |
| | | 1176 | | info.sndWarn = false; |
| | | 1177 | | info.sndSize = -1; |
| | | 1178 | | info.rcvWarn = false; |
| | | 1179 | | info.rcvSize = -1; |
| | | 1180 | | _setBufSizeWarn.Add(type, info); |
| | | 1181 | | } |
| | | 1182 | | else |
| | | 1183 | | { |
| | | 1184 | | info = _setBufSizeWarn[type]; |
| | | 1185 | | } |
| | | 1186 | | return info; |
| | | 1187 | | } |
| | | 1188 | | } |
| | | 1189 | | |
| | | 1190 | | public void setSndBufSizeWarn(short type, int size) |
| | | 1191 | | { |
| | | 1192 | | lock (_setBufSizeWarn) |
| | | 1193 | | { |
| | | 1194 | | BufSizeWarnInfo info = getBufSizeWarn(type); |
| | | 1195 | | info.sndWarn = true; |
| | | 1196 | | info.sndSize = size; |
| | | 1197 | | _setBufSizeWarn[type] = info; |
| | | 1198 | | } |
| | | 1199 | | } |
| | | 1200 | | |
| | | 1201 | | public void setRcvBufSizeWarn(short type, int size) |
| | | 1202 | | { |
| | | 1203 | | lock (_setBufSizeWarn) |
| | | 1204 | | { |
| | | 1205 | | BufSizeWarnInfo info = getBufSizeWarn(type); |
| | | 1206 | | info.rcvWarn = true; |
| | | 1207 | | info.rcvSize = size; |
| | | 1208 | | _setBufSizeWarn[type] = info; |
| | | 1209 | | } |
| | | 1210 | | } |
| | | 1211 | | |
| | | 1212 | | internal void updateConnectionObservers() |
| | | 1213 | | { |
| | | 1214 | | try |
| | | 1215 | | { |
| | | 1216 | | Debug.Assert(_outgoingConnectionFactory != null); |
| | | 1217 | | _outgoingConnectionFactory.updateConnectionObservers(); |
| | | 1218 | | Debug.Assert(_objectAdapterFactory != null); |
| | | 1219 | | _objectAdapterFactory.updateConnectionObservers(); |
| | | 1220 | | } |
| | | 1221 | | catch (Ice.CommunicatorDestroyedException) |
| | | 1222 | | { |
| | | 1223 | | } |
| | | 1224 | | } |
| | | 1225 | | |
| | | 1226 | | internal void updateThreadObservers() |
| | | 1227 | | { |
| | | 1228 | | try |
| | | 1229 | | { |
| | | 1230 | | _clientThreadPool?.updateObservers(); |
| | | 1231 | | _serverThreadPool?.updateObservers(); |
| | | 1232 | | Debug.Assert(_objectAdapterFactory != null); |
| | | 1233 | | _objectAdapterFactory.updateThreadObservers(); |
| | | 1234 | | _endpointHostResolver?.updateObserver(); |
| | | 1235 | | _timer?.updateObserver(_initData.observer); |
| | | 1236 | | } |
| | | 1237 | | catch (Ice.CommunicatorDestroyedException) |
| | | 1238 | | { |
| | | 1239 | | } |
| | | 1240 | | } |
| | | 1241 | | |
| | | 1242 | | internal void addAllAdminFacets() |
| | | 1243 | | { |
| | | 1244 | | lock (_mutex) |
| | | 1245 | | { |
| | | 1246 | | var filteredFacets = new Dictionary<string, Ice.Object>(); |
| | | 1247 | | |
| | | 1248 | | foreach (KeyValuePair<string, Ice.Object> entry in _adminFacets) |
| | | 1249 | | { |
| | | 1250 | | if (_adminFacetFilter.Count == 0 || _adminFacetFilter.Contains(entry.Key)) |
| | | 1251 | | { |
| | | 1252 | | _adminAdapter.addFacet(entry.Value, _adminIdentity, entry.Key); |
| | | 1253 | | } |
| | | 1254 | | else |
| | | 1255 | | { |
| | | 1256 | | filteredFacets.Add(entry.Key, entry.Value); |
| | | 1257 | | } |
| | | 1258 | | } |
| | | 1259 | | _adminFacets = filteredFacets; |
| | | 1260 | | } |
| | | 1261 | | } |
| | | 1262 | | |
| | | 1263 | | internal void setServerProcessProxy(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity) |
| | | 1264 | | { |
| | | 1265 | | Ice.ObjectPrx admin = adminAdapter.createProxy(adminIdentity); |
| | | 1266 | | Ice.LocatorPrx locator = adminAdapter.getLocator(); |
| | | 1267 | | string serverId = _initData.properties.getIceProperty("Ice.Admin.ServerId"); |
| | | 1268 | | |
| | | 1269 | | if (locator != null && serverId.Length > 0) |
| | | 1270 | | { |
| | | 1271 | | Ice.ProcessPrx process = Ice.ProcessPrxHelper.uncheckedCast(admin.ice_facet("Process")); |
| | | 1272 | | try |
| | | 1273 | | { |
| | | 1274 | | // |
| | | 1275 | | // Note that as soon as the process proxy is registered, the communicator might be |
| | | 1276 | | // shutdown by a remote client and admin facets might start receiving calls. |
| | | 1277 | | // |
| | | 1278 | | locator.getRegistry().setServerProcessProxy(serverId, process); |
| | | 1279 | | } |
| | | 1280 | | catch (Ice.ServerNotFoundException) |
| | | 1281 | | { |
| | | 1282 | | if (_traceLevels.location >= 1) |
| | | 1283 | | { |
| | | 1284 | | var s = new System.Text.StringBuilder(); |
| | | 1285 | | s.Append("couldn't register server `" + serverId + "' with the locator registry:\n"); |
| | | 1286 | | s.Append("the server is not known to the locator registry"); |
| | | 1287 | | _initData.logger.trace(_traceLevels.locationCat, s.ToString()); |
| | | 1288 | | } |
| | | 1289 | | |
| | | 1290 | | throw new Ice.InitializationException("Locator knows nothing about server `" + serverId + "'"); |
| | | 1291 | | } |
| | | 1292 | | catch (Ice.LocalException ex) |
| | | 1293 | | { |
| | | 1294 | | if (_traceLevels.location >= 1) |
| | | 1295 | | { |
| | | 1296 | | var s = new System.Text.StringBuilder(); |
| | | 1297 | | s.Append("couldn't register server `" + serverId + "' with the locator registry:\n" + ex); |
| | | 1298 | | _initData.logger.trace(_traceLevels.locationCat, s.ToString()); |
| | | 1299 | | } |
| | | 1300 | | throw; // TODO: Shall we raise a special exception instead of a non obvious local exception? |
| | | 1301 | | } |
| | | 1302 | | |
| | | 1303 | | if (_traceLevels.location >= 1) |
| | | 1304 | | { |
| | | 1305 | | var s = new System.Text.StringBuilder(); |
| | | 1306 | | s.Append("registered server `" + serverId + "' with the locator registry"); |
| | | 1307 | | _initData.logger.trace(_traceLevels.locationCat, s.ToString()); |
| | | 1308 | | } |
| | | 1309 | | } |
| | | 1310 | | } |
| | | 1311 | | |
| | | 1312 | | internal ConnectionOptions serverConnectionOptions(string adapterName) |
| | | 1313 | | { |
| | | 1314 | | Debug.Assert(adapterName.Length > 0); |
| | | 1315 | | Properties properties = _initData.properties; |
| | | 1316 | | string propertyPrefix = $"{adapterName}.Connection"; |
| | | 1317 | | |
| | | 1318 | | return new( |
| | | 1319 | | connectTimeout: TimeSpan.FromSeconds(properties.getPropertyAsIntWithDefault( |
| | | 1320 | | $"{propertyPrefix}.ConnectTimeout", |
| | | 1321 | | (int)_serverConnectionOptions.connectTimeout.TotalSeconds)), |
| | | 1322 | | |
| | | 1323 | | closeTimeout: TimeSpan.FromSeconds(properties.getPropertyAsIntWithDefault( |
| | | 1324 | | $"{propertyPrefix}.CloseTimeout", |
| | | 1325 | | (int)_serverConnectionOptions.closeTimeout.TotalSeconds)), |
| | | 1326 | | |
| | | 1327 | | idleTimeout: TimeSpan.FromSeconds(properties.getPropertyAsIntWithDefault( |
| | | 1328 | | $"{propertyPrefix}.IdleTimeout", |
| | | 1329 | | (int)_serverConnectionOptions.idleTimeout.TotalSeconds)), |
| | | 1330 | | |
| | | 1331 | | enableIdleCheck: properties.getPropertyAsIntWithDefault( |
| | | 1332 | | $"{propertyPrefix}.EnableIdleCheck", |
| | | 1333 | | _serverConnectionOptions.enableIdleCheck ? 1 : 0) > 0, |
| | | 1334 | | |
| | | 1335 | | inactivityTimeout: TimeSpan.FromSeconds(properties.getPropertyAsIntWithDefault( |
| | | 1336 | | $"{propertyPrefix}.InactivityTimeout", |
| | | 1337 | | (int)_serverConnectionOptions.inactivityTimeout.TotalSeconds)), |
| | | 1338 | | |
| | | 1339 | | maxDispatches: properties.getPropertyAsIntWithDefault( |
| | | 1340 | | $"{propertyPrefix}.MaxDispatches", |
| | | 1341 | | _serverConnectionOptions.maxDispatches)); |
| | | 1342 | | } |
| | | 1343 | | |
| | | 1344 | | internal SliceLoader sliceLoader => _initData.sliceLoader; // set in initialize |
| | | 1345 | | |
| | | 1346 | | internal ConnectionOptions clientConnectionOptions { get; private set; } = null!; // set in initialize |
| | | 1347 | | |
| | | 1348 | | internal int[] retryIntervals { get; private set; } |
| | | 1349 | | |
| | | 1350 | | private NetworkProxy createNetworkProxy(Ice.Properties props, int protocolSupport) |
| | | 1351 | | { |
| | | 1352 | | string proxyHost; |
| | | 1353 | | |
| | | 1354 | | proxyHost = props.getIceProperty("Ice.SOCKSProxyHost"); |
| | | 1355 | | if (proxyHost.Length > 0) |
| | | 1356 | | { |
| | | 1357 | | if (protocolSupport == Network.EnableIPv6) |
| | | 1358 | | { |
| | | 1359 | | throw new Ice.InitializationException("IPv6 only is not supported with SOCKS4 proxies"); |
| | | 1360 | | } |
| | | 1361 | | int proxyPort = props.getIcePropertyAsInt("Ice.SOCKSProxyPort"); |
| | | 1362 | | return new SOCKSNetworkProxy(proxyHost, proxyPort); |
| | | 1363 | | } |
| | | 1364 | | |
| | | 1365 | | proxyHost = props.getIceProperty("Ice.HTTPProxyHost"); |
| | | 1366 | | if (proxyHost.Length > 0) |
| | | 1367 | | { |
| | | 1368 | | return new HTTPNetworkProxy(proxyHost, props.getIcePropertyAsInt("Ice.HTTPProxyPort")); |
| | | 1369 | | } |
| | | 1370 | | |
| | | 1371 | | return null; |
| | | 1372 | | } |
| | | 1373 | | |
| | | 1374 | | private ConnectionOptions readConnectionOptions(string propertyPrefix) |
| | | 1375 | | { |
| | | 1376 | | Properties properties = _initData.properties; |
| | | 1377 | | |
| | | 1378 | | // The TimeSpan value can be <= 0. In this case, the timeout is considered infinite. |
| | | 1379 | | return new( |
| | | 1380 | | connectTimeout: TimeSpan.FromSeconds(properties.getIcePropertyAsInt($"{propertyPrefix}.ConnectTimeout")), |
| | | 1381 | | closeTimeout: TimeSpan.FromSeconds(properties.getIcePropertyAsInt($"{propertyPrefix}.CloseTimeout")), |
| | | 1382 | | idleTimeout: TimeSpan.FromSeconds(properties.getIcePropertyAsInt($"{propertyPrefix}.IdleTimeout")), |
| | | 1383 | | enableIdleCheck: properties.getIcePropertyAsInt($"{propertyPrefix}.EnableIdleCheck") > 0, |
| | | 1384 | | inactivityTimeout: |
| | | 1385 | | TimeSpan.FromSeconds(properties.getIcePropertyAsInt($"{propertyPrefix}.InactivityTimeout")), |
| | | 1386 | | maxDispatches: properties.getIcePropertyAsInt($"{propertyPrefix}.MaxDispatches")); |
| | | 1387 | | } |
| | | 1388 | | |
| | | 1389 | | private static bool _printProcessIdDone; |
| | | 1390 | | private static bool _oneOffDone; |
| | | 1391 | | private static readonly object _staticLock = new object(); |
| | | 1392 | | |
| | | 1393 | | private const int StateActive = 0; |
| | | 1394 | | private const int StateDestroyInProgress = 1; |
| | | 1395 | | private const int StateDestroyed = 2; |
| | | 1396 | | |
| | | 1397 | | private int _state; |
| | | 1398 | | private Ice.InitializationData _initData; // Immutable, not reset by destroy(). |
| | | 1399 | | private bool _ownLogger; // When true, this instance owns _initData.logger and must dispose it. |
| | | 1400 | | |
| | | 1401 | | private TraceLevels _traceLevels; // Immutable, not reset by destroy(). |
| | | 1402 | | private DefaultsAndOverrides _defaultsAndOverrides; // Immutable, not reset by destroy(). |
| | | 1403 | | private int _messageSizeMax; // Immutable, not reset by destroy(). |
| | | 1404 | | private int _batchAutoFlushSize; // Immutable, not reset by destroy(). |
| | | 1405 | | private int _classGraphDepthMax; // Immutable, not reset by destroy(). |
| | | 1406 | | private Ice.ToStringMode _toStringMode; // Immutable, not reset by destroy(). |
| | | 1407 | | private int _cacheMessageBuffers; // Immutable, not reset by destroy(). |
| | | 1408 | | private Ice.ImplicitContextI _implicitContext; // Immutable |
| | | 1409 | | private RouterManager _routerManager; |
| | | 1410 | | private LocatorManager _locatorManager; |
| | | 1411 | | private ReferenceFactory _referenceFactory; |
| | | 1412 | | private OutgoingConnectionFactory _outgoingConnectionFactory; |
| | | 1413 | | private ObjectAdapterFactory _objectAdapterFactory; |
| | | 1414 | | private int _protocolSupport; |
| | | 1415 | | private bool _preferIPv6; |
| | | 1416 | | private NetworkProxy _networkProxy; |
| | | 1417 | | private ThreadPool _clientThreadPool; |
| | | 1418 | | private ThreadPool _serverThreadPool; |
| | | 1419 | | private EndpointHostResolver _endpointHostResolver; |
| | | 1420 | | private Timer _timer; |
| | | 1421 | | private RetryQueue _retryQueue; |
| | | 1422 | | private EndpointFactoryManager _endpointFactoryManager; |
| | | 1423 | | private Ice.PluginManager _pluginManager; |
| | | 1424 | | private bool _adminEnabled; |
| | | 1425 | | private Ice.ObjectAdapter _adminAdapter; |
| | | 1426 | | private Dictionary<string, Ice.Object> _adminFacets = new(); |
| | | 1427 | | private readonly HashSet<string> _adminFacetFilter = new(); |
| | | 1428 | | private Ice.Identity _adminIdentity; |
| | | 1429 | | private readonly Dictionary<short, BufSizeWarnInfo> _setBufSizeWarn = new(); |
| | | 1430 | | private ConnectionOptions _serverConnectionOptions; // set in initialize |
| | | 1431 | | private Ice.SSL.SSLEngine _sslEngine; |
| | | 1432 | | |
| | | 1433 | | // The Slice loader(s) added by the application: initData.sliceLoader followed by the loaders added by |
| | | 1434 | | // addSliceLoader. |
| | | 1435 | | private readonly CompositeSliceLoader _applicationSliceLoader = new(); |
| | | 1436 | | |
| | | 1437 | | private readonly object _mutex = new object(); |
| | | 1438 | | } |