/** * Returns the {@link StatMonitorHandler}. If one does not currently exist it will be created. * * @return the StatMonitorHandler for adding monitors * @throws IllegalStateException if no SampleCollector has been created and initialized yet */ static StatMonitorHandler getStatMonitorHandler() { // sync SampleCollector.class and then instance.sampleHandlers synchronized (SampleCollector.class) { if (instance == null) { throw new IllegalStateException("Statistics sampler is not available"); } synchronized (instance.sampleHandlers) { StatMonitorHandler handler = instance.statMonitorHandler; if (handler == null) { handler = new StatMonitorHandler(); instance.addSampleHandler(handler); instance.statMonitorHandler = handler; } return handler; } } }
/** * Initializes this collector by creating a {@link StatArchiveHandler} and registering it as a * handler. * * @param config defines the configuration for the StatArchiveHandler * @param nanosTimeStamp the nanos time stamp to initialize stat archiver with * @param rollingFileHandler provides file rolling behavior */ @SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "There is never more than one SampleCollector instance.") public void initialize(final StatArchiveHandlerConfig config, final long nanosTimeStamp, final RollingFileHandler rollingFileHandler) { synchronized (SampleCollector.class) { instance = this; synchronized (this.sampleHandlers) { StatArchiveHandler newStatArchiveHandler = new StatArchiveHandler(config, this, rollingFileHandler); this.statArchiveHandler = newStatArchiveHandler; addSampleHandler(newStatArchiveHandler); newStatArchiveHandler.initialize(nanosTimeStamp); } } }
"StatArchiveHandler#changeArchiveFile adding handler"); this.collector.addSampleHandler(this);
@Test public void testAddHandlerBeforeSample() { TestSampleHandler handler = new TestSampleHandler(); this.sampleCollector.addSampleHandler(handler);
this.sampleCollector.addSampleHandler(handler);