/** * Resets the impl for unittests. */ void reset() { cleanup(); // cleaning up all context before reseting producer registry instance listeners.clear(); registry.clear(); String junittest = System.getProperty("JUNITTEST"); if (junittest != null && junittest.equalsIgnoreCase("true")) // preventing listener's initialization for JUnit run's return; addListener(new JMXBridgeListener()); }
/** * Creates the ProducerRegistryImpl singleton instance. */ ProducerRegistryImpl() { reset(); }
@Override public Collection<IStatsProducer> getProducers() { List<IStatsProducer> ret = new ArrayList<>(); for (ProducerReference r : getProducerReferences()) { if (r.get() != null) ret.add(r.get()); } return ret; }
/** * This method is primary used for unit tests. */ public void cleanup() { ArrayList<ProducerReference> producerReferences = new ArrayList<ProducerReference>(registry.values()); for (ProducerReference p : producerReferences) { try { if (p.get() != null) unregisterProducer(p.get()); } catch (Exception e) { LOGGER.warn("can't unregister producer " + p, e); } } } }
/** * Resets the registry, useable for unit tests. Note this method doesn't stop producers from running (if the are running) hence it shouldn't be used in production environment. */ public static final void reset(){ instance.reset(); String junittest = System.getProperty("JUNITTEST"); if (junittest!=null && junittest.equalsIgnoreCase("true")) return; StartBuiltInProducers.restartbuiltin(); } }