public void setLocator(LocatorPrx locator) { lock (this) { checkForDeactivation(); _locatorInfo = instance_.locatorManager().get(locator); } }
LocatorI(string name, LookupPrx lookup, Communicator communicator, string instanceName, LocatorPrx voidLocator) { _lookup = lookup; _timeout = communicator.GetPropertyAsInt($"{name}.Timeout") ?? 300; if (_timeout < 0) { _timeout = 300; } _retryCount = communicator.GetPropertyAsInt("${name}.RetryCount") ?? 3; if (_retryCount < 0) { _retryCount = 0; } _retryDelay = communicator.GetPropertyAsInt($"{name}.RetryDelay") ?? 2000; if (_retryDelay < 0) { _retryDelay = 0; } _timer = lookup.Communicator.timer(); _traceLevel = communicator.GetPropertyAsInt($"{name}.Trace.Lookup") ?? 0; _instanceName = instanceName; _warned = false; _locator = lookup.Communicator.getDefaultLocator(); _voidLocator = voidLocator; _pending = false; _pendingRetryCount = 0; _failureCount = 0; _warnOnce = true; // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. // var single = new Endpoint[1]; foreach (var endpt in lookup.Endpoints) { single[0] = endpt; _lookups[lookup.Clone(endpoints: single)] = null; } Debug.Assert(_lookups.Count > 0); }
// // Returns locator info for a given locator. Automatically creates // the locator info if it doesn't exist yet. // public LocatorInfo get(LocatorPrx loc) { if (loc == null) { throw new System.ArgumentNullException(nameof(loc)); } // // The locator can't be located. // LocatorPrx locator = loc.Clone(clearLocator: true); // // TODO: reap unused locator info objects? // lock (this) { LocatorInfo info; if (!_table.TryGetValue(locator, out info)) { // // Rely on locator identity for the adapter table. We want to // have only one table per locator (not one per locator // proxy). // LocatorTable?table = null; LocatorKey key = new LocatorKey(locator); if (!_locatorTables.TryGetValue(key, out table)) { table = new LocatorTable(); _locatorTables[key] = table; } info = new LocatorInfo(locator, table, _background); _table[locator] = info; } return(info); } }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = ServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = TestLocatorPrx.UncheckedCast(communicator.getDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = TestLocatorRegistryPrx.CheckedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = IObjectPrx.Parse("test @ TestAdapter", communicator); var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); var base3 = IObjectPrx.Parse("test", communicator); var base4 = IObjectPrx.Parse("ServerManager", communicator); var base5 = IObjectPrx.Parse("test2", communicator); var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); var anotherLocator = LocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = RouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Compare(@base.Router, anotherRouter) == 0); var router = RouterPrx.Parse("dummyrouter", communicator); communicator.setDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Router, communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = TestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = hello.Clone(adapterId: "unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync().ContinueWith((Task t) => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); registry.setAdapterDirectProxy("TestAdapter3", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; Communicator ic = helper.initialize(properties); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.GetConnection().close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter10", communicator).Clone(encodingVersion: Util.Encoding_1_0).IcePing(); test(++count == locator.getRequestCount()); IObjectPrx.Parse("test -e 1.0@TestAdapter10-2", communicator).IcePing(); test(++count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(new HelloI(), id); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. HelloPrx?helloPrx = HelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateIndirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateDirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
public void setDefaultLocator(LocatorPrx locator) { instance_.setDefaultLocator(locator); }
public void setLocator(LocatorPrx locator) { lock(this) { checkForDeactivation(); _locatorInfo = instance_.locatorManager().get(locator); } }
public static Test.BackgroundPrx allTests(Test.TestHelper helper) { Communicator communicator = helper.communicator(); var background = BackgroundPrx.Parse($"background:{helper.getTestEndpoint(0)}", communicator); var backgroundController = BackgroundControllerPrx.Parse("backgroundController:" + helper.getTestEndpoint(1, "tcp"), communicator); Configuration configuration = Configuration.getInstance(); Console.Write("testing connect... "); Console.Out.Flush(); { connectTests(configuration, background); } Console.Out.WriteLine("ok"); Console.Write("testing initialization... "); Console.Out.Flush(); { initializeTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing connection validation... "); Console.Out.Flush(); { validationTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing read/write... "); Console.Out.Flush(); { readWriteTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing locator... "); Console.Out.Flush(); { var locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(locator: locator, oneway: true); backgroundController.pauseCall("findAdapterById"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("findAdapterById"); locator = LocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone(locator: locator); locator.IcePing(); var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(locator: locator); backgroundController.pauseCall("findAdapterById"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("findAdapterById"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); Console.Write("testing router... "); Console.Out.Flush(); { var router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(router: router, oneway: true); backgroundController.pauseCall("getClientProxy"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("getClientProxy"); router = RouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator); var bg = BackgroundPrx.Parse("background@Test", communicator).Clone(router: router); test(bg.Router != null); backgroundController.pauseCall("getClientProxy"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("getClientProxy"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); bool ws = communicator.GetProperty("Ice.Default.Protocol") == "test-ws"; bool wss = communicator.GetProperty("Ice.Default.Protocol") == "test-wss"; if (!ws && !wss) { Console.Write("testing buffered transport... "); Console.Out.Flush(); configuration.buffered(true); backgroundController.buffered(true); background.opAsync(); background.GetCachedConnection() !.close(ConnectionClose.Forcefully); background.opAsync(); OpAMICallback cb = new OpAMICallback(); var results = new List <Task>(); for (int i = 0; i < 10000; ++i) { var t = background.opAsync().ContinueWith((Task p) => { try { p.Wait(); cb.responseNoOp(); } catch (Ice.Exception ex) { cb.noException(ex); } }); results.Add(t); if (i % 50 == 0) { backgroundController.holdAdapter(); backgroundController.resumeAdapter(); } if (i % 100 == 0) { t.Wait(); } } Task.WaitAll(results.ToArray()); Console.Out.WriteLine("ok"); } return(background); }
public void startServer(Ice.Current current) { foreach (Ice.Communicator c in _communicators) { c.waitForShutdown(); c.destroy(); } _communicators.Clear(); // // Simulate a server: create a new communicator and object // adapter. The object adapter is started on a system allocated // port. The configuration used here contains the Ice.Locator // configuration variable. The new object adapter will register // its endpoints with the locator and create references containing // the adapter id instead of the endpoints. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = _helper.communicator().Properties.Clone(); initData.properties.setProperty("TestAdapter.AdapterId", "TestAdapter"); initData.properties.setProperty("TestAdapter.ReplicaGroupId", "ReplicatedAdapter"); initData.properties.setProperty("TestAdapter2.AdapterId", "TestAdapter2"); Ice.Communicator serverCommunicator = _helper.initialize(initData); _communicators.Add(serverCommunicator); // // Use fixed port to ensure that OA re-activation doesn't re-use previous port from // another OA(e.g.: TestAdapter2 is re-activated using port of TestAdapter). // int nRetry = 10; while (--nRetry > 0) { ObjectAdapter?adapter = null; ObjectAdapter?adapter2 = null; try { serverCommunicator.Properties.setProperty("TestAdapter.Endpoints", _helper.getTestEndpoint(_nextPort++)); serverCommunicator.Properties.setProperty("TestAdapter2.Endpoints", _helper.getTestEndpoint(_nextPort++)); adapter = serverCommunicator.createObjectAdapter("TestAdapter"); adapter2 = serverCommunicator.createObjectAdapter("TestAdapter2"); var locator = LocatorPrx.Parse($"locator:{_helper.getTestEndpoint(0)}", serverCommunicator); adapter.SetLocator(locator); adapter2.SetLocator(locator); var testI = new TestI(adapter, adapter2, _registry); _registry.addObject(adapter.Add(testI, "test")); _registry.addObject(adapter.Add(testI, "test2")); adapter.Add(testI, "test3"); adapter.Activate(); adapter2.Activate(); break; } catch (Ice.SocketException ex) { if (nRetry == 0) { throw ex; } // Retry, if OA creation fails with EADDRINUSE(this can occur when running with JS web // browser clients if the driver uses ports in the same range as this test, ICE-8148) if (adapter != null) { adapter.Destroy(); } if (adapter2 != null) { adapter2.Destroy(); } } } }
/// <summary> /// Creates a new proxy that is identical to this proxy, except for the locator. /// </summary> /// <param name="locator">The locator for the new proxy.</param> /// <returns>The new proxy with the specified locator.</returns> public ObjectPrx ice_locator(LocatorPrx locator) { IceInternal.Reference @ref = _reference.changeLocator(locator); if(@ref.Equals(_reference)) { return this; } else { return newInstance(@ref); } }
initialize() { bool ipv4 = (_communicator.GetPropertyAsInt("Ice.IPv4") ?? 1) > 0; bool preferIPv6 = _communicator.GetPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if (ipv4 && !preferIPv6) { address = _communicator.GetProperty($"{_name}.Address") ?? "239.255.0.1"; } else { address = _communicator.GetProperty($"{_name}.Address") ?? "ff15::1"; } int port = _communicator.GetPropertyAsInt($"{_name}.Port") ?? 4061; string intf = _communicator.GetProperty($"{_name}.Interface") ?? ""; string lookupEndpoints = _communicator.GetProperty($"{_name}.Lookup") ?? ""; if (lookupEndpoints.Length == 0) { int protocol = ipv4 && !preferIPv6 ? IceInternal.Network.EnableIPv4 : IceInternal.Network.EnableIPv6; var interfaces = IceInternal.Network.getInterfacesForMulticast(intf, protocol); foreach (string p in interfaces) { if (p != interfaces[0]) { lookupEndpoints += ":"; } lookupEndpoints += "udp -h \"" + address + "\" -p " + port + " --interface \"" + p + "\""; } } if (_communicator.GetProperty($"{_name}.Reply.Endpoints") == null) { _communicator.SetProperty($"{_name}.Reply.Endpoints", intf.Length == 0 ? "udp -h *" : $"udp -h \"{intf}\""); } if (_communicator.GetProperty($"{_name}.Locator.Endpoints") == null) { _communicator.SetProperty($"{_name}.Locator.AdapterId", Guid.NewGuid().ToString()); } _replyAdapter = _communicator.createObjectAdapter(_name + ".Reply"); _locatorAdapter = _communicator.createObjectAdapter(_name + ".Locator"); // We don't want those adapters to be registered with the locator so clear their locator. _replyAdapter.SetLocator(null); _locatorAdapter.SetLocator(null); var lookupPrx = LookupPrx.Parse($"IceLocatorDiscovery/Lookup -d:{lookupEndpoints}", _communicator); // No colloc optimization or router for the multicast proxy! lookupPrx = lookupPrx.Clone(clearRouter: false, collocationOptimized: false); LocatorPrx voidLo = _locatorAdapter.Add(new VoidLocatorI()); string instanceName = _communicator.GetProperty($"{_name}.InstanceName") ?? ""; var id = new Identity("Locator", instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString()); _defaultLocator = _communicator.getDefaultLocator(); _locator = new LocatorI(_name, lookupPrx, _communicator, instanceName, voidLo); _locatorPrx = LocatorPrx.UncheckedCast( _locatorAdapter.Add((current, incoming) => _locator.Dispatch(current, incoming))); _communicator.setDefaultLocator(_locatorPrx); LookupReply lookupReplyI = new LookupReplyI(_locator); _locator.setLookupReply(_replyAdapter.Add(lookupReplyI).Clone(invocationMode: InvocationMode.Datagram)); _replyAdapter.Activate(); _locatorAdapter.Activate(); }
foundLocator(LocatorPrx locator) { lock (this) { if (locator == null || (_instanceName.Length > 0 && !locator.Identity.category.Equals(_instanceName))) { if (_traceLevel > 2) { StringBuilder s = new StringBuilder("ignoring locator reply: instance name doesn't match\n"); s.Append("expected = ").Append(_instanceName); s.Append("received = ").Append(locator.Identity.category); _lookup.Communicator.Logger.trace("Lookup", s.ToString()); } return; } // // If we already have a locator assigned, ensure the given locator // has the same identity, otherwise ignore it. // if (_pendingRequests.Count > 0 && _locator != null && !locator.Identity.category.Equals(_locator.Identity.category)) { if (!_warned) { _warned = true; // Only warn once locator.Communicator.Logger.warning( "received Ice locator with different instance name:\n" + "using = `" + _locator.Identity.category + "'\n" + "received = `" + locator.Identity.category + "'\n" + "This is typically the case if multiple Ice locators with different " + "instance names are deployed and the property `IceLocatorDiscovery.InstanceName'" + "is not set."); } return; } if (_pending) // No need to continue, we found a locator { _timer.cancel(this); _pendingRetryCount = 0; _pending = false; } if (_traceLevel > 0) { StringBuilder s = new StringBuilder("locator lookup succeeded:\nlocator = "); s.Append(locator); if (_instanceName.Length == 0) { s.Append("\ninstance name = ").Append(_instanceName); } _lookup.Communicator.Logger.trace("Lookup", s.ToString()); } LocatorPrx?l = null; if (_pendingRequests.Count == 0) { _locators.TryGetValue(locator.Identity.category, out _locator); } else { l = _locator; } if (l != null) { // // We found another locator replica, append its endpoints to the // current locator proxy endpoints. // List <Endpoint> newEndpoints = new List <Endpoint>(l.Endpoints); foreach (Endpoint p in locator.Endpoints) { // // Only add endpoints if not already in the locator proxy endpoints // bool found = false; foreach (Endpoint q in newEndpoints) { if (p.Equals(q)) { found = true; break; } } if (!found) { newEndpoints.Add(p); } } l = l.Clone(endpoints: newEndpoints.ToArray()); } else { l = locator; } if (_pendingRequests.Count == 0) { _locators[locator.Identity.category] = l; Monitor.Pulse(this); } else { _locator = l; if (_instanceName.Length == 0) { _instanceName = _locator.Identity.category; // Stick to the first locator } // // Send pending requests if any. // foreach (Request req in _pendingRequests) { req.invoke(_locator); } _pendingRequests.Clear(); } } }
public void setLocator(LocatorPrx locator) { _m.Lock(); try { checkForDeactivation(); _locatorInfo = instance_.locatorManager().get(locator); } finally { _m.Unlock(); } }
foundLocator(LocatorPrx locator, Ice.Current current) { _locator.foundLocator(locator); }
foundLocator(LocatorPrx locator) { lock(this) { if(locator == null || (_instanceName.Length > 0 && !locator.ice_getIdentity().category.Equals(_instanceName))) { return; } // // If we already have a locator assigned, ensure the given locator // has the same identity, otherwise ignore it. // if(_locator != null && !locator.ice_getIdentity().category.Equals(_locator.ice_getIdentity().category)) { if(!_warned) { _warned = true; // Only warn once locator.ice_getCommunicator().getLogger().warning( "received IceGrid locator with different instance name:\n" + "using = `" + _locator.ice_getIdentity().category + "'\n" + "received = `" + locator.ice_getIdentity().category + "'\n" + "This is typically the case if multiple IceGrid registries with different " + "nstance names are deployed and the property `IceGridDiscovery.InstanceName'" + "is not set."); } return; } if(_pendingRetryCount > 0) // No need to retry, we found a locator { _timer.cancel(this); _pendingRetryCount = 0; } if(_locator != null) { // // We found another locator replica, append its endpoints to the // current locator proxy endpoints. // List<Ice.Endpoint> newEndpoints = new List<Ice.Endpoint>(_locator.ice_getEndpoints()); foreach(Ice.Endpoint p in locator.ice_getEndpoints()) { // // Only add endpoints if not already in the locator proxy endpoints // bool found = false; foreach(Ice.Endpoint q in newEndpoints) { if(p.Equals(q)) { found = true; break; } } if(!found) { newEndpoints.Add(p); } } _locator = (LocatorPrx) _locator.ice_endpoints(newEndpoints.ToArray()); } else { _locator = locator; if(_instanceName.Length == 0) { _instanceName = _locator.ice_getIdentity().category; // Stick to the first locator } } // // Send pending requests if any. // foreach(Request req in _pendingRequests) { req.invoke(_locator); } _pendingRequests.Clear(); } }