use of java.net.InetAddress in project hazelcast by hazelcast.
the class InitConnectionTask method bindSocket.
private void bindSocket(SocketChannel socketChannel) throws IOException {
InetAddress inetAddress = getInetAddress();
Socket socket = socketChannel.socket();
if (connectionManager.useAnyOutboundPort()) {
SocketAddress socketAddress = new InetSocketAddress(inetAddress, 0);
socket.bind(socketAddress);
} else {
IOException ex = null;
int retryCount = connectionManager.getOutboundPortCount() * 2;
for (int i = 0; i < retryCount; i++) {
int port = connectionManager.acquireOutboundPort();
SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
try {
socket.bind(socketAddress);
return;
} catch (IOException e) {
ex = e;
logger.finest("Could not bind port[ " + port + "]: " + e.getMessage());
}
}
throw ex;
}
}
use of java.net.InetAddress in project hazelcast by hazelcast.
the class AddressUtil method findRealInet6Address.
private static Inet6Address findRealInet6Address(Inet6Address inet6Address) throws SocketException {
Inet6Address resultInetAddress = null;
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface ni = interfaces.nextElement();
Enumeration<InetAddress> addresses = ni.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (!isInet6Compatible(address, inet6Address)) {
continue;
}
if (resultInetAddress != null) {
throw new IllegalArgumentException("This address " + inet6Address + " is bound to more than one network interface!");
}
resultInetAddress = (Inet6Address) address;
}
}
return resultInetAddress;
}
use of java.net.InetAddress in project hazelcast by hazelcast.
the class DefaultAddressPickerTest method testBindAddress.
private void testBindAddress(InetAddress address) throws Exception {
addressPicker = new DefaultAddressPicker(config, properties, logger);
addressPicker.pickAddress();
int port = config.getNetworkConfig().getPort();
assertEquals(new Address(address, port), addressPicker.getBindAddress());
assertEquals(addressPicker.getBindAddress(), addressPicker.getPublicAddress());
}
use of java.net.InetAddress in project hazelcast by hazelcast.
the class DefaultAddressPickerTest method testBindAddress_withNonLoopbackAddressViaTCPMembers.
@Test
public void testBindAddress_withNonLoopbackAddressViaTCPMembers() throws Exception {
InetAddress address = findIPv4NonLoopbackInterface();
assumeNotNull(address);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).clear().addMember(address.getHostAddress());
testBindAddress(address);
}
use of java.net.InetAddress in project hazelcast by hazelcast.
the class DefaultAddressPickerTest method setup.
@Before
public void setup() throws UnknownHostException {
properties = new HazelcastProperties(config);
InetAddress publicAddress = null;
try {
loopback = InetAddress.getByName("127.0.0.1");
publicAddress = InetAddress.getByName(PUBLIC_HOST);
} catch (UnknownHostException e) {
e.printStackTrace();
}
assumeNotNull(loopback, publicAddress);
localAddressValue = System.getProperty(HAZELCAST_LOCAL_ADDRESS_PROP);
System.clearProperty(HAZELCAST_LOCAL_ADDRESS_PROP);
}
Aggregations