JMX API에 따르면 사용자 정의 후크를 사용하려면 StandardMBean 및 StandardEmitterMBean과 같은 클래스를 사용할 수 있습니다. 따라서 MXBean 자체를 직접 등록하는 대신 직접이 클래스 중 하나로 래핑 할 수 있습니다. 괜찮습니다.하지만 JMX Notification 프레임 워크를 사용하자마자 MXBean 대신이 래핑 된 클래스를 사용할 때 알림이 발생하지 않습니다. 일부 예제 코드 :JMX : 래핑 된 MXBean이 알림을 보내지 않음
MXBean의 인터페이스
public interface MyMXBean {
public void hello();
}
public class MyMXBeanImpl extends NotificationBroadcasterSupport implements MyMXBean {
@Override
public void hello() {
Notification n = //...creating new Notification
sendNotification(n);
}
}
가 Registation이 구현 : 내 빈에 JConsole을 연결하면
public class Registration() {
public static void main(String[] args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName oname =
new ObjectName("example:type=myexample,name=MyExamleMXBean");
// does not fire any notifications
mbs.registerMBean(
new StandardEmitterMBean(new MyMXBeanImpl(), MyMXBean.class, true), oname);
// would fire the notification
// mbs.register(new MyMXBeanImpl(), oname);
}
}
, 알림에 가입 메커니즘을 실행하고 hello() 메서드를 실행하면 아무 일도 일어나지 않습니다. MXBean을 직접 등록 할 때만 모든 것이 잘 동작합니다. MXBean에 사용자 정의 NotificationListeners를 추가 할 때도 작동하지 않습니다. 나는 어떻게 든 래핑 클래스에서이 Notification 이벤트를 잡아 내고 어떤 식 으로든 포워딩하려했지만이 역시 작동하지 않았다. 여기에 내가 누락 된 부분이 있습니까? 또는 래핑 클래스 중 하나를 사용할 때 작동하지 않는 것입니까?
미리 도움 주셔서 감사합니다.
답변 해 주셔서 감사합니다. Nicholas. 그것이 내가 알아 낸 것입니다. JMX가 래핑 클래스에 알림을 적용하고 래핑 된 클래스로 전달하지 않는 것 같습니다. – Sancho