@Override public ProgressNotification getTotalProgress() { ObjectName crossbowNotificationObjectName = null; try { crossbowNotificationObjectName = ObjectName.getInstance("Crossbow:type=CrossbowNotification"); } catch (Exception e) { log.error("Exception while creating workerProgress ObjectName", e); e.printStackTrace(); } int total = totalTasks; int realised = 0; try { for (String url : delegate.scGetAllMBeanServers()) { try { MBeanServerConnection mbsc = JMXConnectorFactory.connect(new JMXServiceURL(url)).getMBeanServerConnection(); CrossbowNotificationMBean crossbowNotification = JMX.newMBeanProxy( mbsc, crossbowNotificationObjectName, CrossbowNotificationMBean.class); ProgressNotification progress = crossbowNotification.getProgress(); realised += progress.getCurrent(); } catch (Exception ex) { log.error("Error while querying MBean server (url: " + url + ")", ex); } } progressNotification = new ProgressNotification(realised, total, null); } catch (RemoteException ex) { log.error("Error while getting MBean servers list.", ex); } return progressNotification; }
public String getTotalNewLogs() { StringBuilder stringBuilder = new StringBuilder(); ObjectName crossbowNotificationObjectName = null; try { crossbowNotificationObjectName = ObjectName.getInstance("Crossbow:type=CrossbowNotification"); } catch (Exception e) { log.error("Exception while creating workerProgress ObjectName", e); e.printStackTrace(); } try { for (String url : delegate.scGetAllMBeanServers()) { try { MBeanServerConnection mbsc = JMXConnectorFactory.connect(new JMXServiceURL(url)).getMBeanServerConnection(); CrossbowNotificationMBean crossbowNotification = JMX.newMBeanProxy( mbsc, crossbowNotificationObjectName, CrossbowNotificationMBean.class); String logs = crossbowNotification.getNewLogs(); if (logs != null && !logs.equals("")) { stringBuilder.append(crossbowNotification.getNewLogs()); stringBuilder.append("\n"); } } catch (Exception ex) { log.error("Error while querying MBean server (url: " + url + ")", ex); } } } catch (RemoteException ex) { log.error("Error while getting MBean servers list.", ex); } return stringBuilder.toString(); }
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); } }