Skip to content

Commit

Permalink
Override IdGenerator Mac Address with EVENTUATE_MAC_ADDRESS
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed May 22, 2019
1 parent aa94b62 commit bfbdd7f
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@ public class IdGeneratorImpl implements IdGenerator {

public IdGeneratorImpl() {
try {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
if (iface.getHardwareAddress() != null) {
macAddress = toLong(iface.getHardwareAddress());
logger.debug("Mac address {}", macAddress);
break;
}
}
macAddress = getMacAddress();
logger.debug("Mac address {}", macAddress);
if (macAddress == null)
throw new RuntimeException("Cannot find mac address");
} catch (SocketException e) {
throw new RuntimeException(e);
}
}

private Long getMacAddress() throws SocketException {
String ma = System.getenv("EVENTUATE_MAC_ADDRESS");
if (ma != null)
return Long.parseLong(ma);
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
if (iface.getHardwareAddress() != null) {
return toLong(iface.getHardwareAddress());
}
}
return null;
}

private Long toLong(byte[] bytes) {
long result = 0L;
for (byte b : bytes) {
Expand Down

0 comments on commit bfbdd7f

Please sign in to comment.