class NetUtil {

	public static Optional<String> serviceName(int port) {
		if (!ValidationUtil.port(port))
			throw new IllegalArgumentException("Invalid port: " + port);

		if (!serviceResolutionEnabled)
			// Service name resolution disabled
			return Optional.empty();

		if (port >= 49152)
			// Ephemeral port range
			return Optional.empty();

		if (serviceCache.containsKey(port))
			// The service name is cached
			return Optional.of(serviceCache.get(port));

		try {
			var serviceName = serviceName0(port);
			if (serviceName != null) {
				serviceCache.put(port, serviceName);
				return Optional.of(serviceName);
			} else {
				return Optional.empty();
			}
		} catch (Exception e) {
			serviceResolutionEnabled = false;
			return Optional.empty();
		}
	}

	private  NetUtil();

}