private AddressDefinition getSystemConfiguredAddress() throws UnknownHostException { String address = config.getProperty("hazelcast.local.localAddress"); if (address != null) { address = address.trim(); if ("127.0.0.1".equals(address) || "localhost".equals(address)) { return pickLoopbackAddress(address); } else { logger.info("Picking address configured by property 'hazelcast.local.localAddress'"); return new AddressDefinition(address, InetAddress.getByName(address)); } } return null; }
private AddressDefinition getSystemConfiguredAddress() throws UnknownHostException { String address = config.getProperty("hazelcast.local.localAddress"); if (address != null) { address = address.trim(); if ("127.0.0.1".equals(address) || "localhost".equals(address)) { return pickLoopbackAddress(address); } else { logger.info("Picking address configured by property 'hazelcast.local.localAddress'"); return new AddressDefinition(address, InetAddress.getByName(address)); } } return null; }
private AddressDefinition pickAddressDef() throws UnknownHostException, SocketException { AddressDefinition addressDef = getSystemConfiguredAddress(); if (addressDef == null) { addressDef = pickInterfaceAddressDef(); } if (addressDef != null) { // check if scope ID is set correctly addressDef.inetAddress = fixScopeIdAndGetInetAddress(addressDef.inetAddress); } if (addressDef == null) { addressDef = pickLoopbackAddress(null); } return addressDef; }
private AddressDefinition pickAddressDef() throws UnknownHostException, SocketException { AddressDefinition addressDef = getSystemConfiguredAddress(); if (addressDef == null) { addressDef = pickInterfaceAddressDef(); } if (addressDef != null) { // check if scope ID is set correctly addressDef.inetAddress = fixScopeIdAndGetInetAddress(addressDef.inetAddress); } if (addressDef == null) { addressDef = pickLoopbackAddress(null); } return addressDef; }
private AddressDefinition getPublicAddress(int port) throws UnknownHostException { String address = config.getProperty("hazelcast.local.publicAddress"); if (address == null) { address = config.getNetworkConfig().getPublicAddress(); } if (address != null) { address = address.trim(); if ("127.0.0.1".equals(address) || "localhost".equals(address)) { return pickLoopbackAddress(address, port); } else { // allow port to be defined in same string in the form of <host>:<port>, e.g. 10.0.0.0:1234 AddressUtil.AddressHolder holder = AddressUtil.getAddressHolder(address, port); return new AddressDefinition(holder.getAddress(), holder.getPort(), InetAddress.getByName(holder.getAddress())); } } return null; }
private AddressDefinition getPublicAddress(int port) throws UnknownHostException { String address = config.getProperty("hazelcast.local.publicAddress"); if (address == null) { address = config.getNetworkConfig().getPublicAddress(); } if (address != null) { address = address.trim(); if ("127.0.0.1".equals(address) || "localhost".equals(address)) { return pickLoopbackAddress(address, port); } else { // allow port to be defined in same string in the form of <host>:<port>, e.g. 10.0.0.0:1234 AddressUtil.AddressHolder holder = AddressUtil.getAddressHolder(address, port); return new AddressDefinition(holder.getAddress(), holder.getPort(), InetAddress.getByName(holder.getAddress())); } } return 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); }
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); }