use of java.net.InetAddress in project otter by alibaba.
the class DefaultCommunicationClientImpl method buildParams.
// ===================== helper method ==================
private CommunicationParam buildParams(String addr) {
CommunicationParam params = new CommunicationParam();
String[] strs = StringUtils.split(addr, ":");
if (strs == null || strs.length != 2) {
throw new IllegalArgumentException("addr example: 127.0.0.1:1099");
}
InetAddress address = null;
try {
address = InetAddress.getByName(strs[0]);
} catch (UnknownHostException e) {
throw new CommunicationException("addr_error", "addr[" + addr + "] is unknow!");
}
params.setIp(address.getHostAddress());
params.setPort(Integer.valueOf(strs[1]));
return params;
}
use of java.net.InetAddress in project hazelcast by hazelcast.
the class DefaultAddressPicker method pickMatchingAddress.
private AddressDefinition pickMatchingAddress(Collection<InterfaceDefinition> interfaces) throws SocketException {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
boolean preferIPv4Stack = preferIPv4Stack();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface ni = networkInterfaces.nextElement();
Enumeration<InetAddress> e = ni.getInetAddresses();
while (e.hasMoreElements()) {
InetAddress inetAddress = e.nextElement();
if (preferIPv4Stack && inetAddress instanceof Inet6Address) {
continue;
}
if (interfaces != null && !interfaces.isEmpty()) {
AddressDefinition address = match(inetAddress, interfaces);
if (address != null) {
return address;
}
} else if (!inetAddress.isLoopbackAddress()) {
return new AddressDefinition(inetAddress);
}
}
}
return null;
}
use of java.net.InetAddress in project gradle by gradle.
the class InetAddressFactory method findCommunicationAddresses.
private void findCommunicationAddresses() throws UnknownHostException {
communicationAddresses = new ArrayList<InetAddress>();
if (inetAddresses.getLoopback().isEmpty()) {
if (inetAddresses.getRemote().isEmpty()) {
InetAddress fallback = InetAddress.getByName(null);
logger.debug("No loopback addresses, using fallback {}", fallback);
communicationAddresses.add(fallback);
} else {
logger.debug("No loopback addresses, using remote addresses instead.");
communicationAddresses.addAll(inetAddresses.getRemote());
}
} else {
communicationAddresses.addAll(inetAddresses.getLoopback());
}
}
use of java.net.InetAddress in project gradle by gradle.
the class MultiChoiceAddressSerializer method write.
@Override
public void write(Encoder encoder, MultiChoiceAddress address) throws IOException {
UUID canonicalAddress = address.getCanonicalAddress();
encoder.writeLong(canonicalAddress.getMostSignificantBits());
encoder.writeLong(canonicalAddress.getLeastSignificantBits());
encoder.writeInt(address.getPort());
encoder.writeSmallInt(address.getCandidates().size());
for (InetAddress inetAddress : address.getCandidates()) {
encoder.writeBinary(inetAddress.getAddress());
}
}
use of java.net.InetAddress in project j2objc by google.
the class SocketChannelImpl method socket.
/*
* Getting the internal Socket If we have not the socket, we create a new
* one.
*/
@Override
public synchronized Socket socket() {
if (socket == null) {
try {
InetAddress addr = null;
int port = 0;
if (connectAddress != null) {
addr = connectAddress.getAddress();
port = connectAddress.getPort();
}
socket = new SocketAdapter(new PlainSocketImpl(fd, localPort, addr, port), this);
} catch (SocketException e) {
return null;
}
}
return socket;
}
Aggregations