< prev index next >

application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java

Print this page

        

@@ -33,37 +33,47 @@
 package org.openjdk.jmc.rjmx.services.internal;
 
 import javax.management.MBeanServerConnection;
 
 import org.openjdk.jmc.rjmx.ConnectionException;
+import org.openjdk.jmc.rjmx.ConnectionToolkit;
 import org.openjdk.jmc.rjmx.IConnectionHandle;
 import org.openjdk.jmc.rjmx.ServiceNotAvailableException;
 import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService;
 import org.openjdk.jmc.rjmx.services.IDiagnosticCommandService;
+import javax.management.ObjectName;
 
 public class HotSpot23CommercialFeaturesService implements ICommercialFeaturesService {
         private final static String VM_FLAG = "UnlockCommercialFeatures"; //$NON-NLS-1$
         private final static String UNLOCK_COMMAND = "VM.unlock_commercial_features"; //$NON-NLS-1$
         private final MBeanServerConnection server;
         private final IDiagnosticCommandService dcs;
+        private final static String JFR2_MBEAN_OBJECT_NAME = "jdk.management.jfr:type=FlightRecorder"; //$NON-NLS-1$
 
         public HotSpot23CommercialFeaturesService(IConnectionHandle handle)
                         throws ConnectionException, ServiceNotAvailableException {
                 server = handle.getServiceOrThrow(MBeanServerConnection.class);
                 dcs = handle.getServiceOrNull(IDiagnosticCommandService.class);
                 try {
                         HotspotManagementToolkit.getVMOption(server, VM_FLAG); // Will fail if option is not available
                 } catch (Exception e) {
+                        // Commercial Feature option is not available but Flighter Recorder is.
+                        if (!isJfrMBeanAvailable()) {
                         throw new ServiceNotAvailableException(""); //$NON-NLS-1$
                 }
         }
+        }
 
         @Override
         public boolean isCommercialFeaturesEnabled() {
                 try {
                         return ((String) HotspotManagementToolkit.getVMOption(server, VM_FLAG)).contains("true"); //$NON-NLS-1$
                 } catch (Exception e) {
+                        // Commercial Feature option is not available but Flighter Recorder is.
+                        if (isJfrMBeanAvailable()) {
+                                return true;
+                        }
                         return false;
                 }
         }
 
         @Override

@@ -73,6 +83,21 @@
                 }
                 if (!isCommercialFeaturesEnabled()) {
                         HotspotManagementToolkit.setVMOption(server, VM_FLAG, "true"); //$NON-NLS-1$
                 }
         }
+
+        private boolean isJfrMBeanAvailable() {
+                try {
+                        getJfrMBeanObjectName();
+                        return true;
+                } catch (Exception e) {
+                        return false;
+                }
+        }
+
+        private ObjectName getJfrMBeanObjectName() throws Exception {
+                ObjectName candidateObjectName = ConnectionToolkit.createObjectName(JFR2_MBEAN_OBJECT_NAME);
+                server.getMBeanInfo(candidateObjectName);
+                return candidateObjectName;
+        }
 }
< prev index next >