0

I have a requirement where I need to design a small app which contains a button. When the user clicks on that, it will connect to corresponding weblogic server and get the MDS dump ZIP file located in particular location downloaded for the user. I need to implement this programmatically using java language and preferably using MBeans.

I am new to this MBeans concept. Can any one help me out on how to figure out the correct MBean to get access to the dump files and download them?

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
RKC
  • 1,834
  • 13
  • 13

1 Answers1

0

I have already done something like this: here all my code:

public class HeapGenerator {

private HeapGenerator() {

}

private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";
private static long lastHeapDumpGenrationTime ;
// field to store the hotspot diagnostic MBean
private static volatile HotSpotDiagnosticMXBean hotspotMBean;

public static void generateHeapDump(String fileName, boolean live) {
    // initialize hotspot diagnostic MBean
    initHotspotMBean();
    try {
        File dumpFile = new File(fileName);
        if (dumpFile.exists()) {
            dumpFile.delete();
        }
        hotspotMBean.dumpHeap(fileName, live);
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception exp) {
        throw new RuntimeException(exp);
    }
}

// initialize the hotspot diagnostic MBean field
private static void initHotspotMBean() {
    if (hotspotMBean == null) {
        synchronized (HeapDumpGenerator.class) {
            if (hotspotMBean == null) {
                hotspotMBean = getHotspotMBean();
            }
        }
    }
}

// get the hotspot diagnostic MBean from the
// platform MBean server
private static HotSpotDiagnosticMXBean getHotspotMBean() {
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME, HotSpotDiagnosticMXBean.class);
        return bean;
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception exp) {
        throw new RuntimeException(exp);
    }
}

public static String generateHeapDump() {
    String fileName = getFullHeapDumpFileName();
    generateHeapDump(fileName, true);
    return fileName;
}

}
Salah
  • 8,567
  • 3
  • 26
  • 43