internal ILocatorRegistryPrx?GetLocatorRegistry() { lock (this) { if (_locatorRegistry != null) { return(_locatorRegistry); } } // // Do not make locator calls from within sync. // ILocatorRegistryPrx locatorRegistry = Locator.GetRegistry(); if (locatorRegistry == null) { return(null); } lock (this) { // // The locator registry can't be located. We use ordered // endpoint selection in case the locator returned a proxy // with some endpoints which are prefered to be tried first. // _locatorRegistry = locatorRegistry.Clone(clearLocator: true, endpointSelectionType: EndpointSelectionType.Ordered); return(_locatorRegistry); } }
public override void Run(string[] args) { // // Register the server manager. The server manager creates a new // 'server'(a server isn't a different process, it's just a new // communicator and object adapter). // Dictionary <string, string> properties = CreateTestProperties(ref args); using Communicator communicator = Initialize(properties); communicator.SetProperty("ServerManagerAdapter.Endpoints", GetTestEndpoint(0)); ObjectAdapter adapter = communicator.CreateObjectAdapter("ServerManagerAdapter"); // // We also register a sample server locator which implements the // locator interface, this locator is used by the clients and the // 'servers' created with the server manager interface. // var registry = new ServerLocatorRegistry(); var obj = new ServerManager(registry, this); adapter.Add("ServerManager", obj); registry.AddObject(adapter.CreateProxy("ServerManager", IObjectPrx.Factory)); ILocatorRegistryPrx registryPrx = adapter.Add("registry", registry, ILocatorRegistryPrx.Factory); adapter.Add("locator", new ServerLocator(registry, registryPrx)); adapter.Activate(); ServerReady(); communicator.WaitForShutdown(); }
public override void run(string[] args) { // // Register the server manager. The server manager creates a new // 'server'(a server isn't a different process, it's just a new // communicator and object adapter). // var properties = createTestProperties(ref args); properties["Ice.ThreadPool.Server.Size"] = "2"; using (var communicator = initialize(properties)) { communicator.SetProperty("ServerManagerAdapter.Endpoints", getTestEndpoint(0)); ObjectAdapter adapter = communicator.createObjectAdapter("ServerManagerAdapter"); // // We also register a sample server locator which implements the // locator interface, this locator is used by the clients and the // 'servers' created with the server manager interface. // ServerLocatorRegistry registry = new ServerLocatorRegistry(); var obj = new ServerManagerI(registry, this); adapter.Add(obj, "ServerManager"); registry.addObject(adapter.CreateProxy("ServerManager")); ILocatorRegistryPrx registryPrx = adapter.Add(registry, "registry"); adapter.Add(new ServerLocator(registry, registryPrx), "locator"); adapter.Activate(); serverReady(); communicator.waitForShutdown(); } }
public override async Task RunAsync(string[] args) { await Communicator.ActivateAsync(); Communicator.SetProperty("ServerManagerAdapter.Endpoints", GetTestEndpoint(0)); // Register the server manager. The server manager creates a new 'server'(a server isn't a different // process, it's just a new communicator and object adapter). ObjectAdapter adapter = Communicator.CreateObjectAdapter("ServerManagerAdapter"); // We also register a sample server locator which implements the locator interface, this locator is used by // the clients and the 'servers' created with the server manager interface. var registry = new ServerLocatorRegistry(); var obj = new ServerManager(registry, this); adapter.Add("ServerManager", obj); registry.AddObject(adapter.CreateProxy("ServerManager", IObjectPrx.Factory)); ILocatorRegistryPrx registryPrx = adapter.Add("registry", registry, ILocatorRegistryPrx.Factory); adapter.Add("locator", new ServerLocator(registry, registryPrx)); await adapter.ActivateAsync(); ServerReady(); await Communicator.ShutdownComplete; }
private static void UnregisterAdapterEndpoints( ILocatorRegistryPrx registry, string adapterId, string replicaGroupId) { if (registry.Protocol == Protocol.Ice1) { registry.SetReplicatedAdapterDirectProxy(adapterId, replicaGroupId, null); } else { registry.UnregisterAdapterEndpoints(adapterId, replicaGroupId); } }
private static void RegisterAdapterEndpoints( ILocatorRegistryPrx registry, string adapterId, string replicaGroupId, IObjectPrx proxy) { if (proxy.Protocol == Protocol.Ice1) { registry.SetReplicatedAdapterDirectProxy(adapterId, replicaGroupId, proxy); } else { registry.RegisterAdapterEndpoints(adapterId, replicaGroupId, proxy.Endpoints.ToEndpointDataList()); } }
public void Initialize(PluginInitializationContext context) { const string defaultIPv4Endpoint = "udp -h 239.255.0.1 -p 4061"; const string defaultIPv6Endpoint = "udp -h \"ff15::1\" -p 4061"; if (_communicator.GetProperty("IceDiscovery.Multicast.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", $"{defaultIPv4Endpoint}:{defaultIPv6Endpoint}"); } string?lookupEndpoints = _communicator.GetProperty("IceDiscovery.Lookup"); if (lookupEndpoints == null) { List <string> endpoints = new (); List <string> ipv4Interfaces = Network.GetInterfacesForMulticast("0.0.0.0", Network.EnableIPv4); List <string> ipv6Interfaces = Network.GetInterfacesForMulticast("::0", Network.EnableIPv6); endpoints.AddRange(ipv4Interfaces.Select(i => $"{defaultIPv4Endpoint} --interface \"{i}\"")); endpoints.AddRange(ipv6Interfaces.Select(i => $"{defaultIPv6Endpoint} --interface \"{i}\"")); lookupEndpoints = string.Join(":", endpoints); } if (_communicator.GetProperty("IceDiscovery.Reply.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Reply.Endpoints", "udp -h \"::0\" -p 0"); } if (_communicator.GetProperty("IceDiscovery.Locator.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _multicastAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Multicast"); _replyAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Reply"); _locatorAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Locator"); // Setup locator registry. var locatorRegistryServant = new LocatorRegistry(_communicator); ILocatorRegistryPrx locatorRegistry = _locatorAdapter.AddWithUUID(locatorRegistryServant, ILocatorRegistryPrx.Factory); ILookupPrx lookup = ILookupPrx.Parse($"IceDiscovery/Lookup -d:{lookupEndpoints}", _communicator).Clone(clearRouter: true); // Add lookup Ice object var lookupServant = new Lookup(locatorRegistryServant, _communicator); _multicastAdapter.Add("IceDiscovery/Lookup", lookupServant); // Setup locator on the communicator. _locator = _locatorAdapter.AddWithUUID(new Locator(locatorRegistry, lookup, _replyAdapter), ILocatorPrx.Factory); _defaultLocator = _communicator.DefaultLocator; _communicator.DefaultLocator = _locator; _multicastAdapter.Activate(); _replyAdapter.Activate(); _locatorAdapter.Activate(); }
public ServerLocator(ServerLocatorRegistry registry, ILocatorRegistryPrx registryPrx) { _registry = registry; _registryPrx = registryPrx; _requestCount = 0; }
public void Initialize(PluginInitializationContext context) { bool ipv4 = _communicator.GetPropertyAsBool("Ice.IPv4") ?? true; bool preferIPv6 = _communicator.GetPropertyAsBool("Ice.PreferIPv6Address") ?? false; string address; if (ipv4 && !preferIPv6) { address = _communicator.GetProperty("IceDiscovery.Address") ?? "239.255.0.1"; } else { address = _communicator.GetProperty("IceDiscovery.Address") ?? "ff15::1"; } int port = _communicator.GetPropertyAsInt("IceDiscovery.Port") ?? 4061; string intf = _communicator.GetProperty("IceDiscovery.Interface") ?? ""; if (_communicator.GetProperty("IceDiscovery.Multicast.Endpoints") == null) { if (intf.Length > 0) { _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", $"udp -h \"{address}\" -p {port} --interface \"{intf}\""); } else { _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", $"udp -h \"{address}\" -p {port}"); } } string lookupEndpoints = _communicator.GetProperty("IceDiscovery.Lookup") ?? ""; if (lookupEndpoints.Length == 0) { int ipVersion = ipv4 && !preferIPv6 ? Network.EnableIPv4 : Network.EnableIPv6; List <string> interfaces = Network.GetInterfacesForMulticast(intf, ipVersion); foreach (string p in interfaces) { if (p != interfaces[0]) { lookupEndpoints += ":"; } lookupEndpoints += $"udp -h \"{address}\" -p {port} --interface \"{p}\""; } } if (_communicator.GetProperty("IceDiscovery.Reply.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Reply.Endpoints", intf.Length == 0 ? "udp -h *" : $"udp -h \"{intf}\""); } if (_communicator.GetProperty("IceDiscovery.Locator.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _multicastAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Multicast"); _replyAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Reply"); _locatorAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Locator"); // Setup locator registry. var locatorRegistry = new LocatorRegistry(); ILocatorRegistryPrx locatorRegistryPrx = _locatorAdapter.AddWithUUID(locatorRegistry, ILocatorRegistryPrx.Factory); ILookupPrx lookupPrx = ILookupPrx.Parse($"IceDiscovery/Lookup -d:{lookupEndpoints}", _communicator).Clone(clearRouter: true); // Add lookup Ice object var lookup = new Lookup(locatorRegistry, lookupPrx, _communicator, _replyAdapter); _multicastAdapter.Add("IceDiscovery/Lookup", lookup); // Setup locator on the communicator. _locator = _locatorAdapter.AddWithUUID(new Locator(lookup, locatorRegistryPrx), ILocatorPrx.Factory); _defaultLocator = _communicator.DefaultLocator; _communicator.DefaultLocator = _locator; _multicastAdapter.Activate(); _replyAdapter.Activate(); _locatorAdapter.Activate(); }
internal Locator(Lookup lookup, ILocatorRegistryPrx registry) { _lookup = lookup; _registry = registry; }
public void initialize() { bool ipv4 = (_communicator.GetPropertyAsInt("Ice.IPv4") ?? 1) > 0; bool preferIPv6 = _communicator.GetPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if (ipv4 && !preferIPv6) { address = _communicator.GetProperty("IceDiscovery.Address") ?? "239.255.0.1"; } else { address = _communicator.GetProperty("IceDiscovery.Address") ?? "ff15::1"; } int port = _communicator.GetPropertyAsInt("IceDiscovery.Port") ?? 4061; string intf = _communicator.GetProperty("IceDiscovery.Interface") ?? ""; if (_communicator.GetProperty("IceDiscovery.Multicast.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", intf.Length > 0 ? $"udp -h \"{address}\" -p {port} --interface \"{intf}\"" : $"udp -h \"{address}\" -p {port}"); } string lookupEndpoints = _communicator.GetProperty("IceDiscovery.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("IceDiscovery.Reply.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Reply.Endpoints", intf.Length == 0 ? "udp -h *" : $"udp -h \"{intf}\""); } if (_communicator.GetProperty("IceDiscovery.Locator.Endpoints") == null) { _communicator.SetProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _multicastAdapter = _communicator.createObjectAdapter("IceDiscovery.Multicast"); _replyAdapter = _communicator.createObjectAdapter("IceDiscovery.Reply"); _locatorAdapter = _communicator.createObjectAdapter("IceDiscovery.Locator"); // // Setup locatory registry. // LocatorRegistryI locatorRegistry = new LocatorRegistryI(_communicator); ILocatorRegistryPrx locatorRegistryPrx = _locatorAdapter.Add(locatorRegistry); ILookupPrx lookupPrx = ILookupPrx.Parse("IceDiscovery/Lookup -d:" + lookupEndpoints, _communicator).Clone( clearRouter: true, collocationOptimized: false); // No colloc optimization or router for the multicast proxy! // // Add lookup and lookup reply Ice objects // LookupI lookup = new LookupI(locatorRegistry, lookupPrx, _communicator); _multicastAdapter.Add(lookup, "IceDiscovery/Lookup"); LookupReplyTraits lookupT = default; LookupReplyI lookupReply = new LookupReplyI(lookup); _replyAdapter.AddDefaultServant( (current, incoming) => lookupT.Dispatch(lookupReply, current, incoming), ""); lookup.SetLookupReply(ILookupReplyPrx.UncheckedCast(_replyAdapter.CreateProxy("dummy")).Clone(invocationMode: InvocationMode.Datagram)); // // Setup locator on the communicator. // _locator = _locatorAdapter.Add(new LocatorI(lookup, locatorRegistryPrx)); _defaultLocator = _communicator.getDefaultLocator(); _communicator.setDefaultLocator(_locator); _multicastAdapter.Activate(); _replyAdapter.Activate(); _locatorAdapter.Activate(); }