aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java')
-rw-r--r--utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java b/utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java
index a2fb5a8b..6698d7cf 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/network/NetworkUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,10 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.util.UUID;
import javax.net.ssl.TrustManager;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.net.util.TrustManagerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,7 +37,8 @@ import org.slf4j.LoggerFactory;
/**
* Network Utilities.
*/
-public class NetworkUtil {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NetworkUtil {
public static final Logger logger = LoggerFactory.getLogger(NetworkUtil.class.getName());
@@ -49,10 +53,6 @@ public class NetworkUtil {
*/
private static final TrustManager[] ALWAYS_TRUST_MANAGER = { TrustManagerUtils.getAcceptAllTrustManager() };
- private NetworkUtil() {
- // Empty constructor
- }
-
/**
* Allocates an available port on which a server may listen.
*
@@ -113,7 +113,7 @@ public class NetworkUtil {
*/
public static boolean isTcpPortOpen(String host, int port, int retries, long interval)
throws InterruptedException {
- int retry = 0;
+ var retry = 0;
while (retry < retries) {
/*
* As with the server socket, this is only used to see if the port is open,
@@ -171,4 +171,15 @@ public class NetworkUtil {
return "127.0.0.1";
}
+
+ /**
+ * Generates a globally unique name, typically for use in PDP messages, to uniquely
+ * identify a PDP (or PAP), regardless on what cluster it resides.
+ *
+ * @param prefix text to be prepended to the generated value
+ * @return a globally unique name
+ */
+ public static String genUniqueName(String prefix) {
+ return prefix + "-" + UUID.randomUUID();
+ }
}