zentol commented on a change in pull request #11586:
URL: https://github.com/apache/flink/pull/11586#discussion_r433801486



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/management/JMXServer.java
##########
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.management;
+
+import org.apache.flink.configuration.JMXServerOptions;
+import org.apache.flink.util.NetUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnectorServer;
+import javax.management.remote.rmi.RMIJRMPServerImpl;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.net.MalformedURLException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicReference;
+
+
+/**
+ * JMX Server implementation that JMX clients can connect to.
+ *
+ * <p>Heavily based on j256 simplejmx project
+ *
+ * 
<p>https://github.com/j256/simplejmx/blob/master/src/main/java/com/j256/simplejmx/server/JmxServer.java
+ */
+public class JMXServer {
+       private static final Logger LOG = 
LoggerFactory.getLogger(JMXServer.class);
+
+       private static JMXServer instance = null;
+
+       private final AtomicReference<Remote> rmiServerReference = new 
AtomicReference<>();
+
+       private Registry rmiRegistry;
+       private JMXConnectorServer connector;
+       private int port;
+
+       /**
+        * Construct a new JMV-wide JMX server or acquire existing JMX server.
+        *
+        * <p>If JMXServer static instance is already constructed, it will not 
be
+        * reconstruct again. Instead a warning sign will be posted if the 
desired
+        * port configuration doesn't match the existing JMXServer static 
instance.
+        *
+        * @param portsConfig port configuration of the JMX server.
+        * @return JMXServer static instance.
+        */
+       public static JMXServer startInstance(String portsConfig) {
+               if (instance == null) {
+                       if 
(!portsConfig.equals(JMXServerOptions.JMX_SERVER_PORT.defaultValue())) {
+                               instance = 
startJMXServerWithPortRanges(portsConfig);
+                       } else {
+                               LOG.warn("JMX Server start failed. No explicit 
JMX port is configured.");

Review comment:
       This should not be logged as a warning (since it is completely fine to 
not have a JMXServer); probably only at debug.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to