This discussion is archived
0 Replies Latest reply: Nov 29, 2010 1:10 PM by 819590 RSS

JMX NotificationListener is never called (Weblogic 10.3)

819590 Newbie
Currently Being Moderated
Hi folks

I'm trying to register a NotificationListener which gets called when the 'HeapSizeCurrent' attribute of the JVMRuntimeMBean has changed.

I tried the following code, but the listener is never called. Any ideas?
public class Test implements NotificationListener {
  /**
   * @param args
   */
  public static void main(String[] args) throws Exception {
    NotificationListener listener = new Test();
    AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
    filter.enableAttribute("HeapSizeCurrent");

    JMXServiceURL serviceURL = new JMXServiceURL("t3", "localhost", 7011, "/jndi/weblogic.management.mbeanservers.domainruntime");
    Map<String, Object> env = new HashMap<String, Object>();
    env.put(Context.SECURITY_PRINCIPAL, "weblogic");
    env.put(Context.SECURITY_CREDENTIALS, "weblogic");
    env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
    env.put("jmx.remote.x.request.waiting.timeout", new Long(10000));

    JMXConnector connector = JMXConnectorFactory.connect(serviceURL, env);
    MBeanServerConnection connection = connector.getMBeanServerConnection();

    ObjectName domainRuntimeServiceMBean = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
    ObjectName[] serverRuntimes = (ObjectName[]) connection.getAttribute(domainRuntimeServiceMBean, "ServerRuntimes");

    for (ObjectName serverRuntime : serverRuntimes) {
      ObjectName jvmRuntime = (ObjectName) connection.getAttribute(serverRuntime, "JVMRuntime");
      connection.addNotificationListener(jvmRuntime, listener, filter, null);
      System.out.println("added listener");
    }

    System.in.read();
    connector.close();
  }

  @Override
  public void handleNotification(Notification notification, Object handback) {
    if(notification instanceof AttributeChangeNotification) {
      AttributeChangeNotification attributeChange = (AttributeChangeNotification) notification;
      System.out.println("This notification is an AttributeChangeNotification");
      System.out.println("Observed Attribute: " + attributeChange.getAttributeName() );
      System.out.println("Old Value: " + attributeChange.getOldValue() );
      System.out.println("New Value: " + attributeChange.getNewValue() );
    }
  }
}
Thanks

Edited by: 816587 on 29-Nov-2010 13:10

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points