@Test public void testCloseAll() { WatchDataSourceRegistry registry = new WatchDataSourceRegistry(); int[] counts = new int[] {0, 1, 10, 100}; for (int count : counts) { Collection<Watch> watches = new ArrayList<Watch>(); for (int j = 0; j < count; j++) { String id = "watch" + j; LoggingWatchDataSource ds = new LoggingWatchDataSource( id, EmptyConfiguration.INSTANCE); Watch watch = new GaugeWatch(ds, id); watches.add(watch); } for (Watch watch : watches) { registry.register(watch); } registry.closeAll(); for (Watch watch : watches) { LoggingWatchDataSource ds = (LoggingWatchDataSource) watch.getWatchDataSource(); checkLog(ds.log(), "close()"); } for (Watch watch : watches) { registry.deregister(watch); LoggingWatchDataSource ds = (LoggingWatchDataSource) watch.getWatchDataSource(); checkLog(ds.log(), "close()"); } registry.closeAll(); for (Watch watch : watches) { LoggingWatchDataSource ds = (LoggingWatchDataSource) watch.getWatchDataSource(); checkLog(ds.log(), ""); } } }
public void closeAll() { Watch[] watches = watchRegistry.toArray(new Watch[0]); for(Watch w : watches) { if(w instanceof PeriodicWatch) ((PeriodicWatch)w).stop(); try { WatchDataSource wd = w.getWatchDataSource(); if (wd != null) wd.close(); watchRegistry.remove(w); } catch (Exception e) { logger.warn("Closing WatchDataSource", e); } } }
WatchDataSourceRegistry implements WatchRegistry { public void closeAll() { Watch[] watches = watchRegistry.toArray(new Watch[0]); for(Watch w : watches) { if(w instanceof PeriodicWatch) ((PeriodicWatch)w).stop(); try { WatchDataSource wd = w.getWatchDataSource(); if (wd != null) wd.close(); watchRegistry.remove(w); } catch (Exception e) { logger.warn("Closing WatchDataSource", e); } } } }
WatchDataSourceRegistry implements WatchRegistry { public void closeAll() { Watch[] watches = watchRegistry.toArray(new Watch[0]); for(Watch w : watches) { if(w instanceof PeriodicWatch) ((PeriodicWatch)w).stop(); try { WatchDataSource wd = w.getWatchDataSource(); if (wd != null) wd.close(); watchRegistry.remove(w); } catch (Exception e) { logger.warn("Closing WatchDataSource", e); } } }  }
WatchDataSourceRegistry implements WatchRegistry { public void closeAll() { Watch[] watches = watchRegistry.toArray(new Watch[0]); for(Watch w : watches) { if(w instanceof PeriodicWatch) ((PeriodicWatch)w).stop(); try { WatchDataSource wd = w.getWatchDataSource(); if (wd != null) wd.close(); watchRegistry.remove(w); } catch (Exception e) { logger.warn("Closing WatchDataSource", e); } } }  void deregister(Watch... watches); void closeAll(); void register(Watch... watches); void addThresholdListener(String id, ThresholdListener thresholdListener); void removeThresholdListener(String id, ThresholdListener thresholdListener); Watch findWatch(String id); WatchDataSource[] fetch(); WatchDataSource fetch(String id); void setServiceBeanContext(ServiceBeanContext context); }
WatchDataSourceRegistry implements WatchRegistry { public void closeAll() { Watch[] watches = watchRegistry.toArray(new Watch[0]); for(Watch w : watches) { if(w instanceof PeriodicWatch) ((PeriodicWatch)w).stop(); try { WatchDataSource wd = w.getWatchDataSource(); if (wd != null) wd.close(); watchRegistry.remove(w); } catch (Exception e) { logger.warn("Closing WatchDataSource", e); } } }  void deregister(Watch... watches); void closeAll(); void register(Watch... watches); void addThresholdListener(String id, ThresholdListener thresholdListener); void removeThresholdListener(String id, ThresholdListener thresholdListener); Watch findWatch(String id); WatchDataSource[] fetch(); WatchDataSource fetch(String id); void setServiceBeanContext(ServiceBeanContext context);  }