1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.management.jfr.internal; 27 28 import java.util.Collections; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Set; 32 import java.util.concurrent.Callable; 33 34 import jdk.jfr.internal.management.ManagementSupport; 35 import jdk.management.jfr.FlightRecorderMXBean; 36 import jdk.management.jfr.SettingDescriptorInfo; 37 // XXX TODO 38 //import sun.management.spi.PlatformMBeanProvider; 39 40 public final class FlightRecorderMXBeanProvider /*extends PlatformMBeanProvider */{ 41 42 private final static class SingleMBeanComponent 43 /*implements PlatformComponent<FlightRecorderMXBean>*/ { 44 private final String objectName; 45 private final Class<FlightRecorderMXBean> mbeanInterface; 46 47 public SingleMBeanComponent(String objectName, 48 Class<FlightRecorderMXBean> mbeanInterface) { 49 this.objectName = objectName; 50 this.mbeanInterface = mbeanInterface; 51 } 52 53 // @Override 54 // public Set<String> mbeanInterfaceNames() { 55 // return Collections.singleton(mbeanInterface.getName()); 56 // } 57 // 58 // @Override 59 // public Map<String, FlightRecorderMXBean> nameToMBeanMap() { 60 // FlightRecorderMXBean bean = getFlightRecorderMXBean(); 61 // if (bean != null) { 62 // return Collections.singletonMap(objectName, bean); 63 // } else { 64 // return Collections.emptyMap(); 65 // } 66 // } 67 // 68 // @Override 69 // public String getObjectNamePattern() { 70 // return objectName; 71 // } 72 // 73 // @Override 74 // public Set<Class<? extends FlightRecorderMXBean>> mbeanInterfaces() { 75 // return Collections.singleton(mbeanInterface); 76 // } 77 } 78 79 private static Callable<FlightRecorderMXBean> flightRecorderMXBeanFactory; 80 81 private static volatile FlightRecorderMXBean flightRecorderMXBean; 82 83 public static FlightRecorderMXBean getFlightRecorderMXBean() { 84 FlightRecorderMXBean bean = flightRecorderMXBean; 85 if (bean == null) { 86 SettingDescriptorInfo.from(null); // Sets flightRecorderMXBeanFactory under <clinit> lock 87 synchronized (flightRecorderMXBeanFactory) { 88 bean = flightRecorderMXBean; 89 if (bean != null) { 90 return bean; 91 } 92 try { 93 bean = flightRecorderMXBean = flightRecorderMXBeanFactory.call(); 94 } catch (Exception e) { 95 ManagementSupport.logError("Could not create Flight Recorder " 96 + "instance for MBeanServer. " + e.getMessage()); 97 } 98 } 99 } 100 return bean; 101 } 102 103 public static void setFlightRecorderMXBeanFactory(Callable<FlightRecorderMXBean> factory) { 104 flightRecorderMXBeanFactory = factory; 105 } 106 107 // @Override 108 // public List<PlatformComponent<?>> getPlatformComponentList() { 109 // String objectName = FlightRecorderMXBean.MXBEAN_NAME; 110 // Class<FlightRecorderMXBean> mbeanInterface = FlightRecorderMXBean.class; 111 // return Collections.singletonList(new SingleMBeanComponent(objectName, mbeanInterface)); 112 // } 113 }