private static void appendMatchingInterfaces(Collection<InterfaceDefinition> interfaces, Map<String, String> address2DomainMap, String configInterface) { for (Entry<String, String> entry : address2DomainMap.entrySet()) { String address = entry.getKey(); if (AddressUtil.matchInterface(address, configInterface)) { interfaces.add(new InterfaceDefinition(entry.getValue(), address)); } } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } AddressDefinition that = (AddressDefinition) o; if (port != that.port) { return false; } if (inetAddress != null ? !inetAddress.equals(that.inetAddress) : that.inetAddress != null) { return false; } return true; }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (inetAddress != null ? inetAddress.hashCode() : 0); result = 31 * result + port; return result; } }
private List<InterfaceDefinition> getInterfaces() { NetworkConfig networkConfig = config.getNetworkConfig(); TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig(); // address -> domain Map<String, String> addressDomainMap = createAddressToDomainMap(tcpIpConfig); // must preserve insertion order List<InterfaceDefinition> interfaceDefs = new ArrayList<InterfaceDefinition>(); if (networkConfig.getInterfaces().isEnabled()) { Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces(); for (String configInterface : configInterfaces) { if (!AddressUtil.isIpAddress(configInterface)) { logger.warning("'" + configInterface + "' is not an IP address! Removing from interface list."); continue; } // add interfaces matching to members in TcpIpConfig appendMatchingInterfaces(interfaceDefs, addressDomainMap, configInterface); // add default interface definition interfaceDefs.add(new InterfaceDefinition(null, configInterface)); } logger.info("Interfaces is enabled, trying to pick one address matching to one of: " + interfaceDefs); } else if (tcpIpConfig.isEnabled()) { for (Entry<String, String> entry : addressDomainMap.entrySet()) { interfaceDefs.add(new InterfaceDefinition(entry.getValue(), entry.getKey())); } logger.info("Interfaces is disabled, trying to pick one address from TCP-IP config addresses: " + interfaceDefs); } return interfaceDefs; }
private List<InterfaceDefinition> getInterfaces() { NetworkConfig networkConfig = config.getNetworkConfig(); TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig(); // address -> domain Map<String, String> addressDomainMap = createAddressToDomainMap(tcpIpConfig); // must preserve insertion order List<InterfaceDefinition> interfaceDefs = new ArrayList<InterfaceDefinition>(); if (networkConfig.getInterfaces().isEnabled()) { Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces(); for (String configInterface : configInterfaces) { if (!AddressUtil.isIpAddress(configInterface)) { logger.warning("'" + configInterface + "' is not an IP address! Removing from interface list."); continue; } // add interfaces matching to members in TcpIpConfig appendMatchingInterfaces(interfaceDefs, addressDomainMap, configInterface); // add default interface definition interfaceDefs.add(new InterfaceDefinition(null, configInterface)); } logger.info("Interfaces is enabled, trying to pick one address matching to one of: " + interfaceDefs); } else if (tcpIpConfig.isEnabled()) { for (Entry<String, String> entry : addressDomainMap.entrySet()) { interfaceDefs.add(new InterfaceDefinition(entry.getValue(), entry.getKey())); } logger.info("Interfaces is disabled, trying to pick one address from TCP-IP config addresses: " + interfaceDefs); } return interfaceDefs; }
private AddressDefinition pickInterfaceAddressDef() throws UnknownHostException, SocketException { Collection<InterfaceDefinition> interfaces = getInterfaces(); if (interfaces.contains(new InterfaceDefinition("localhost", "127.0.0.1"))) { return pickLoopbackAddress("localhost"); } if (interfaces.contains(new InterfaceDefinition("127.0.0.1"))) { return pickLoopbackAddress(null); } logger.info("Prefer IPv4 stack is " + preferIPv4Stack() + ", prefer IPv6 addresses is " + preferIPv6Addresses()); if (interfaces.size() > 0) { AddressDefinition addressDef = pickMatchingAddress(interfaces); if (addressDef != null) { return addressDef; } } NetworkConfig networkConfig = config.getNetworkConfig(); if (networkConfig.getInterfaces().isEnabled()) { String msg = "Hazelcast CANNOT start on this node. No matching network interface found.\n" + "Interface matching must be either disabled or updated in the hazelcast.xml config file."; logger.severe(msg); throw new RuntimeException(msg); } if (networkConfig.getJoin().getTcpIpConfig().isEnabled()) { logger.warning("Could not find a matching address to start with! Picking one of non-loopback addresses."); } return pickMatchingAddress(null); }
private AddressDefinition pickInterfaceAddressDef() throws UnknownHostException, SocketException { Collection<InterfaceDefinition> interfaces = getInterfaces(); if (interfaces.contains(new InterfaceDefinition("localhost", "127.0.0.1"))) { return pickLoopbackAddress("localhost"); } if (interfaces.contains(new InterfaceDefinition("127.0.0.1"))) { return pickLoopbackAddress(null); } logger.info("Prefer IPv4 stack is " + preferIPv4Stack() + ", prefer IPv6 addresses is " + preferIPv6Addresses()); if (interfaces.size() > 0) { AddressDefinition addressDef = pickMatchingAddress(interfaces); if (addressDef != null) { return addressDef; } } NetworkConfig networkConfig = config.getNetworkConfig(); if (networkConfig.getInterfaces().isEnabled()) { String msg = "Hazelcast CANNOT start on this node. No matching network interface found.\n" + "Interface matching must be either disabled or updated in the hazelcast.xml config file."; logger.severe(msg); throw new RuntimeException(msg); } if (networkConfig.getJoin().getTcpIpConfig().isEnabled()) { logger.warning("Could not find a matching address to start with! Picking one of non-loopback addresses."); } return pickMatchingAddress(null); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } AddressDefinition that = (AddressDefinition) o; if (port != that.port) { return false; } if (inetAddress != null ? !inetAddress.equals(that.inetAddress) : that.inetAddress != null) { return false; } return true; }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (inetAddress != null ? inetAddress.hashCode() : 0); result = 31 * result + port; return result; } }
private static void appendMatchingInterfaces(Collection<InterfaceDefinition> interfaces, Map<String, String> address2DomainMap, String configInterface) { for (Entry<String, String> entry : address2DomainMap.entrySet()) { String address = entry.getKey(); if (AddressUtil.matchInterface(address, configInterface)) { interfaces.add(new InterfaceDefinition(entry.getValue(), address)); } } }