private static int getFreePort(@Nonnull InetAddress localHostAddress) throws IOException { final FreeTcpPortDetector detector = new FreeTcpPortDetector(localHostAddress, 10000, 45000); return detector.detect(); }
@Nonnull public static NetworkInterfaceQuery networkInterface() { return new NetworkInterfaceQuery(); }
@Nonnull public static NetworkInterface getLoopBackInterface() { final NetworkInterface networkInterface = networkInterfaceRepository().findOneBy(LOOP_BACK_QUERY); if (networkInterface == null) { throw new IllegalStateException("Could not find a loopBack device."); } return networkInterface; }
@Nonnull public static InetAddress getFirstAddressOf(@Nonnull NetworkInterface networkInterface) { final InetAddress address = findFirstAddressOf(networkInterface); if (address == null) { throw new IllegalArgumentException("Interface " + networkInterface.getName() + " has no address."); } return address; }
@Nullable protected HostService toHostService(@Nonnull SRVRecord record) { final InetSocketAddress address = toInetSocketAddress(record); return address != null ? new HostService(address, record.getPriority(), record.getWeight(), record.getTTL()) : null; }
@Override public long countBy(@Nonnull NetworkInterfaceQuery query) { return countElementsOf(findBy(query)); }
@Nonnull public static NetworkInterfaceRepository networkInterfaceRepository() { return getInstance(); }
protected boolean applyType(@Nonnull NetworkInterface of) { return _type == null || _type == typeOf(of); }
@Nonnull public String buildQueryFor(@Nonnull String service, @Nonnull Protocol protocol, @Nonnull String host) { return "_" + service + "._" + protocol.getName() + "." + host; }
public FreeTcpPortDetector(@Nonnull NetworkInterface networkInterface, @Nullable IntegerRange portRange) { this(getFirstAddressOf(networkInterface), portRange); }
@Nonnull public static HostService hostService(@Nonnull InetSocketAddress address, @Nonnegative int priority, @Nonnegative int weight, @Nonnegative long ttl) { return new HostService(address, priority, weight, ttl); }
public static void assertThatContainsAddress(@Nonnull NetworkInterface networkInterface, @Nonnull InetAddress address) throws IllegalArgumentException { if (!containsAddress(networkInterface, address)) { throw new IllegalArgumentException("Interface " + networkInterface.getName() + " is not bound to address " + address + "."); } }
@Nonnull public NetworkInterfaceQuery withName(@Nullable String name) { return withNameMatches(name != null ? compile(quote(name)) : null); }
@Nonnull public static HostService hostService(@Nonnull InetAddress address, @Nonnegative int port, @Nonnegative int priority, @Nonnegative int weight, @Nonnegative long ttl) { return hostService(new InetSocketAddress(address, port), priority, weight, ttl); }
@Nonnull public static NetworkInterfaceType typeOf(@Nonnull NetworkInterface what) { final String name = what.getName(); NetworkInterfaceType result = other; for (final NetworkInterfaceType current : values()) { final Pattern pattern = current._namePattern; if (pattern != null && pattern.matcher(name).matches()) { result = current; break; } } return result; }
@Nonnull public static String makeRelative(@Nonnull String url) { String result = url; if (StringUtils.isNotBlank(url)) { final String withoutScheme = removeScheme(url); final String[] splits = withoutScheme.split("/", 2); if (splits.length > 1) { result = "/" + splits[1]; } else { result = "/"; } } return result; }
private static int getFreePort(@Nonnull InetAddress localHostAddress) throws IOException { final FreeTcpPortDetector detector = new FreeTcpPortDetector(localHostAddress, 10000, 45000); return detector.detect(); }
@Nullable @Override public NetworkInterface findOneBy(@Nonnull NetworkInterfaceQuery query) { return findFirstOf(findBy(query)); }
@Nonnull protected static InetSocketAddress detectPort(@Nullable InetAddress address, @Nullable IntegerRange portRange) { final int port = new FreeTcpPortDetector(address, portRange).detect(); return new InetSocketAddress(address, port); }