< Summary

Information
Class: IceLocatorDiscovery.LocatorI
Assembly: IceLocatorDiscovery
File(s): /_/csharp/src/IceLocatorDiscovery/PluginI.cs
Tag: 91_21789722663
Line coverage
74%
Covered lines: 173
Uncovered lines: 59
Coverable lines: 232
Total lines: 683
Line coverage: 74.5%
Branch coverage
72%
Covered branches: 87
Total branches: 120
Branch coverage: 72.5%
Method coverage
100%
Covered methods: 8
Total methods: 8
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)62.5%8.05890.63%
setLookupReply(...)91.67%12.521284.62%
ice_invokeAsync(...)100%11100%
foundLocator(...)52.38%224.794253.03%
invoke(...)73.08%67.572660.53%
performFindLocatorAsync()100%11100%
exception(...)92.86%14.011496.15%
runTimerTask()94.44%18.351889.74%

File(s)

/_/csharp/src/IceLocatorDiscovery/PluginI.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Diagnostics;
 4using System.Text;
 5
 6namespace IceLocatorDiscovery;
 7
 8public sealed class PluginFactory : Ice.PluginFactory
 9{
 10    public string pluginName => "IceLocatorDiscovery";
 11
 12    public Ice.Plugin create(Ice.Communicator communicator, string name, string[] args)
 13    {
 14        if (name != pluginName)
 15        {
 16            throw new Ice.PluginInitializationException(
 17                $"The Locator Discovery plug-in must be named '{pluginName}'.");
 18        }
 19
 20        return new PluginI(communicator);
 21    }
 22}
 23
 24internal class Request : TaskCompletionSource<Ice.Object_Ice_invokeResult>
 25{
 26    public Request(
 27        LocatorI locator,
 28        string operation,
 29        Ice.OperationMode mode,
 30        byte[] inParams,
 31        Dictionary<string, string> context)
 32        : base(TaskCreationOptions.RunContinuationsAsynchronously)
 33    {
 34        _locator = locator;
 35        _operation = operation;
 36        _mode = mode;
 37        _inParams = inParams;
 38        _context = context;
 39    }
 40
 41    public void
 42    invoke(Ice.LocatorPrx l)
 43    {
 44        if (_locatorPrx == null || !_locatorPrx.Equals(l))
 45        {
 46            _locatorPrx = l;
 47            _ = performInvokeAsync(l);
 48        }
 49        else
 50        {
 51            Debug.Assert(_exception != null);
 52            throw _exception;
 53        }
 54
 55        async Task performInvokeAsync(Ice.LocatorPrx locator)
 56        {
 57            try
 58            {
 59                Ice.Object_Ice_invokeResult result =
 60                    await locator.ice_invokeAsync(_operation, _mode, _inParams, _context).ConfigureAwait(false);
 61                SetResult(result);
 62            }
 63            catch (Ice.RequestFailedException exc)
 64            {
 65                SetException(exc);
 66            }
 67            catch (Ice.UnknownException exc)
 68            {
 69                SetException(exc);
 70            }
 71            catch (Ice.NoEndpointException)
 72            {
 73                SetException(new Ice.ObjectNotExistException());
 74            }
 75            catch (Ice.ObjectAdapterDeactivatedException)
 76            {
 77                SetException(new Ice.ObjectNotExistException());
 78            }
 79            catch (Ice.ObjectAdapterDestroyedException)
 80            {
 81                SetException(new Ice.ObjectNotExistException());
 82            }
 83            catch (Ice.CommunicatorDestroyedException)
 84            {
 85                SetException(new Ice.ObjectNotExistException());
 86            }
 87            catch (Exception exc)
 88            {
 89                _exception = exc;
 90                _locator.invoke(_locatorPrx, this); // Retry with new locator proxy
 91            }
 92        }
 93    }
 94
 95    private readonly LocatorI _locator;
 96    private readonly string _operation;
 97    private readonly Ice.OperationMode _mode;
 98    private readonly Dictionary<string, string> _context;
 99    private readonly byte[] _inParams;
 100
 101    private Ice.LocatorPrx _locatorPrx;
 102    private Exception _exception;
 103}
 104
 105internal class VoidLocatorI : Ice.LocatorDisp_
 106{
 107    public override Ice.ObjectPrx findObjectById(Ice.Identity id, Ice.Current current) => null;
 108
 109    public override Ice.ObjectPrx findAdapterById(string id, Ice.Current current) => null;
 110
 111    public override Ice.LocatorRegistryPrx getRegistry(Ice.Current current) => null;
 112}
 113
 114internal class LocatorI : Ice.BlobjectAsync, Ice.Internal.TimerTask
 115{
 1116    public
 1117    LocatorI(LookupPrx lookup, Ice.Properties properties, string instanceName, Ice.LocatorPrx voidLocator)
 118    {
 1119        _lookup = lookup;
 1120        _timeout = properties.getIcePropertyAsInt("IceLocatorDiscovery.Timeout");
 1121        if (_timeout < 0)
 122        {
 0123            _timeout = 300;
 124        }
 1125        _retryCount = properties.getIcePropertyAsInt("IceLocatorDiscovery.RetryCount");
 1126        if (_retryCount < 0)
 127        {
 0128            _retryCount = 0;
 129        }
 1130        _retryDelay = properties.getIcePropertyAsInt("IceLocatorDiscovery.RetryDelay");
 1131        if (_retryDelay < 0)
 132        {
 0133            _retryDelay = 0;
 134        }
 1135        _timer = Ice.Internal.Util.getInstance(lookup.ice_getCommunicator()).timer();
 1136        _traceLevel = properties.getIcePropertyAsInt("IceLocatorDiscovery.Trace.Lookup");
 1137        _instanceName = instanceName;
 1138        _warned = false;
 1139        _locator = lookup.ice_getCommunicator().getDefaultLocator();
 1140        _voidLocator = voidLocator;
 1141        _pending = false;
 1142        _pendingRetryCount = 0;
 1143        _failureCount = 0;
 1144        _warnOnce = true;
 145
 146        //
 147        // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast
 148        // datagram on each endpoint.
 149        //
 1150        var single = new Ice.Endpoint[1];
 1151        foreach (Ice.Endpoint endpoint in lookup.ice_getEndpoints())
 152        {
 1153            single[0] = endpoint;
 1154            _lookups[(LookupPrx)lookup.ice_endpoints(single)] = null;
 155        }
 156        Debug.Assert(_lookups.Count > 0);
 1157    }
 158
 159    public void
 160    setLookupReply(LookupReplyPrx lookupReply)
 161    {
 162        //
 163        // Use a lookup reply proxy whose address matches the interface used to send multicast datagrams.
 164        //
 1165        var single = new Ice.Endpoint[1];
 1166        foreach (LookupPrx key in new List<LookupPrx>(_lookups.Keys))
 167        {
 1168            var info = (Ice.UDPEndpointInfo)key.ice_getEndpoints()[0].getInfo();
 1169            if (info.mcastInterface.Length > 0)
 170            {
 1171                foreach (Ice.Endpoint q in lookupReply.ice_getEndpoints())
 172                {
 1173                    Ice.EndpointInfo r = q.getInfo();
 1174                    if (r is Ice.IPEndpointInfo &&
 1175                        ((Ice.IPEndpointInfo)r).host.Equals(info.mcastInterface, StringComparison.Ordinal))
 176                    {
 0177                        single[0] = q;
 0178                        _lookups[key] = (LookupReplyPrx)lookupReply.ice_endpoints(single);
 179                    }
 180                }
 181            }
 182
 1183            if (_lookups[key] == null)
 184            {
 185                // Fallback: just use the given lookup reply proxy if no matching endpoint found.
 1186                _lookups[key] = lookupReply;
 187            }
 188        }
 1189    }
 190
 191    public override Task<Ice.Object_Ice_invokeResult>
 192    ice_invokeAsync(byte[] inParams, Ice.Current current)
 193    {
 1194        lock (_mutex)
 195        {
 1196            var request = new Request(this, current.operation, current.mode, inParams, current.ctx);
 1197            invoke(null, request);
 1198            return request.Task;
 199        }
 1200    }
 201
 202    public void
 203    foundLocator(Ice.LocatorPrx locator)
 204    {
 1205        lock (_mutex)
 206        {
 1207            if (locator == null)
 208            {
 0209                if (_traceLevel > 2)
 210                {
 0211                    _lookup.ice_getCommunicator().getLogger().trace(
 0212                        "Lookup",
 0213                        "ignoring locator reply: (null locator)");
 214                }
 0215                return;
 216            }
 217
 1218            if (_instanceName.Length > 0 &&
 1219                !locator.ice_getIdentity().category.Equals(_instanceName, StringComparison.Ordinal))
 220            {
 0221                if (_traceLevel > 2)
 222                {
 0223                    var s = new StringBuilder("ignoring locator reply: instance name doesn't match\n");
 0224                    s.Append("expected = ").Append(_instanceName);
 0225                    s.Append("received = ").Append(locator.ice_getIdentity().category);
 0226                    _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 227                }
 0228                return;
 229            }
 230
 231            //
 232            // If we already have a locator assigned, ensure the given locator
 233            // has the same identity, otherwise ignore it.
 234            //
 1235            if (_pendingRequests.Count > 0 &&
 1236               _locator != null &&
 1237               !locator.ice_getIdentity().category.Equals(
 1238                   _locator.ice_getIdentity().category,
 1239                   StringComparison.Ordinal))
 240            {
 0241                if (!_warned)
 242                {
 0243                    _warned = true; // Only warn once
 244
 0245                    locator.ice_getCommunicator().getLogger().warning(
 0246                    "received Ice locator with different instance name:\n" +
 0247                    "using = `" + _locator.ice_getIdentity().category + "'\n" +
 0248                    "received = `" + locator.ice_getIdentity().category + "'\n" +
 0249                    "This is typically the case if multiple Ice locators with different " +
 0250                    "instance names are deployed and the property `IceLocatorDiscovery.InstanceName'" +
 0251                    "is not set.");
 252                }
 0253                return;
 254            }
 255
 1256            if (_pending) // No need to continue, we found a locator
 257            {
 1258                _timer.cancel(this);
 1259                _pendingRetryCount = 0;
 1260                _pending = false;
 261            }
 262
 1263            if (_traceLevel > 0)
 264            {
 1265                var s = new StringBuilder("locator lookup succeeded:\nlocator = ");
 1266                s.Append(locator);
 1267                if (_instanceName.Length > 0)
 268                {
 1269                    s.Append("\ninstance name = ").Append(_instanceName);
 270                }
 1271                _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 272            }
 273
 1274            Ice.LocatorPrx l = null;
 1275            if (_pendingRequests.Count == 0)
 276            {
 1277                _locators.TryGetValue(locator.ice_getIdentity().category, out _locator);
 278            }
 279            else
 280            {
 1281                l = _locator;
 282            }
 1283            if (l != null)
 284            {
 285                //
 286                // We found another locator replica, append its endpoints to the
 287                // current locator proxy endpoints.
 288                //
 0289                var newEndpoints = new List<Ice.Endpoint>(l.ice_getEndpoints());
 0290                foreach (Ice.Endpoint p in locator.ice_getEndpoints())
 291                {
 292                    //
 293                    // Only add endpoints if not already in the locator proxy endpoints
 294                    //
 0295                    bool found = false;
 0296                    foreach (Ice.Endpoint q in newEndpoints)
 297                    {
 0298                        if (p.Equals(q))
 299                        {
 0300                            found = true;
 0301                            break;
 302                        }
 303                    }
 0304                    if (!found)
 305                    {
 0306                        newEndpoints.Add(p);
 307                    }
 308                }
 0309                l = (Ice.LocatorPrx)l.ice_endpoints(newEndpoints.ToArray());
 310            }
 311            else
 312            {
 1313                l = locator;
 314            }
 315
 1316            if (_pendingRequests.Count == 0)
 317            {
 1318                _locators[locator.ice_getIdentity().category] = l;
 319            }
 320            else
 321            {
 1322                _locator = l;
 1323                if (_instanceName.Length == 0)
 324                {
 1325                    _instanceName = _locator.ice_getIdentity().category; // Stick to the first locator
 326                }
 327
 328                //
 329                // Send pending requests if any.
 330                //
 1331                foreach (Request req in _pendingRequests)
 332                {
 1333                    req.invoke(_locator);
 334                }
 1335                _pendingRequests.Clear();
 336            }
 1337        }
 1338    }
 339
 340    public void
 341    invoke(Ice.LocatorPrx locator, Request request)
 342    {
 1343        lock (_mutex)
 344        {
 1345            if (request != null && _locator != null && _locator != locator)
 346            {
 1347                request.invoke(_locator);
 348            }
 1349            else if (request != null && Ice.Internal.Time.currentMonotonicTimeMillis() < _nextRetry)
 350            {
 1351                request.invoke(_voidLocator); // Don't retry to find a locator before the retry delay expires
 352            }
 353            else
 354            {
 1355                _locator = null;
 356
 1357                if (request != null)
 358                {
 1359                    _pendingRequests.Add(request);
 360                }
 361
 1362                if (!_pending) // No request in progress
 363                {
 1364                    _pending = true;
 1365                    _pendingRetryCount = _retryCount;
 1366                    _failureCount = 0;
 367                    try
 368                    {
 1369                        if (_traceLevel > 1)
 370                        {
 1371                            var s = new StringBuilder("looking up locator:\nlookup = ");
 1372                            s.Append(_lookup);
 1373                            if (_instanceName.Length > 0)
 374                            {
 1375                                s.Append("\ninstance name = ").Append(_instanceName);
 376                            }
 1377                            _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 378                        }
 379
 1380                        foreach (KeyValuePair<LookupPrx, LookupReplyPrx> l in _lookups)
 381                        {
 1382                            _ = performFindLocatorAsync(l.Key, l.Value);
 383                        }
 1384                        _timer.schedule(this, _timeout);
 1385                    }
 0386                    catch (Ice.LocalException ex)
 387                    {
 0388                        if (_traceLevel > 0)
 389                        {
 0390                            var s = new StringBuilder("locator lookup failed:\nlookup = ");
 0391                            s.Append(_lookup);
 0392                            if (_instanceName.Length > 0)
 393                            {
 0394                                s.Append("\ninstance name = ").Append(_instanceName);
 395                            }
 0396                            s.Append('\n').Append(ex);
 0397                            _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 398                        }
 399
 0400                        foreach (Request req in _pendingRequests)
 401                        {
 0402                            req.invoke(_voidLocator);
 403                        }
 0404                        _pendingRequests.Clear();
 0405                        _pendingRetryCount = 0;
 0406                        _pending = false;
 0407                    }
 408                }
 409            }
 0410        }
 411
 412        async Task performFindLocatorAsync(LookupPrx lookupPrx, LookupReplyPrx lookupReplyPrx)
 413        {
 414            // Exit the mutex lock before proceeding.
 1415            await Task.Yield();
 416
 417            // Send multicast request.
 418            try
 419            {
 1420                await lookupPrx.findLocatorAsync(_instanceName, lookupReplyPrx).ConfigureAwait(false);
 1421            }
 1422            catch (System.Exception ex)
 423            {
 1424                exception(ex);
 1425            }
 1426        }
 1427    }
 428
 429    private void exception(Exception ex)
 430    {
 1431        lock (_mutex)
 432        {
 1433            if (++_failureCount == _lookups.Count && _pending)
 434            {
 435                //
 436                // All the lookup calls failed, cancel the timer and propagate the error to the requests.
 437                //
 1438                _timer.cancel(this);
 1439                _pendingRetryCount = 0;
 1440                _pending = false;
 441
 1442                if (_warnOnce)
 443                {
 1444                    var builder = new StringBuilder();
 1445                    builder.Append("failed to lookup locator with lookup proxy `");
 1446                    builder.Append(_lookup);
 1447                    builder.Append("':\n");
 1448                    builder.Append(ex);
 1449                    _lookup.ice_getCommunicator().getLogger().warning(builder.ToString());
 1450                    _warnOnce = false;
 451                }
 452
 1453                if (_traceLevel > 0)
 454                {
 1455                    var s = new StringBuilder("locator lookup failed:\nlookup = ");
 1456                    s.Append(_lookup);
 1457                    if (_instanceName.Length > 0)
 458                    {
 0459                        s.Append("\ninstance name = ").Append(_instanceName);
 460                    }
 1461                    s.Append('\n').Append(ex);
 1462                    _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 463                }
 464
 1465                if (_pendingRequests.Count > 0)
 466                {
 1467                    foreach (Request req in _pendingRequests)
 468                    {
 1469                        req.invoke(_voidLocator);
 470                    }
 1471                    _pendingRequests.Clear();
 472                }
 473            }
 1474        }
 1475    }
 476
 477    public void runTimerTask()
 478    {
 1479        lock (_mutex)
 480        {
 1481            if (!_pending)
 482            {
 483                Debug.Assert(_pendingRequests.Count == 0);
 0484                return; // Request failed
 485            }
 486
 1487            if (_pendingRetryCount > 0)
 488            {
 1489                --_pendingRetryCount;
 490                try
 491                {
 1492                    if (_traceLevel > 1)
 493                    {
 1494                        var s = new StringBuilder("retrying locator lookup:\nlookup = ");
 1495                        s.Append(_lookup);
 1496                        s.Append("\nretry count = ").Append(_retryCount);
 1497                        if (_instanceName.Length > 0)
 498                        {
 1499                            s.Append("\ninstance name = ").Append(_instanceName);
 500                        }
 1501                        _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 502                    }
 503
 1504                    foreach (KeyValuePair<LookupPrx, LookupReplyPrx> l in _lookups)
 505                    {
 1506                        l.Key.findLocatorAsync(_instanceName, l.Value).ContinueWith(
 1507                            t =>
 1508                            {
 1509                                try
 1510                                {
 1511                                    t.Wait();
 1512                                }
 0513                                catch (AggregateException ex)
 1514                                {
 0515                                    exception(ex.InnerException);
 0516                                }
 1517                            },
 1518                            l.Key.ice_scheduler()); // Send multicast request.
 519                    }
 1520                    _timer.schedule(this, _timeout);
 1521                    return;
 522                }
 0523                catch (Ice.LocalException)
 524                {
 0525                }
 0526                _pendingRetryCount = 0;
 527            }
 528
 529            Debug.Assert(_pendingRetryCount == 0);
 1530            _pending = false;
 531
 1532            if (_traceLevel > 0)
 533            {
 1534                var s = new StringBuilder("locator lookup timed out:\nlookup = ");
 1535                s.Append(_lookup);
 1536                if (_instanceName.Length > 0)
 537                {
 1538                    s.Append("\ninstance name = ").Append(_instanceName);
 539                }
 1540                _lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
 541            }
 542
 1543            if (_pendingRequests.Count > 0)
 544            {
 1545                foreach (Request req in _pendingRequests)
 546                {
 1547                    req.invoke(_voidLocator);
 548                }
 1549                _pendingRequests.Clear();
 550            }
 1551            _nextRetry = Ice.Internal.Time.currentMonotonicTimeMillis() + _retryDelay;
 1552        }
 1553    }
 554
 555    private readonly LookupPrx _lookup;
 1556    private readonly Dictionary<LookupPrx, LookupReplyPrx> _lookups = new Dictionary<LookupPrx, LookupReplyPrx>();
 557    private readonly int _timeout;
 558    private readonly Ice.Internal.Timer _timer;
 559    private readonly int _traceLevel;
 560    private readonly int _retryCount;
 561    private readonly int _retryDelay;
 562
 563    private string _instanceName;
 564    private bool _warned;
 565    private Ice.LocatorPrx _locator;
 566    private readonly Ice.LocatorPrx _voidLocator;
 1567    private readonly Dictionary<string, Ice.LocatorPrx> _locators = new Dictionary<string, Ice.LocatorPrx>();
 568
 569    private bool _pending;
 570    private int _pendingRetryCount;
 571    private int _failureCount;
 1572    private bool _warnOnce = true;
 1573    private readonly List<Request> _pendingRequests = new List<Request>();
 574    private long _nextRetry;
 1575    private readonly object _mutex = new();
 576}
 577
 578internal class LookupReplyI : LookupReplyDisp_
 579{
 580    public LookupReplyI(LocatorI locator) => _locator = locator;
 581
 582    public override void
 583    foundLocator(Ice.LocatorPrx locator, Ice.Current current) => _locator.foundLocator(locator);
 584
 585    private readonly LocatorI _locator;
 586}
 587
 588internal class PluginI : Ice.Plugin
 589{
 590    public
 591    PluginI(Ice.Communicator communicator) => _communicator = communicator;
 592
 593    public void
 594    initialize()
 595    {
 596        Ice.Properties properties = _communicator.getProperties();
 597
 598        bool ipv4 = properties.getIcePropertyAsInt("Ice.IPv4") > 0;
 599        bool preferIPv6 = properties.getIcePropertyAsInt("Ice.PreferIPv6Address") > 0;
 600        string address = properties.getIceProperty("IceLocatorDiscovery.Address");
 601        if (address.Length == 0)
 602        {
 603            address = ipv4 && !preferIPv6 ? "239.255.0.1" : "ff15::1";
 604        }
 605        int port = properties.getIcePropertyAsInt("IceLocatorDiscovery.Port");
 606        string intf = properties.getIceProperty("IceLocatorDiscovery.Interface");
 607
 608        string lookupEndpoints = properties.getIceProperty("IceLocatorDiscovery.Lookup");
 609        if (lookupEndpoints.Length == 0)
 610        {
 611            int protocol = ipv4 && !preferIPv6 ? Ice.Internal.Network.EnableIPv4 : Ice.Internal.Network.EnableIPv6;
 612            List<string> interfaces = Ice.Internal.Network.getInterfacesForMulticast(intf, protocol);
 613            foreach (string p in interfaces)
 614            {
 615                if (p != interfaces[0])
 616                {
 617                    lookupEndpoints += ":";
 618                }
 619                lookupEndpoints += "udp -h \"" + address + "\" -p " + port + " --interface \"" + p + "\"";
 620            }
 621        }
 622
 623        if (properties.getIceProperty("IceLocatorDiscovery.Reply.Endpoints").Length == 0)
 624        {
 625            properties.setProperty(
 626                "IceLocatorDiscovery.Reply.Endpoints",
 627                "udp -h " + (intf.Length == 0 ? "*" : "\"" + intf + "\""));
 628        }
 629
 630        if (properties.getIceProperty("IceLocatorDiscovery.Locator.Endpoints").Length == 0)
 631        {
 632            properties.setProperty("IceLocatorDiscovery.Locator.AdapterId", Guid.NewGuid().ToString());
 633        }
 634
 635        _replyAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Reply");
 636        _locatorAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Locator");
 637
 638        // We don't want those adapters to be registered with the locator so clear their locator.
 639        _replyAdapter.setLocator(null);
 640        _locatorAdapter.setLocator(null);
 641
 642        Ice.ObjectPrx lookupPrx = Ice.ObjectPrxHelper.createProxy(
 643            _communicator,
 644            "IceLocatorDiscovery/Lookup -d:" + lookupEndpoints);
 645
 646        lookupPrx = lookupPrx.ice_router(null);
 647
 648        Ice.LocatorPrx voidLo = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI()));
 649
 650        string instanceName = properties.getIceProperty("IceLocatorDiscovery.InstanceName");
 651        var id = new Ice.Identity("Locator", instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString());
 652
 653        _defaultLocator = _communicator.getDefaultLocator();
 654        _locator = new LocatorI(LookupPrxHelper.uncheckedCast(lookupPrx), properties, instanceName, voidLo);
 655        _locatorPrx = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.add(_locator, id));
 656        _communicator.setDefaultLocator(_locatorPrx);
 657
 658        Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(_locator)).ice_datagram();
 659        _locator.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply));
 660
 661        _replyAdapter.activate();
 662        _locatorAdapter.activate();
 663    }
 664
 665    public void
 666    destroy()
 667    {
 668        _replyAdapter?.destroy();
 669        _locatorAdapter?.destroy();
 670        if (_communicator.getDefaultLocator().Equals(_locatorPrx))
 671        {
 672            // Restore original default locator proxy, if the user didn't change it in the meantime
 673            _communicator.setDefaultLocator(_defaultLocator);
 674        }
 675    }
 676
 677    private readonly Ice.Communicator _communicator;
 678    private Ice.ObjectAdapter _locatorAdapter;
 679    private Ice.ObjectAdapter _replyAdapter;
 680    private LocatorI _locator;
 681    private Ice.LocatorPrx _locatorPrx;
 682    private Ice.LocatorPrx _defaultLocator;
 683}