com.transferwise.tasks.utils.ClientIdUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tw-tasks-core Show documentation
Show all versions of tw-tasks-core Show documentation
Transferwise Tasks Executor - Fire and forget until Alert.
The newest version!
package com.transferwise.tasks.utils;
import com.transferwise.common.baseutils.ExceptionUtils;
import java.net.InetAddress;
import org.apache.commons.lang3.StringUtils;
public final class ClientIdUtils {
private ClientIdUtils() {
throw new AssertionError();
}
public static String clientIdFromHostname() {
String hostName = ExceptionUtils.doUnchecked(() -> InetAddress.getLocalHost().getHostName());
String clientId = hostName.replaceAll("[^\\p{Alpha}\\p{Digit}]", "");
if (StringUtils.isEmpty(clientId)) {
throw new IllegalStateException("Could not get clientId from hostname '" + hostName + "'.");
}
return clientId;
}
}