Package com.networknt.consul
Class ConsulUtils
- java.lang.Object
-
- com.networknt.consul.ConsulUtils
-
public class ConsulUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ConsulUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConsulServicebuildService(URL url)build consul service from urlstatic URLbuildUrl(String protocol, ConsulService service)build url from servicestatic StringconvertConsulSerivceId(URL url)convert url to consul service id.static StringconvertGroupToServiceName(String group)convert group to service namestatic StringconvertServiceId(String host, int port, String path)static StringgetGroupFromServiceName(String group)get group from consul servicestatic StringgetPathFromServiceId(String serviceId)get path of url from service id in consulstatic StringgetProtocolFromTag(String tag)get protocol from consul tagstatic intgetTimeoutBufferInSecond(String timeoutBuffer)convert the string timeoutBuffer to integer seconds from the config file.static StringgetUrlClusterInfo(URL url)get cluster info from url, cluster info (protocol, path)static intgetWaitInSecond(String wait)convert the string wait to integer seconds from the config file.static booleanisSame(List<URL> urls1, List<URL> urls2)Check if two lists have the same urls.
-
-
-
Method Detail
-
isSame
public static boolean isSame(List<URL> urls1, List<URL> urls2)
Check if two lists have the same urls.- Parameters:
urls1- first url listurls2- second url list- Returns:
- boolean true when they are the same
-
buildService
public static ConsulService buildService(URL url)
build consul service from url- Parameters:
url- a URL object- Returns:
- ConsulService consul service
-
buildUrl
public static URL buildUrl(String protocol, ConsulService service)
build url from service- Parameters:
protocol- the protocol of the serviceservice- consul service- Returns:
- URL object
-
getUrlClusterInfo
public static String getUrlClusterInfo(URL url)
get cluster info from url, cluster info (protocol, path)- Parameters:
url- a URL object- Returns:
- String url cluster info
-
convertGroupToServiceName
public static String convertGroupToServiceName(String group)
convert group to service name- Parameters:
group- group- Returns:
- String service name
-
getGroupFromServiceName
public static String getGroupFromServiceName(String group)
get group from consul service- Parameters:
group- group- Returns:
- group
-
convertConsulSerivceId
public static String convertConsulSerivceId(URL url)
convert url to consul service id. serviceid includes ip+port+service- Parameters:
url- a URL object- Returns:
- service id
-
getPathFromServiceId
public static String getPathFromServiceId(String serviceId)
get path of url from service id in consul- Parameters:
serviceId- service id- Returns:
- path
-
getProtocolFromTag
public static String getProtocolFromTag(String tag)
get protocol from consul tag- Parameters:
tag- tag- Returns:
- protocol
-
getWaitInSecond
public static int getWaitInSecond(String wait)
convert the string wait to integer seconds from the config file. The possible format might be 600s or 10m etc. And the result will be 600 after the conversion.- Parameters:
wait- String format of wait from the config- Returns:
- int of the wait seconds
-
getTimeoutBufferInSecond
public static int getTimeoutBufferInSecond(String timeoutBuffer)
convert the string timeoutBuffer to integer seconds from the config file. The possible format might be 600s or 10m etc. And the result will be 600 after the conversion. Default timeoutBuffer value is 5s- Parameters:
timeoutBuffer- String format of timeoutBuffer from the config- Returns:
- int of the timeoutBuffer in seconds
-
-