diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-03-01 19:42:52 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-03-01 19:42:52 +0100 |
commit | 0a57f0b1841f51bc45ff2adc9ac19e114d695e43 (patch) | |
tree | 2ecab85164a70618fc0f861058f97194cb4e797e /java/src | |
parent | UWP build failure (diff) | |
download | ice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.tar.bz2 ice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.tar.xz ice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.zip |
Fixed ICE-7584 - discovery plugins now send multicast datagrams on all interfaces
Diffstat (limited to 'java/src')
11 files changed, 438 insertions, 357 deletions
diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Network.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Network.java index 7e29515406d..cb56f0bb9e1 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Network.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Network.java @@ -303,7 +303,7 @@ public final class Network try { java.util.Set<java.net.NetworkInterface> interfaces = new java.util.HashSet<>(); - for(String address : getInterfacesForMulticast(intf, group)) + for(String address : getInterfacesForMulticast(intf, getProtocolSupport(group))) { java.net.NetworkInterface intf2 = getInterface(address); if(!interfaces.contains(intf2)) @@ -325,7 +325,7 @@ public final class Network try { java.util.Set<java.net.NetworkInterface> interfaces = new java.util.HashSet<>(); - for(String address : getInterfacesForMulticast(intf, group)) + for(String address : getInterfacesForMulticast(intf, getProtocolSupport(group))) { java.net.NetworkInterface intf2 = getInterface(address); if(!interfaces.contains(intf2)) @@ -1081,10 +1081,9 @@ public final class Network return hosts; } - public static java.util.ArrayList<String> - getInterfacesForMulticast(String intf, java.net.InetSocketAddress mcastAddr) + public static java.util.List<String> + getInterfacesForMulticast(String intf, int protocolSupport) { - int protocolSupport = getProtocolSupport(mcastAddr); java.util.ArrayList<String> interfaces = new java.util.ArrayList<>(); if(isWildcard(intf)) { diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java index 6d1273b8793..eb3319e9b46 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java @@ -6,7 +6,7 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -// Generated by makeprops.py from file ..\config\PropertyNames.xml, Fri Feb 24 18:49:18 2017 +// Generated by makeprops.py from file ./config/PropertyNames.xml, Tue Feb 28 15:01:12 2017 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -504,6 +504,43 @@ public final class PropertyNames new Property("IceGridAdmin\\.Discovery\\.Reply\\.ThreadPool\\.ThreadIdleTime", false, null), new Property("IceGridAdmin\\.Discovery\\.Reply\\.ThreadPool\\.ThreadPriority", false, null), new Property("IceGridAdmin\\.Discovery\\.Reply\\.MessageSizeMax", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ACM\\.Timeout", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ACM\\.Heartbeat", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ACM\\.Close", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ACM", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.AdapterId", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Endpoints", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.EndpointSelection", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.ConnectionCached", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.PreferSecure", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.LocatorCacheTimeout", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.InvocationTimeout", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.Locator", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.Router", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.CollocationOptimized", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator\\.Context\\.[^\\s]+", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Locator", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.PublishedEndpoints", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ReplicaGroupId", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.EndpointSelection", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.ConnectionCached", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.PreferSecure", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.LocatorCacheTimeout", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.InvocationTimeout", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.Locator", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.Router", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.CollocationOptimized", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router\\.Context\\.[^\\s]+", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.Router", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ProxyOptions", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.Size", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.SizeMax", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.SizeWarn", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.StackSize", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.Serialize", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.ThreadIdleTime", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.ThreadPool\\.ThreadPriority", false, null), + new Property("IceGridAdmin\\.Discovery\\.Locator\\.MessageSizeMax", false, null), new Property("IceGridAdmin\\.Trace\\.Observers", false, null), new Property("IceGridAdmin\\.Trace\\.SaveToRegistry", false, null), null diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastClientTransceiver.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastClientTransceiver.java index e3edc69d4b5..2390cea50a1 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastClientTransceiver.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastClientTransceiver.java @@ -161,7 +161,8 @@ final class UdpMulticastClientTransceiver implements Transceiver public String toDetailedString() { StringBuilder s = new StringBuilder(toString()); - java.util.List<String> intfs = Network.getInterfacesForMulticast(_mcastInterface, _addr); + java.util.List<String> intfs = Network.getInterfacesForMulticast(_mcastInterface, + Network.getProtocolSupport(_addr)); if(!intfs.isEmpty()) { s.append("\nlocal interfaces = "); diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastServerTransceiver.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastServerTransceiver.java index 8c7b462e89e..bfcc1c11060 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastServerTransceiver.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpMulticastServerTransceiver.java @@ -169,7 +169,8 @@ final class UdpMulticastServerTransceiver implements Transceiver public String toDetailedString() { StringBuilder s = new StringBuilder(toString()); - java.util.List<String> intfs = Network.getInterfacesForMulticast(_mcastInterface, _addr); + java.util.List<String> intfs = Network.getInterfacesForMulticast(_mcastInterface, + Network.getProtocolSupport(_addr)); if(!intfs.isEmpty()) { s.append("\nlocal interfaces = "); diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpTransceiver.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpTransceiver.java index 491e6c0b7ee..8f6d5683251 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpTransceiver.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpTransceiver.java @@ -290,7 +290,7 @@ final class UdpTransceiver implements Transceiver } else { - intfs = Network.getInterfacesForMulticast(_mcastInterface, _mcastAddr); + intfs = Network.getInterfacesForMulticast(_mcastInterface, Network.getProtocolSupport(_mcastAddr)); } if(!intfs.isEmpty()) { diff --git a/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/LookupI.java b/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/LookupI.java index 5e3910d4aef..ac99857d3ae 100644 --- a/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/LookupI.java +++ b/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/LookupI.java @@ -172,17 +172,78 @@ class LookupI implements Lookup public LookupI(LocatorRegistryI registry, LookupPrx lookup, com.zeroc.Ice.Properties properties) { _registry = registry; - _lookup = lookup; _timeout = properties.getPropertyAsIntWithDefault("IceDiscovery.Timeout", 300); _retryCount = properties.getPropertyAsIntWithDefault("IceDiscovery.RetryCount", 3); _latencyMultiplier = properties.getPropertyAsIntWithDefault("IceDiscovery.LatencyMultiplier", 1); _domainId = properties.getProperty("IceDiscovery.DomainId"); _timer = com.zeroc.IceInternal.Util.getInstance(lookup.ice_getCommunicator()).timer(); + + try + { + lookup.ice_getConnection(); + } + catch(com.zeroc.Ice.LocalException ex) + { + StringBuilder b = new StringBuilder(); + b.append("IceDiscovery is unable to establish a multicast connection:\n"); + b.append("proxy = "); + b.append(lookup.toString()); + b.append('\n'); + b.append(ex.toString()); + throw new com.zeroc.Ice.PluginInitializationException(b.toString()); + } + + // + // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast + // datagram on each endpoint. + // + com.zeroc.Ice.Endpoint[] single = new com.zeroc.Ice.Endpoint[1]; + for(com.zeroc.Ice.Endpoint endpt : lookup.ice_getEndpoints()) + { + try + { + single[0] = endpt; + LookupPrx l = (LookupPrx)lookup.ice_endpoints(single); + l.ice_getConnection(); + _lookup.put(l, null); + } + catch(com.zeroc.Ice.LocalException ex) + { + } + } + assert(!_lookup.isEmpty()); } void setLookupReply(LookupReplyPrx lookupReply) { - _lookupReply = lookupReply; + // + // Use a lookup reply proxy whose adress matches the interface used to send multicast datagrams. + // + com.zeroc.Ice.Endpoint[] single = new com.zeroc.Ice.Endpoint[1]; + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + com.zeroc.Ice.UDPEndpointInfo info = + (com.zeroc.Ice.UDPEndpointInfo)entry.getKey().ice_getEndpoints()[0].getInfo(); + if(!info.mcastInterface.isEmpty()) + { + for(com.zeroc.Ice.Endpoint q : lookupReply.ice_getEndpoints()) + { + com.zeroc.Ice.EndpointInfo r = q.getInfo(); + if(r instanceof com.zeroc.Ice.IPEndpointInfo && + ((com.zeroc.Ice.IPEndpointInfo)r).host.equals(info.mcastInterface)) + { + single[0] = q; + entry.setValue((LookupReplyPrx)lookupReply.ice_endpoints(single)); + } + } + } + + if(entry.getValue() == null) + { + // Fallback: just use the given lookup reply proxy if no matching endpoint found. + entry.setValue(lookupReply); + } + } } @Override @@ -250,7 +311,10 @@ class LookupI implements Lookup { try { - _lookup.findObjectByIdAsync(_domainId, id, _lookupReply); + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findObjectByIdAsync(_domainId, id, entry.getValue()); + } request.scheduleTimer(_timeout); } catch(com.zeroc.Ice.LocalException ex) @@ -274,7 +338,10 @@ class LookupI implements Lookup { try { - _lookup.findAdapterByIdAsync(_domainId, adapterId, _lookupReply); + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findAdapterByIdAsync(_domainId, adapterId, entry.getValue()); + } request.scheduleTimer(_timeout); } catch(com.zeroc.Ice.LocalException ex) @@ -325,7 +392,10 @@ class LookupI implements Lookup { try { - _lookup.findObjectByIdAsync(_domainId, request.getId(), _lookupReply); + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findObjectByIdAsync(_domainId, request.getId(), entry.getValue()); + } request.scheduleTimer(_timeout); return; } @@ -350,7 +420,10 @@ class LookupI implements Lookup { try { - _lookup.findAdapterByIdAsync(_domainId, request.getId(), _lookupReply); + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findAdapterByIdAsync(_domainId, request.getId(), entry.getValue()); + } request.scheduleTimer(_timeout); return; } @@ -364,8 +437,7 @@ class LookupI implements Lookup } private LocatorRegistryI _registry; - private final LookupPrx _lookup; - private LookupReplyPrx _lookupReply; + private java.util.Map<LookupPrx, LookupReplyPrx> _lookup = new java.util.HashMap<>(); private final int _timeout; private final int _retryCount; private final int _latencyMultiplier; diff --git a/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/PluginI.java b/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/PluginI.java index 9b52edf963b..46bed9f0ee8 100644 --- a/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/PluginI.java +++ b/java/src/IceDiscovery/src/main/java/com/zeroc/IceDiscovery/PluginI.java @@ -9,6 +9,8 @@ package com.zeroc.IceDiscovery; +import com.zeroc.IceInternal.Network; + public class PluginI implements com.zeroc.Ice.Plugin { public PluginI(com.zeroc.Ice.Communicator communicator) @@ -45,16 +47,28 @@ public class PluginI implements com.zeroc.Ice.Plugin } properties.setProperty("IceDiscovery.Multicast.Endpoints", s.toString()); } - if(properties.getProperty("IceDiscovery.Reply.Endpoints").isEmpty()) + + String lookupEndpoints = properties.getProperty("IceDiscovery.Lookup"); + if(lookupEndpoints.isEmpty()) { - StringBuilder s = new StringBuilder(); - s.append("udp"); - if(!intf.isEmpty()) + int protocol = ipv4 && !preferIPv6 ? Network.EnableIPv4 : Network.EnableIPv6; + java.util.List<String> interfaces = Network.getInterfacesForMulticast(intf, protocol); + for(String p : interfaces) { - s.append(" -h \"").append(intf).append("\""); + if(p != interfaces.get(0)) + { + lookupEndpoints += ":"; + } + lookupEndpoints += "udp -h \"" + address + "\" -p " + port + " --interface \"" + p + "\""; } - properties.setProperty("IceDiscovery.Reply.Endpoints", s.toString()); } + + if(properties.getProperty("IceDiscovery.Reply.Endpoints").isEmpty()) + { + properties.setProperty("IceDiscovery.Reply.Endpoints", + "udp -h " + (intf.isEmpty() ? "*" : "\"" + intf + "\"")); + } + if(properties.getProperty("IceDiscovery.Locator.Endpoints").isEmpty()) { properties.setProperty("IceDiscovery.Locator.AdapterId", java.util.UUID.randomUUID().toString()); @@ -71,34 +85,8 @@ public class PluginI implements com.zeroc.Ice.Plugin com.zeroc.Ice.LocatorRegistryPrx locatorRegistryPrx = com.zeroc.Ice.LocatorRegistryPrx.uncheckedCast( _locatorAdapter.addWithUUID(locatorRegistry)); - String lookupEndpoints = properties.getProperty("IceDiscovery.Lookup"); - if(lookupEndpoints.isEmpty()) - { - StringBuilder s = new StringBuilder(); - s.append("udp -h \"").append(address).append("\" -p ").append(port); - if(!intf.isEmpty()) - { - s.append(" --interface \"").append(intf).append("\""); - } - lookupEndpoints = s.toString(); - } - com.zeroc.Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); // No collocation optimization for the multicast proxy! - try - { - lookupPrx.ice_getConnection(); - } - catch(com.zeroc.Ice.LocalException ex) - { - StringBuilder b = new StringBuilder(); - b.append("IceDiscovery is unable to establish a multicast connection:\n"); - b.append("proxy = "); - b.append(lookupPrx.toString()); - b.append('\n'); - b.append(ex.toString()); - throw new com.zeroc.Ice.PluginInitializationException(b.toString()); - } // // Add lookup and lookup reply Ice objects diff --git a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/SessionKeeper.java b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/SessionKeeper.java index a12122ea4cf..9aeb8315872 100644 --- a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/SessionKeeper.java +++ b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/SessionKeeper.java @@ -62,9 +62,8 @@ import javax.naming.ldap.Rdn; import java.net.NetworkInterface; import java.net.InetAddress; -import com.zeroc.IceLocatorDiscovery.LookupPrx; -import com.zeroc.IceLocatorDiscovery.LookupReplyPrx; -import com.zeroc.IceLocatorDiscovery.LookupReply; +import com.zeroc.IceLocatorDiscovery.Plugin; +import com.zeroc.IceLocatorDiscovery.PluginFactory; import com.zeroc.IceGrid.*; @@ -1075,175 +1074,67 @@ public class SessionKeeper _nextButton.requestFocusInWindow(); } - public void destroyDiscoveryAdapter() - { - synchronized(SessionKeeper.this) - { - if(_discoveryAdapter != null) - { - SwingUtilities.invokeLater(() -> - { - if(_directDiscoveryEndpointModel.size() > 0) - { - _discoveryStatus.setText(""); - } - else - { - _discoveryStatus.setText("No registries found"); - } - }); - _discoveryAdapter.destroy(); - _discoveryAdapter = null; - } - } - } - - public void refreshDiscoveryEndpoints() + public void refreshDiscoveryLocators() { final com.zeroc.Ice.Communicator communicator = _coordinator.getCommunicator(); - if(_discoveryLookupReply == null) - { - _discoveryLookupReply = new LookupReply() - { - @Override - public void foundLocator(final com.zeroc.Ice.LocatorPrx locator, com.zeroc.Ice.Current curr) - { - SwingUtilities.invokeLater(() -> - { - if(_directDiscoveryEndpointModel.indexOf(locator) == -1) - { - _directDiscoveryEndpointModel.addElement(locator); - } - - if(_directDiscoveryEndpointModel.size() > 0 && - _directDiscoveryEndpointList.getSelectedIndex() == -1) - { - _directDiscoveryEndpointList.setSelectedIndex(0); - } - }); - } - }; - } - _discoveryStatus.setText("Searching for registries..."); - - // - // If there isn't any search in progress clear the endpoint list. - // - synchronized(SessionKeeper.this) - { - if(_discoveryAdapter == null) - { - _directDiscoveryEndpointModel.clear(); - } - } - - final com.zeroc.Ice.Properties properties = communicator.getProperties(); - final String intf = _discoveryInterfaces.getSelectedItem().toString(); - - String lookupEndpoints = properties.getProperty("IceGridAdmin.Discovery.Lookup"); - String address; - if(properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0 && - properties.getPropertyAsInt("Ice.PreferIPv6Address") <= 0) - { - address = "239.255.0.1"; - } - else - { - address = "ff15::1"; - } - if(lookupEndpoints.isEmpty()) - { - StringBuilder s = new StringBuilder(); - s.append("udp -h \""); - s.append(properties.getPropertyWithDefault("IceGridAdmin.Discovery.Address", address)); - s.append("\" -p "); - s.append(4061); - if(!intf.isEmpty()) - { - s.append(" --interface \"").append(intf).append("\""); - } - lookupEndpoints = s.toString(); - } - try { - final LookupPrx lookupPrx = LookupPrx.uncheckedCast( - communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + - lookupEndpoints).ice_collocationOptimized(false).ice_router(null)); - new Thread(() -> { synchronized(SessionKeeper.this) { - // - // If search is in progress when refresh is hit, cancel the - // finish task we will schedule a new one with this new - // search. - // - if(_discoveryFinishTask != null) - { - _discoveryFinishTask.cancel(); - } - - if(properties.getProperty("IceGridAdmin.Discovery.Reply.Endpoints").isEmpty()) + try { - StringBuilder s = new StringBuilder(); - s.append("udp"); - if(!intf.isEmpty()) + if(_discoveryPlugin == null) { - s.append(" -h \"").append(intf).append("\""); + PluginFactory f = new PluginFactory(); + _discoveryPlugin = (Plugin)f.create(communicator, "IceGridAdmin.Discovery", null); + _discoveryPlugin.initialize(); } - properties.setProperty("IceGridAdmin.Discovery.Reply.Endpoints", s.toString()); - } - try - { - if(_discoveryAdapter == null) + final List<com.zeroc.Ice.LocatorPrx> locators = _discoveryPlugin.getLocators("", 1000); + SwingUtilities.invokeLater(() -> { - _discoveryAdapter = communicator.createObjectAdapter( - "IceGridAdmin.Discovery.Reply"); - _discoveryAdapter.activate(); - _discoveryReplyPrx = LookupReplyPrx.uncheckedCast( - _discoveryAdapter.addWithUUID(_discoveryLookupReply).ice_datagram()); - } + _directDiscoveryLocatorModel.clear(); + for(com.zeroc.Ice.LocatorPrx locator : locators) + { + _directDiscoveryLocatorModel.addElement(locator); + } + if(_directDiscoveryLocatorModel.size() > 0 && + _directDiscoveryLocatorList.getSelectedIndex() == -1) + { + _directDiscoveryLocatorList.setSelectedIndex(0); + } - lookupPrx.findLocator("", _discoveryReplyPrx); + if(_directDiscoveryLocatorModel.size() > 0) + { + _discoveryStatus.setText(""); + } + else + { + _discoveryStatus.setText("No registries found"); + } + }); } catch(final com.zeroc.Ice.LocalException ex) { - ex.printStackTrace(); - destroyDiscoveryAdapter(); SwingUtilities.invokeLater(() -> { + _discoveryStatus.setText("No registries found"); JOptionPane.showMessageDialog(ConnectionWizardDialog.this, ex.toString(), - "Error while looking up locator endpoints", + "Error while looking up registries", JOptionPane.ERROR_MESSAGE); }); } - - // - // We schedule a timer task to destroy the discovery adapter after 2 - // seconds, the user doesn't need to wait, discovered proxies are - // added as they are found. - // - _discoveryFinishTask = new java.util.TimerTask() - { - @Override - public void run() - { - destroyDiscoveryAdapter(); - } - }; - new java.util.Timer().schedule(_discoveryFinishTask, 2000); } }).start(); } catch(com.zeroc.Ice.LocalException ex) { JOptionPane.showMessageDialog(ConnectionWizardDialog.this, ex.toString(), - "Error while looking up locator endpoints", JOptionPane.ERROR_MESSAGE); + "Error while looking up registries", JOptionPane.ERROR_MESSAGE); } } @@ -1298,69 +1189,11 @@ public class SessionKeeper builder.append(new JLabel("Connect to an IceGrid registry through a Glacier2 router.")); _cardPanel.add(builder.getPanel(), WizardStep.ConnectionTypeStep.toString()); } - - JPanel discoveryInterface; - { - FormLayout layout = new FormLayout("pref, 2dlu, pref:grow", "pref"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - _discoveryInterfaces = new JComboBox(); - - builder.append("Discovery Interface:", _discoveryInterfaces); - - List<String> addresses = new ArrayList<String>(); - try - { - Enumeration<NetworkInterface> p = NetworkInterface.getNetworkInterfaces(); - - while(p != null && p.hasMoreElements()) - { - NetworkInterface intf = p.nextElement(); - if(intf.isUp()) - { - Enumeration<InetAddress> q = intf.getInetAddresses(); - while(q != null && q.hasMoreElements()) - { - InetAddress address = q.nextElement(); - if(!address.isAnyLocalAddress()) - { - addresses.add(address.getHostAddress()); - } - } - } - } - } - catch(java.net.SocketException ex) - { - JOptionPane.showMessageDialog(ConnectionWizardDialog.this, - ex.toString(), - "Error retrieving network interfaces", - JOptionPane.ERROR_MESSAGE); - } - - final com.zeroc.Ice.Properties properties = _coordinator.getCommunicator().getProperties(); - String selected = properties.getPropertyWithDefault("IceGridAdmin.Discovery.Interface", "127.0.0.1"); - if(!addresses.contains(selected)) - { - addresses.add(selected); - } - - _discoveryInterfaces.setModel(new DefaultComboBoxModel(addresses.toArray())); - _discoveryInterfaces.setSelectedItem(selected); - _discoveryInterfaces.addActionListener(new ActionListener () - { - @Override - public void actionPerformed(ActionEvent e) - { - refreshDiscoveryEndpoints(); - } - }); - discoveryInterface = builder.getPanel(); - } - // Direct Discovery Endpoint List + // Direct Discovery Locator List { - _directDiscoveryEndpointModel = new DefaultListModel<>(); - _directDiscoveryEndpointList = new JList(_directDiscoveryEndpointModel) + _directDiscoveryLocatorModel = new DefaultListModel<>(); + _directDiscoveryLocatorList = new JList(_directDiscoveryLocatorModel) { @Override public String getToolTipText(MouseEvent evt) @@ -1378,9 +1211,9 @@ public class SessionKeeper return null; } }; - _directDiscoveryEndpointList.setVisibleRowCount(7); - _directDiscoveryEndpointList.setFixedCellWidth(500); - _directDiscoveryEndpointList.addMouseListener( + _directDiscoveryLocatorList.setVisibleRowCount(7); + _directDiscoveryLocatorList.setFixedCellWidth(500); + _directDiscoveryLocatorList.addMouseListener( new MouseAdapter() { @Override @@ -1388,8 +1221,8 @@ public class SessionKeeper { if(e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { - Object obj = _directDiscoveryEndpointModel.getElementAt( - _directDiscoveryEndpointList.locationToIndex(e.getPoint())); + Object obj = _directDiscoveryLocatorModel.getElementAt( + _directDiscoveryLocatorList.locationToIndex(e.getPoint())); if(obj != null && obj instanceof com.zeroc.Ice.LocatorPrx) { _nextButton.doClick(0); @@ -1397,9 +1230,9 @@ public class SessionKeeper } } }); - - _directDiscoveryEndpointList.addListSelectionListener(new ListSelectionListener() + + _directDiscoveryLocatorList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) @@ -1409,20 +1242,20 @@ public class SessionKeeper }); ButtonGroup group = new ButtonGroup(); - _directDiscoveryDiscoveredEndpoint = new JRadioButton(new AbstractAction("Discovered Endpoints") + _directDiscoveryDiscoveredLocators = new JRadioButton(new AbstractAction("Discovered Registries") { @Override public void actionPerformed(ActionEvent e) { - _directDiscoveryEndpointList.setEnabled(true); + _directDiscoveryLocatorList.setEnabled(true); _discoveryStatus.setEnabled(true); _discoveryRefresh.setEnabled(true); validatePanel(); - refreshDiscoveryEndpoints(); + refreshDiscoveryLocators(); } }); - _directDiscoveryDiscoveredEndpoint.setSelected(true); - group.add(_directDiscoveryDiscoveredEndpoint); + _directDiscoveryDiscoveredLocators.setSelected(true); + group.add(_directDiscoveryDiscoveredLocators); JPanel discoveryStatus; { @@ -1435,7 +1268,7 @@ public class SessionKeeper @Override public void actionPerformed(ActionEvent e) { - refreshDiscoveryEndpoints(); + refreshDiscoveryLocators(); } }); @@ -1449,8 +1282,7 @@ public class SessionKeeper @Override public void actionPerformed(ActionEvent e) { - destroyDiscoveryAdapter(); - _directDiscoveryEndpointList.setEnabled(false); + _directDiscoveryLocatorList.setEnabled(false); _discoveryStatus.setEnabled(false); _discoveryRefresh.setEnabled(false); validatePanel(); @@ -1463,9 +1295,8 @@ public class SessionKeeper DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.border(Borders.DIALOG); builder.rowGroupingEnabled(false); - builder.append(_directDiscoveryDiscoveredEndpoint); - builder.append(discoveryInterface); - builder.append(createStrippedScrollPane(_directDiscoveryEndpointList)); + builder.append(_directDiscoveryDiscoveredLocators); + builder.append(createStrippedScrollPane(_directDiscoveryLocatorList)); builder.append(discoveryStatus); builder.append(_directDiscoveryManualEndpoint); _cardPanel.add(builder.getPanel(), WizardStep.DirectDiscoveryChooseStep.toString()); @@ -2170,9 +2001,9 @@ public class SessionKeeper { _cardLayout.show(_cardPanel, WizardStep.DirectDiscoveryChooseStep.toString()); _wizardSteps.push(WizardStep.DirectDiscoveryChooseStep); - if(_directDiscoveryDiscoveredEndpoint.isSelected()) + if(_directDiscoveryDiscoveredLocators.isSelected()) { - refreshDiscoveryEndpoints(); + refreshDiscoveryLocators(); } break; } @@ -2186,9 +2017,9 @@ public class SessionKeeper } else { - com.zeroc.Ice.LocatorPrx locator = _directDiscoveryEndpointList.getSelectedValue(); + com.zeroc.Ice.LocatorPrx locator = _directDiscoveryLocatorList.getSelectedValue(); _directInstanceName.setText(locator.ice_getIdentity().category); - + String endpoints = null; for(com.zeroc.Ice.Endpoint endpoint : locator.ice_getEndpoints()) { @@ -2496,7 +2327,8 @@ public class SessionKeeper @Override public void actionPerformed(ActionEvent e) { - destroyDiscoveryAdapter(); + _discoveryPlugin.destroy(); + _discoveryPlugin = null; ConnectionInfo inf = getConfiguration(); if(inf == null) @@ -2670,7 +2502,8 @@ public class SessionKeeper @Override public void actionPerformed(ActionEvent e) { - destroyDiscoveryAdapter(); + _discoveryPlugin.destroy(); + _discoveryPlugin = null; dispose(); } }; @@ -2707,7 +2540,7 @@ public class SessionKeeper } else { - _directDiscoveryEndpointList.requestFocusInWindow(); + _directDiscoveryLocatorList.requestFocusInWindow(); } break; } @@ -2851,7 +2684,7 @@ public class SessionKeeper } else { - validated = _directDiscoveryEndpointList.getSelectedValue() != null; + validated = _directDiscoveryLocatorList.getSelectedValue() != null; } break; } @@ -3247,17 +3080,13 @@ public class SessionKeeper private JCheckBox _directConnectToMaster; // Direct Discovery Endpoints - private JComboBox _discoveryInterfaces; - private JList<com.zeroc.Ice.LocatorPrx> _directDiscoveryEndpointList; - private DefaultListModel<com.zeroc.Ice.LocatorPrx> _directDiscoveryEndpointModel; - private JRadioButton _directDiscoveryDiscoveredEndpoint; + private JList<com.zeroc.Ice.LocatorPrx> _directDiscoveryLocatorList; + private DefaultListModel<com.zeroc.Ice.LocatorPrx> _directDiscoveryLocatorModel; + private JRadioButton _directDiscoveryDiscoveredLocators; private JLabel _discoveryStatus; private JButton _discoveryRefresh; - private java.util.TimerTask _discoveryFinishTask; - private com.zeroc.Ice.ObjectAdapter _discoveryAdapter; - private LookupReplyPrx _discoveryReplyPrx; - private LookupReply _discoveryLookupReply; + private Plugin _discoveryPlugin; private JRadioButton _directDiscoveryManualEndpoint; // Direct Endpoints panel components diff --git a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/Plugin.java b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/Plugin.java new file mode 100644 index 00000000000..b050046aab7 --- /dev/null +++ b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/Plugin.java @@ -0,0 +1,17 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package com.zeroc.IceLocatorDiscovery; + +import java.util.List; + +public interface Plugin extends com.zeroc.Ice.Plugin +{ + List<com.zeroc.Ice.LocatorPrx> getLocators(String instanceName, int waitTime); +} diff --git a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginFactory.java b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginFactory.java index 6c6b82f4fac..cec8ddf78b3 100644 --- a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginFactory.java +++ b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginFactory.java @@ -14,6 +14,6 @@ public class PluginFactory implements com.zeroc.Ice.PluginFactory @Override public com.zeroc.Ice.Plugin create(com.zeroc.Ice.Communicator communicator, String name, String[] args) { - return new PluginI(communicator); + return new PluginI(name, communicator); } } diff --git a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java index 5cdf0d781ff..3a50fd6c79b 100644 --- a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java +++ b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java @@ -9,13 +9,16 @@ package com.zeroc.IceLocatorDiscovery; +import com.zeroc.IceInternal.Network; import java.util.List; import java.util.Arrays; import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -class PluginI implements com.zeroc.Ice.Plugin +class PluginI implements Plugin { private static class Request { @@ -135,24 +138,85 @@ class PluginI implements com.zeroc.Ice.Plugin private static class LocatorI implements com.zeroc.Ice.BlobjectAsync { - LocatorI(LookupPrx lookup, com.zeroc.Ice.Properties properties, String instanceName, + LocatorI(String name, LookupPrx lookup, com.zeroc.Ice.Properties properties, String instanceName, com.zeroc.Ice.LocatorPrx voidLocator) { - _lookup = lookup; - _timeout = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.Timeout", 300); - _retryCount = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.RetryCount", 3); - _retryDelay = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.RetryDelay", 2000); + _timeout = properties.getPropertyAsIntWithDefault(name + ".Timeout", 300); + _retryCount = properties.getPropertyAsIntWithDefault(name + ".RetryCount", 3); + _retryDelay = properties.getPropertyAsIntWithDefault(name + ".RetryDelay", 2000); _timer = com.zeroc.IceInternal.Util.getInstance(lookup.ice_getCommunicator()).timer(); _instanceName = instanceName; _warned = false; _locator = lookup.ice_getCommunicator().getDefaultLocator(); _voidLocator = voidLocator; _pendingRetryCount = 0; + + try + { + lookup.ice_getConnection(); + } + catch(com.zeroc.Ice.LocalException ex) + { + StringBuilder b = new StringBuilder(); + b.append("IceDiscovery is unable to establish a multicast connection:\n"); + b.append("proxy = "); + b.append(lookup.toString()); + b.append('\n'); + b.append(ex.toString()); + throw new com.zeroc.Ice.PluginInitializationException(b.toString()); + } + + // + // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast + // datagram on each endpoint. + // + com.zeroc.Ice.Endpoint[] single = new com.zeroc.Ice.Endpoint[1]; + for(com.zeroc.Ice.Endpoint endpt : lookup.ice_getEndpoints()) + { + try + { + single[0] = endpt; + LookupPrx l = (LookupPrx)lookup.ice_endpoints(single); + l.ice_getConnection(); + _lookup.put(l, null); + } + catch(com.zeroc.Ice.LocalException ex) + { + } + } + assert(!_lookup.isEmpty()); } public void setLookupReply(LookupReplyPrx lookupReply) { - _lookupReply = lookupReply; + // + // Use a lookup reply proxy whose adress matches the interface used to send multicast datagrams. + // + com.zeroc.Ice.Endpoint[] single = new com.zeroc.Ice.Endpoint[1]; + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + com.zeroc.Ice.UDPEndpointInfo info = + (com.zeroc.Ice.UDPEndpointInfo)entry.getKey().ice_getEndpoints()[0].getInfo(); + if(!info.mcastInterface.isEmpty()) + { + for(com.zeroc.Ice.Endpoint q : lookupReply.ice_getEndpoints()) + { + com.zeroc.Ice.EndpointInfo r = q.getInfo(); + if(r instanceof com.zeroc.Ice.IPEndpointInfo && + ((com.zeroc.Ice.IPEndpointInfo)r).host.equals(info.mcastInterface)) + { + single[0] = q; + entry.setValue((LookupReplyPrx)lookupReply.ice_endpoints(single)); + } + } + } + + if(entry.getValue() == null) + { + // Fallback: just use the given lookup reply proxy if no matching endpoint found. + entry.setValue(lookupReply); + } + } } @Override @@ -164,6 +228,56 @@ class PluginI implements com.zeroc.Ice.Plugin return f; } + public List<com.zeroc.Ice.LocatorPrx> + getLocators(String instanceName, int waitTime) + { + // + // Clear locators from previous search. + // + synchronized(this) + { + _locators.clear(); + } + + // + // Find a locator + // + invoke(null, null); + + // + // Wait for responses + // + try + { + if(instanceName.isEmpty()) + { + Thread.sleep(waitTime); + } + else + { + synchronized(this) + { + while(!_locators.containsKey(instanceName) && _pendingRetryCount > 0) + { + wait(waitTime); + } + } + } + } + catch(java.lang.InterruptedException ex) + { + throw new com.zeroc.Ice.OperationInterruptedException(); + } + + // + // Return found locators + // + synchronized(this) + { + return new ArrayList<>(_locators.values()); + } + } + public synchronized void foundLocator(com.zeroc.Ice.LocatorPrx locator) { if(locator == null || @@ -176,7 +290,8 @@ class PluginI implements com.zeroc.Ice.Plugin // 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(!_pendingRequests.isEmpty() && + _locator != null && !locator.ice_getIdentity().category.equals(_locator.ice_getIdentity().category)) { if(!_warned) { @@ -201,14 +316,15 @@ class PluginI implements com.zeroc.Ice.Plugin _pendingRetryCount = 0; } - if(_locator != null) + com.zeroc.Ice.LocatorPrx l = + _pendingRequests.isEmpty() ? _locators.get(locator.ice_getIdentity().category) : _locator; + if(l != null) { // // We found another locator replica, append its endpoints to the // current locator proxy endpoints. // - List<com.zeroc.Ice.Endpoint> newEndpoints = new ArrayList<>( - Arrays.asList(_locator.ice_getEndpoints())); + List<com.zeroc.Ice.Endpoint> newEndpoints = new ArrayList<>(Arrays.asList(l.ice_getEndpoints())); for(com.zeroc.Ice.Endpoint p : locator.ice_getEndpoints()) { // @@ -229,50 +345,72 @@ class PluginI implements com.zeroc.Ice.Plugin } } - _locator = (com.zeroc.Ice.LocatorPrx)_locator.ice_endpoints( + l = (com.zeroc.Ice.LocatorPrx)l.ice_endpoints( newEndpoints.toArray(new com.zeroc.Ice.Endpoint[newEndpoints.size()])); } else { - _locator = locator; + l = locator; + } + + if(_pendingRequests.isEmpty()) + { + _locators.put(locator.ice_getIdentity().category, l); + notify(); + } + else + { + _locator = l; if(_instanceName.isEmpty()) { _instanceName = _locator.ice_getIdentity().category; // Stick to the first locator } - } - // - // Send pending requests if any. - // - for(Request req : _pendingRequests) - { - req.invoke(_locator); + // + // Send pending requests if any. + // + for(Request req : _pendingRequests) + { + req.invoke(_locator); + } + _pendingRequests.clear(); } - _pendingRequests.clear(); } public synchronized void invoke(com.zeroc.Ice.LocatorPrx locator, Request request) { if(_locator != null && _locator != locator) { - request.invoke(_locator); + if(request != null) + { + request.invoke(_locator); + } } else if(com.zeroc.IceInternal.Time.currentMonotonicTimeMillis() < _nextRetry) { - request.invoke(_voidLocator); // Don't retry to find a locator before the retry delay expires + if(request != null) + { + request.invoke(_voidLocator); // Don't retry to find a locator before the retry delay expires + } } else { _locator = null; - _pendingRequests.add(request); + if(request != null) + { + _pendingRequests.add(request); + } if(_pendingRetryCount == 0) // No request in progress { _pendingRetryCount = _retryCount; try { - _lookup.findLocatorAsync(_instanceName, _lookupReply); // Send multicast request. + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findLocatorAsync(_instanceName, entry.getValue()); // Send multicast request. + } _future = _timer.schedule(_retryTask, _timeout, java.util.concurrent.TimeUnit.MILLISECONDS); } catch(com.zeroc.Ice.LocalException ex) @@ -299,7 +437,10 @@ class PluginI implements com.zeroc.Ice.Plugin { try { - _lookup.findLocatorAsync(_instanceName, _lookupReply); // Send multicast request. + for(Map.Entry<LookupPrx, LookupReplyPrx> entry : _lookup.entrySet()) + { + entry.getKey().findLocatorAsync(_instanceName, entry.getValue()); // Send multicast request + } _future = _timer.schedule(_retryTask, _timeout, java.util.concurrent.TimeUnit.MILLISECONDS); return; } @@ -320,7 +461,7 @@ class PluginI implements com.zeroc.Ice.Plugin } }; - private final LookupPrx _lookup; + private final Map<LookupPrx, LookupReplyPrx> _lookup = new java.util.HashMap<>(); private final int _timeout; private java.util.concurrent.Future<?> _future; private final java.util.concurrent.ScheduledExecutorService _timer; @@ -329,9 +470,9 @@ class PluginI implements com.zeroc.Ice.Plugin private String _instanceName; private boolean _warned; - private LookupReplyPrx _lookupReply; private com.zeroc.Ice.LocatorPrx _locator; private com.zeroc.Ice.LocatorPrx _voidLocator; + private Map<String, com.zeroc.Ice.LocatorPrx> _locators = new HashMap<>(); private int _pendingRetryCount; private List<Request> _pendingRequests = new ArrayList<>(); @@ -354,8 +495,9 @@ class PluginI implements com.zeroc.Ice.Plugin private final LocatorI _locator; } - public PluginI(com.zeroc.Ice.Communicator communicator) + public PluginI(String name, com.zeroc.Ice.Communicator communicator) { + _name = name; _communicator = communicator; } @@ -369,76 +511,63 @@ class PluginI implements com.zeroc.Ice.Plugin String address; if(ipv4 && !preferIPv6) { - address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "239.255.0.1"); + address = properties.getPropertyWithDefault(_name + ".Address", "239.255.0.1"); } else { - address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "ff15::1"); + address = properties.getPropertyWithDefault(_name + ".Address", "ff15::1"); } - int port = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.Port", 4061); - String intf = properties.getProperty("IceLocatorDiscovery.Interface"); + int port = properties.getPropertyAsIntWithDefault(_name + ".Port", 4061); + String intf = properties.getProperty(_name + ".Interface"); - if(properties.getProperty("IceLocatorDiscovery.Reply.Endpoints").isEmpty()) + String lookupEndpoints = properties.getProperty(_name + ".Lookup"); + if(lookupEndpoints.isEmpty()) { - StringBuilder s = new StringBuilder(); - s.append("udp"); - if(!intf.isEmpty()) + int protocol = ipv4 && !preferIPv6 ? Network.EnableIPv4 : Network.EnableIPv6; + java.util.List<String> interfaces = Network.getInterfacesForMulticast(intf, protocol); + for(String p : interfaces) { - s.append(" -h \"").append(intf).append("\""); + if(p != interfaces.get(0)) + { + lookupEndpoints += ":"; + } + lookupEndpoints += "udp -h \"" + address + "\" -p " + port + " --interface \"" + p + "\""; } - properties.setProperty("IceLocatorDiscovery.Reply.Endpoints", s.toString()); } - if(properties.getProperty("IceLocatorDiscovery.Locator.Endpoints").isEmpty()) + + if(properties.getProperty(_name + ".Reply.Endpoints").isEmpty()) + { + properties.setProperty(_name + ".Reply.Endpoints", "udp -h " + (intf.isEmpty() ? "*" : "\"" + intf + "\"")); + } + + if(properties.getProperty(_name + ".Locator.Endpoints").isEmpty()) { - properties.setProperty("IceLocatorDiscovery.Locator.AdapterId", java.util.UUID.randomUUID().toString()); + properties.setProperty(_name + ".Locator.AdapterId", java.util.UUID.randomUUID().toString()); } - _replyAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Reply"); - _locatorAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Locator"); + _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); - String lookupEndpoints = properties.getProperty("IceLocatorDiscovery.Lookup"); - if(lookupEndpoints.isEmpty()) - { - StringBuilder s = new StringBuilder(); - s.append("udp -h \"").append(address).append("\" -p ").append(port); - if(!intf.isEmpty()) - { - s.append(" --interface \"").append(intf).append("\""); - } - lookupEndpoints = s.toString(); - } - com.zeroc.Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); // No collocation optimization for the multicast proxy! - try - { - lookupPrx.ice_getConnection(); // Ensure we can establish a connection to the multicast proxy - } - catch(com.zeroc.Ice.LocalException ex) - { - StringBuilder s = new StringBuilder(); - s.append("IceLocatorDiscovery is unable to establish a multicast connection:\n"); - s.append("proxy = ").append(lookupPrx.toString()).append("\n").append(ex); - throw new com.zeroc.Ice.PluginInitializationException(s.toString()); - } com.zeroc.Ice.LocatorPrx voidLoc = com.zeroc.Ice.LocatorPrx.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI())); - String instanceName = properties.getProperty("IceLocatorDiscovery.InstanceName"); + String instanceName = properties.getProperty(_name + ".InstanceName"); com.zeroc.Ice.Identity id = new com.zeroc.Ice.Identity(); id.name = "Locator"; id.category = !instanceName.isEmpty() ? instanceName : java.util.UUID.randomUUID().toString(); - LocatorI locator = new LocatorI(LookupPrx.uncheckedCast(lookupPrx), properties, instanceName, voidLoc); - _communicator.setDefaultLocator(com.zeroc.Ice.LocatorPrx.uncheckedCast(_locatorAdapter.addWithUUID(locator))); + _locator = new LocatorI(_name, LookupPrx.uncheckedCast(lookupPrx), properties, instanceName, voidLoc); + _communicator.setDefaultLocator(com.zeroc.Ice.LocatorPrx.uncheckedCast(_locatorAdapter.addWithUUID(_locator))); - com.zeroc.Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(locator)).ice_datagram(); - locator.setLookupReply(LookupReplyPrx.uncheckedCast(lookupReply)); + com.zeroc.Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(_locator)).ice_datagram(); + _locator.setLookupReply(LookupReplyPrx.uncheckedCast(lookupReply)); _replyAdapter.activate(); _locatorAdapter.activate(); @@ -451,7 +580,15 @@ class PluginI implements com.zeroc.Ice.Plugin _locatorAdapter.destroy(); } + public List<com.zeroc.Ice.LocatorPrx> + getLocators(String instanceName, int waitTime) + { + return _locator.getLocators(instanceName, waitTime); + } + + private String _name; private com.zeroc.Ice.Communicator _communicator; private com.zeroc.Ice.ObjectAdapter _locatorAdapter; private com.zeroc.Ice.ObjectAdapter _replyAdapter; + private LocatorI _locator; } |