initialize() { Ice.Properties properties = _communicator.getProperties(); bool ipv4 = properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool preferIPv6 = properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if (ipv4 && !preferIPv6) { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "239.255.0.1"); } else { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "ff15::1"); } int port = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.Port", 4061); string intf = properties.getProperty("IceLocatorDiscovery.Interface"); if (properties.getProperty("IceLocatorDiscovery.Reply.Endpoints").Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp"); if (intf.Length > 0) { s.Append(" -h \""); s.Append(intf); s.Append("\""); } properties.setProperty("IceLocatorDiscovery.Reply.Endpoints", s.ToString()); } if (properties.getProperty("IceLocatorDiscovery.Locator.Endpoints").Length == 0) { properties.setProperty("IceLocatorDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _replyAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Reply"); _locatorAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Locator"); // We don't want those adapters to be registered with the locator so clear their locator. _replyAdapter.setLocator(null); _locatorAdapter.setLocator(null); string lookupEndpoints = properties.getProperty("IceLocatorDiscovery.Lookup"); if (lookupEndpoints.Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp -h \""); s.Append(address); s.Append("\" -p "); s.Append(port); if (intf.Length > 0) { s.Append(" --interface \""); s.Append(intf); s.Append("\""); } lookupEndpoints = s.ToString(); } Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); // No colloc optimization for the multicast proxy! try { lookupPrx.ice_getConnection(); // Ensure we can establish a connection to the multicast proxy } catch (Ice.LocalException ex) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("IceLocatorDiscovery is unable to establish a multicast connection:\n"); s.Append("proxy = "); s.Append(lookupPrx.ToString()); s.Append("\n"); s.Append(ex); throw new Ice.PluginInitializationException(s.ToString()); } Ice.LocatorPrx voidLo = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI())); string instanceName = properties.getProperty("IceLocatorDiscovery.InstanceName"); Ice.Identity id = new Ice.Identity(); id.name = "Locator"; id.category = instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString(); LocatorI locator = new LocatorI(LookupPrxHelper.uncheckedCast(lookupPrx), properties, instanceName, voidLo); _communicator.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(locator))); Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(locator)).ice_datagram(); locator.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply)); _replyAdapter.activate(); _locatorAdapter.activate(); }
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 = ILookupPrx.Parse($"IceLocatorDiscovery/Lookup -d:{lookupEndpoints}", _communicator); // No colloc optimization or router for the multicast proxy! lookupPrx = lookupPrx.Clone(clearRouter: false, collocationOptimized: false); ILocatorPrx 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 = ILocatorPrx.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(); }
public void initialize() { Ice.Properties properties = _communicator.getProperties(); bool ipv4 = properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool preferIPv6 = properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if(ipv4 && !preferIPv6) { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "239.255.0.1"); } else { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "ff15::1"); } int port = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.Port", 4061); string intf = properties.getProperty("IceLocatorDiscovery.Interface"); if(properties.getProperty("IceLocatorDiscovery.Reply.Endpoints").Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp"); if(intf.Length > 0) { s.Append(" -h \""); s.Append(intf); s.Append("\""); } properties.setProperty("IceLocatorDiscovery.Reply.Endpoints", s.ToString()); } if(properties.getProperty("IceLocatorDiscovery.Locator.Endpoints").Length == 0) { properties.setProperty("IceLocatorDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _replyAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Reply"); _locatorAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Locator"); // We don't want those adapters to be registered with the locator so clear their locator. _replyAdapter.setLocator(null); _locatorAdapter.setLocator(null); string lookupEndpoints = properties.getProperty("IceLocatorDiscovery.Lookup"); if(lookupEndpoints.Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp -h \""); s.Append(address); s.Append("\" -p "); s.Append(port); if(intf.Length > 0) { s.Append(" --interface \""); s.Append(intf); s.Append("\""); } lookupEndpoints = s.ToString(); } Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); // No colloc optimization for the multicast proxy! try { lookupPrx.ice_getConnection(); // Ensure we can establish a connection to the multicast proxy } catch (Ice.LocalException ex) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("IceLocatorDiscovery is unable to establish a multicast connection:\n"); s.Append("proxy = "); s.Append(lookupPrx.ToString()); s.Append("\n"); s.Append(ex); throw new Ice.PluginInitializationException(s.ToString()); } Ice.LocatorPrx voidLo = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI())); string instanceName = properties.getProperty("IceLocatorDiscovery.InstanceName"); Ice.Identity id = new Ice.Identity(); id.name = "Locator"; id.category = instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString(); LocatorI locator = new LocatorI(LookupPrxHelper.uncheckedCast(lookupPrx), properties, instanceName, voidLo); _communicator.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(locator))); Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(locator)).ice_datagram(); locator.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply)); _replyAdapter.activate(); _locatorAdapter.activate(); }
initialize() { Ice.Properties properties = _communicator.getProperties(); bool ipv4 = properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool preferIPv6 = properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if (ipv4 && !preferIPv6) { address = properties.getPropertyWithDefault(_name + ".Address", "239.255.0.1"); } else { address = properties.getPropertyWithDefault(_name + ".Address", "ff15::1"); } int port = properties.getPropertyAsIntWithDefault(_name + ".Port", 4061); string intf = properties.getProperty(_name + ".Interface"); string lookupEndpoints = properties.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 (properties.getProperty(_name + ".Reply.Endpoints").Length == 0) { properties.setProperty(_name + ".Reply.Endpoints", "udp -h " + (intf.Length == 0 ? "*" : "\"" + intf + "\"")); } if (properties.getProperty(_name + ".Locator.Endpoints").Length == 0) { properties.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); Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + lookupEndpoints); // No colloc optimization or router for the multicast proxy! lookupPrx = lookupPrx.ice_collocationOptimized(false).ice_router(null); Ice.LocatorPrx voidLo = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI())); string instanceName = properties.getProperty(_name + ".InstanceName"); Ice.Identity id = new Ice.Identity(); id.name = "Locator"; id.category = instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString(); _defaultLocator = _communicator.getDefaultLocator(); _locator = new LocatorI(_name, LookupPrxHelper.uncheckedCast(lookupPrx), properties, instanceName, voidLo); _locatorPrx = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(_locator)); _communicator.setDefaultLocator(_locatorPrx); Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(_locator)).ice_datagram(); _locator.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply)); _replyAdapter.activate(); _locatorAdapter.activate(); }