@Override
 public void addNotificationListener(
     ObjectName name, ObjectName listener, NotificationFilter filter, Object handback)
     throws InstanceNotFoundException, IOException {
   try {
     connection.addNotificationListener(name, listener, filter, handback);
   } catch (IOException e) {
     if (!checkConnection()) {
       connection.addNotificationListener(name, listener, filter, handback);
     } else {
       throw e;
     }
   }
 }
Пример #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);
    }
  }
Пример #3
0
 /**
  * register to get JMX notifications
  *
  * @param pathName path of the resource or collection which the notification is about
  * @throws Exception
  */
 public void registerNotificationListener(String pathName) throws Exception {
   path = pathName;
   try {
     mbsc.addNotificationListener(nodeAgent, this, null, null);
     log.info("Registered for event notifications");
   } catch (Exception e) {
     log.error("NotificationListener registration fail");
     throw new Exception("NotificationListener registration fail" + e.getMessage());
   }
 }
Пример #4
0
  public void init() throws Exception {

    super.init();

    url = getParameter(URL);

    if (url == null) {
      protocol = getParameter(PROTOCOL);
      host = getParameter(HOST);
      port = Integer.parseInt(getParameter(PORT));
      transportPort = Integer.parseInt(getParameter(TRANSPORT_PORT));

      url = "service:jmx:" + protocol + "://" + host;
      if (transportPort != DEFAULT_TRANSPORT_PORT) url += ":" + transportPort;

      url += "/jndi/" + protocol + "://" + host;
      if (port != DEFAULT_PORT) url += ":" + port;

      url += "/penrose";

      // url =
      // "service:jmx:rmi://localhost:rmiTransportProtocol/jndi/rmi://localhost:rmiProtocol/penrose";
    }

    bindDn = getParameter(BIND_DN);
    log.debug("Bind DN: " + bindDn);

    bindPassword = getParameter(BIND_PASSWORD);
    log.debug("Password: "******"java.lang:type=Memory");

    Hashtable<String, Object> parameters = new Hashtable<String, Object>();

    if (bindDn != null && bindPassword != null) {
      log.debug("Binding as " + bindDn + ".");

      String[] credentials = new String[] {bindDn, bindPassword};

      parameters.put(JMXConnector.CREDENTIALS, credentials);
    }

    JMXServiceURL serviceURL = new JMXServiceURL(url);
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL, parameters);

    connection = connector.getMBeanServerConnection();
    connection.addNotificationListener(memoryMBean, this, null, null);
  }
  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);
    }
  }