以编程方式从weblogic服务器获取转储

时间:2014-03-10 12:04:54

标签: java jmx jdeveloper mbeans

我有一个要求,我需要设计一个包含按钮的小应用程序。当用户点击它时,它将连接到相应的weblogic服务器并获取位于为用户下载的特定位置的MDS转储ZIP文件。我需要使用java语言以编程方式实现它,最好使用MBeans。

我是这个MBeans概念的新手。任何人都可以帮助我找出正确的MBean来获取转储文件并下载它们吗?

1 个答案:

答案 0 :(得分:0)

我已经做过类似的事情:这里是我的所有代码:

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;
}

}