co.cask.common
Class Networks

java.lang.Object
  extended by co.cask.common.Networks

public final class Networks
extends Object

Utility class to provide methods for common network related operations.


Method Summary
static int getRandomPort()
          Find a random free port in localhost for binding.
static String normalizeWebappDiscoveryName(String name)
          Normalizes the name by doing the following: Remove trailing slashes. Remove :80 from end of the host part if any. Replace '.', ':', '/' and '-' with '_'. URL encode the name.
static InetAddress resolve(String hostname, InetAddress onErrorAddress)
          Resolves the given hostname into InetAddress.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resolve

public static InetAddress resolve(String hostname,
                                  InetAddress onErrorAddress)
Resolves the given hostname into InetAddress.

Parameters:
hostname - The hostname in String. If null, return localhost.
onErrorAddress - InetAddress to return if the given hostname cannot be resolved.
Returns:
An InetAddress of the resolved hostname.

getRandomPort

public static int getRandomPort()
Find a random free port in localhost for binding.

Returns:
A port number or -1 for failure.

normalizeWebappDiscoveryName

public static String normalizeWebappDiscoveryName(String name)
                                           throws UnsupportedEncodingException
Normalizes the name by doing the following:

Parameters:
name - discovery name that needs to be normalized.
Returns:
the normalized discovery name.
Throws:
UnsupportedEncodingException


Copyright © 2015 Cask Data, Inc. Licensed under the Apache License, Version 2.0.