paul8263 commented on a change in pull request #16108:
URL: https://github.com/apache/flink/pull/16108#discussion_r770266892



##########
File path: flink-core/src/main/java/org/apache/flink/util/NetUtils.java
##########
@@ -498,4 +503,33 @@ public static boolean isValidClientPort(int port) {
     public static boolean isValidHostPort(int port) {
         return 0 <= port && port <= 65535;
     }
+
+    /**
+     * Port wrapper class which holds a {@link FileLock} until it releases. 
Used to avoid race
+     * condition among multiple threads/processes.
+     */
+    public static class Port implements AutoCloseable {
+        private final int port;
+        private final FileLock fileLock;
+
+        public Port(int port, FileLock fileLock) throws IOException {
+            Preconditions.checkNotNull(fileLock, "FileLock should not be 
null");
+            Preconditions.checkState(fileLock.isValid(), "FileLock should be 
locked");
+            this.port = port;
+            this.fileLock = fileLock;
+        }
+
+        public int getPort() {
+            return port;
+        }
+
+        public void release() throws IOException {
+            fileLock.unlockAndDestroy();
+        }

Review comment:
       OK. I'll inline it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to