SpeedoJMXBean未暴露给JConsole

时间:2014-09-24 06:45:38

标签: java jmx

考虑以下计划:

public class SpeedoJMXBean implements SpeedoListener {
private SpeedoDTO lastData;
private SpeedoBean speedo;

@Required
public void setSpeedo(SpeedoBean speedo) {
    this.speedo = speedo;
}

public void init() throws MBeanRegistrationException, InstanceAlreadyExistsException,      NotCompliantMBeanException, MalformedObjectNameException {
    speedo.addListener(this);
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("MineStar:type=Speedometer,name=Statistics");
    MineStarMBean impl = new MineStarMBean();
    impl.addProperty(new PropertyAdapter("ThreadCount", "Thread Count", "java.lang.Integer") {
        public Object getValue() {
            return ThreadManagement.getThreadCount();
        }
    });
    impl.addProperty(new PropertyAdapter("Buffered", "Buffered Count", "java.lang.Integer") {
        public Object getValue() {
            if (lastData == null) return 0;
            return lastData.getBuffered();
        }
    });
    impl.addProperty(new PropertyAdapter("EPM", "Events Per Minute", "java.lang.Integer") {
        public Object getValue() {
            if (lastData == null) return 0;
            return lastData.getEventsPerMinute();
        }
    });
    server.registerMBean(impl, objectName);
}

@Override
public void speedoData(SpeedoDTO data) {
    lastData = data;
}

@Override
public void connectionPoolData(ConnectionPoolDTO data) {
    // not interested at the moment
}

@Override
public void gcActivity(GarbageCollectionDTO gcDTO) {
    // not interested at the moment
}
}

SpeedoBean未暴露给jconsole mbeans浏览器。我需要公开我的外部工具的Speedo信息。谁能告诉我这里的问题是什么?

注意 - 这在xml文件中初始化为 -

<bean id="speedoJMX" class="com.mincom.env.service.server.gadget.SpeedoJMXBean" init-     method="init" scope="singleton"
      lazy-init="true">
    <property name="speedo">
        <ref local="speedo"/>
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

我得到了答案。正如此链接中提到的Click Here刚刚将lazy-init更改为false。

<bean id="speedoJMX" class="com.mincom.env.service.server.gadget.SpeedoJMXBean" init-     method="init" scope="singleton"
      lazy-init="false">