@Override
 public void removeNotificationListener(ObjectName name, NotificationListener listener)
     throws InstanceNotFoundException, ListenerNotFoundException, IOException {
   try {
     connection.removeNotificationListener(name, listener);
   } catch (IOException e) {
     if (!checkConnection()) {
       connection.removeNotificationListener(name, listener);
     } else {
       throw e;
     }
   }
 }
Beispiel #2
0
  private static void test() {
    try {
      JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
      JMXConnectorServer server;
      JMXServiceURL addr;
      JMXConnector client;
      MBeanServerConnection mserver;

      final ObjectName delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
      final NotificationListener dummyListener =
          new NotificationListener() {
            public void handleNotification(Notification n, Object o) {
              // do nothing
              return;
            }
          };

      server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
      server.start();

      addr = server.getAddress();
      client = JMXConnectorFactory.newJMXConnector(addr, null);
      client.connect(null);

      mserver = client.getMBeanServerConnection();
      String s1 = "1";
      String s2 = "2";
      String s3 = "3";

      mserver.addNotificationListener(delegateName, dummyListener, null, s1);
      mserver.addNotificationListener(delegateName, dummyListener, null, s2);
      mserver.addNotificationListener(delegateName, dummyListener, null, s3);

      mserver.removeNotificationListener(delegateName, dummyListener, null, s3);
      mserver.removeNotificationListener(delegateName, dummyListener, null, s2);
      mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
      client.close();

      server.stop();
    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
      System.exit(1);
    }
  }
  private void registerNotificationListener() {

    log.debug("Reseting and registering at all WorkerProgressMBeans as listener");

    ObjectName workerProgressObjectName = null;
    ObjectName crossbowNotificationObjectName = null;
    try {
      crossbowNotificationObjectName = ObjectName.getInstance("Crossbow:type=CrossbowNotification");
      workerProgressObjectName = ObjectName.getInstance("Crossbow:type=WorkerProgress");

    } catch (Exception e) {
      log.error("Exception while creating workerProgress ObjectName", e);
      e.printStackTrace();
    }

    MBeanServer server = JimsMBeanServer.findJimsMBeanServer();

    try {

      for (String url : delegate.scGetAllMBeanServers()) {

        try {

          MBeanServerConnection mbsc =
              JMXConnectorFactory.connect(new JMXServiceURL(url)).getMBeanServerConnection();

          CrossbowNotificationMBean crossbowNotification =
              JMX.newMBeanProxy(
                  mbsc, crossbowNotificationObjectName, CrossbowNotificationMBean.class);

          crossbowNotification.reset();

          try {
            mbsc.removeNotificationListener(
                workerProgressObjectName, crossbowNotificationObjectName);
          } catch (Exception e) {
            log.error(
                "Exception while removing notification listener from MBean server (url: "
                    + url
                    + ")",
                e);
          }
          mbsc.addNotificationListener(
              workerProgressObjectName, crossbowNotificationObjectName, null, null);

          log.info(
              "CrosbowNotification successfully registered lestener at WorkerProgressMBean (url: "
                  + url
                  + ")");

        } catch (Exception ex) {
          log.error("Error while querying MBean server (url: " + url + ")", ex);
        }
      }

      progressNotification = new ProgressNotification(0, totalTasks, WorkerProgress.getIpAddress());

    } catch (RemoteException ex) {
      log.error("Error while getting MBean servers list.", ex);
    }
  }
Beispiel #4
0
 public void removeNotificationListener()
     throws ListenerNotFoundException, InstanceNotFoundException, IOException {
   mbsc.removeNotificationListener(nodeAgent, this, null, null);
 }