parent
0d5f967c7f
commit
e92a9bf003
|
@ -83,6 +83,34 @@ public class Addressing {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InetAddress getIpAddress() throws SocketException {
|
public static InetAddress getIpAddress() throws SocketException {
|
||||||
|
return getIpAddress(new AddressSelectionCondition() {
|
||||||
|
@Override
|
||||||
|
public boolean isAcceptableAddress(InetAddress addr) {
|
||||||
|
return addr instanceof Inet4Address || addr instanceof Inet6Address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InetAddress getIp4Address() throws SocketException {
|
||||||
|
return getIpAddress(new AddressSelectionCondition() {
|
||||||
|
@Override
|
||||||
|
public boolean isAcceptableAddress(InetAddress addr) {
|
||||||
|
return addr instanceof Inet4Address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InetAddress getIp6Address() throws SocketException {
|
||||||
|
return getIpAddress(new AddressSelectionCondition() {
|
||||||
|
@Override
|
||||||
|
public boolean isAcceptableAddress(InetAddress addr) {
|
||||||
|
return addr instanceof Inet6Address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InetAddress getIpAddress(AddressSelectionCondition condition) throws
|
||||||
|
SocketException {
|
||||||
// Before we connect somewhere, we cannot be sure about what we'd be bound to; however,
|
// Before we connect somewhere, we cannot be sure about what we'd be bound to; however,
|
||||||
// we only connect when the message where client ID is, is long constructed. Thus,
|
// we only connect when the message where client ID is, is long constructed. Thus,
|
||||||
// just use whichever IP address we can find.
|
// just use whichever IP address we can find.
|
||||||
|
@ -94,7 +122,7 @@ public class Addressing {
|
||||||
while (addresses.hasMoreElements()) {
|
while (addresses.hasMoreElements()) {
|
||||||
InetAddress addr = addresses.nextElement();
|
InetAddress addr = addresses.nextElement();
|
||||||
if (addr.isLoopbackAddress()) continue;
|
if (addr.isLoopbackAddress()) continue;
|
||||||
if (addr instanceof Inet4Address || addr instanceof Inet6Address) {
|
if (condition.isAcceptableAddress(addr)) {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,4 +151,16 @@ public class Addressing {
|
||||||
}
|
}
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for AddressSelectionCondition to check if address is acceptable
|
||||||
|
*/
|
||||||
|
public interface AddressSelectionCondition{
|
||||||
|
/**
|
||||||
|
* Condition on which to accept inet address
|
||||||
|
* @param address to check
|
||||||
|
* @return true to accept this address
|
||||||
|
*/
|
||||||
|
public boolean isAcceptableAddress(InetAddress address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,8 +253,6 @@ public class ClusterStatusPublisher extends Chore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(Configuration conf) throws IOException {
|
public void connect(Configuration conf) throws IOException {
|
||||||
NetworkInterface ni = NetworkInterface.getByInetAddress(Addressing.getIpAddress());
|
|
||||||
|
|
||||||
String mcAddress = conf.get(HConstants.STATUS_MULTICAST_ADDRESS,
|
String mcAddress = conf.get(HConstants.STATUS_MULTICAST_ADDRESS,
|
||||||
HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS);
|
HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS);
|
||||||
int port = conf.getInt(HConstants.STATUS_MULTICAST_PORT,
|
int port = conf.getInt(HConstants.STATUS_MULTICAST_PORT,
|
||||||
|
@ -269,13 +267,19 @@ public class ClusterStatusPublisher extends Chore {
|
||||||
}
|
}
|
||||||
|
|
||||||
final InetSocketAddress isa = new InetSocketAddress(mcAddress, port);
|
final InetSocketAddress isa = new InetSocketAddress(mcAddress, port);
|
||||||
InternetProtocolFamily family = InternetProtocolFamily.IPv4;
|
|
||||||
|
InternetProtocolFamily family;
|
||||||
|
InetAddress localAddress;
|
||||||
if (ina instanceof Inet6Address) {
|
if (ina instanceof Inet6Address) {
|
||||||
|
localAddress = Addressing.getIp6Address();
|
||||||
family = InternetProtocolFamily.IPv6;
|
family = InternetProtocolFamily.IPv6;
|
||||||
|
}else{
|
||||||
|
localAddress = Addressing.getIp4Address();
|
||||||
|
family = InternetProtocolFamily.IPv4;
|
||||||
}
|
}
|
||||||
|
NetworkInterface ni = NetworkInterface.getByInetAddress(localAddress);
|
||||||
|
|
||||||
Bootstrap b = new Bootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
|
|
||||||
b.group(group)
|
b.group(group)
|
||||||
.channelFactory(new HBaseDatagramChannelFactory<Channel>(NioDatagramChannel.class, family))
|
.channelFactory(new HBaseDatagramChannelFactory<Channel>(NioDatagramChannel.class, family))
|
||||||
.option(ChannelOption.SO_REUSEADDR, true)
|
.option(ChannelOption.SO_REUSEADDR, true)
|
||||||
|
|
Loading…
Reference in New Issue