public void run() { super.run(); // save the last set of active JVMs Set lastActiveVms = activeVms; try { // get the current set of active JVMs activeVms = (HashSet) vmManager.activeVms(); } catch (MonitorException e) { // XXX: use logging api System.err.println("MonitoredHostProvider: polling task " + "caught MonitorException:"); e.printStackTrace(); // mark the HostManager as errored and notify listeners setLastException(e); fireDisconnectedEvents(); } if (activeVms.isEmpty()) { return; } Set startedVms = new HashSet(); Set terminatedVms = new HashSet(); for (Iterator i = activeVms.iterator(); i.hasNext(); /* empty */ ) { Integer vmid = (Integer) i.next(); if (!lastActiveVms.contains(vmid)) { // a new file has been detected, add to set startedVms.add(vmid); } } for (Iterator i = lastActiveVms.iterator(); i.hasNext(); /* empty */ ) { Object o = i.next(); if (!activeVms.contains(o)) { // JVM has terminated, remove it from the active list terminatedVms.add(o); } } if (!startedVms.isEmpty() || !terminatedVms.isEmpty()) { fireVmStatusChangedEvents(activeVms, startedVms, terminatedVms); } }