protected void sample() throws InterruptedException { this.system.getStatSampler().getSampleCollector().sample(NanoTimer.getTime()); Thread.sleep(SLEEP); }
/** * 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; } } }
@Test public void testGetStatMonitorHandlerAfterClose() { this.sampleCollector.close(); try { /* StatMonitorHandler handler = */ SampleCollector.getStatMonitorHandler(); fail( "getStatMonitorHandler should throw IllegalStateException when SampleCollector is closed"); } catch (IllegalStateException expected) { // passed } }
ResourceType type = getResourceType(handlers, statistics); ResourceInstance resource = allocateResourceInstance(type, statistics); notifyOldHandlersOfResource(handlers, resource); } catch (IgnoreResourceException ex) { ignoreCount++; ignoreCount); List<ResourceInstance> ri = cleanupResources(resources, ignoreCount); notifyOldHandlers(handlers, ri); notifyNewHandlersOfResources(handlers, this.resourceTypeMap.values(), this.resourceInstMap.values());
resourceType = allocateResourceType(handlers, type); notifyOldHandlersOfResourceType(handlers, resourceType);
initSpecialStats(); this.sampleCollector = new SampleCollector(this); this.sampleCollector.initialize(this, timer.getTime(), new MainWithChildrenRollingFileHandler()); break; this.sampleCollector.sample(nanosTimeStamp); closeSpecialStats(); if (this.sampleCollector != null) { this.sampleCollector.close();
@Before public void setUp() throws Exception { final long startTime = System.currentTimeMillis(); this.manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime); final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName()); when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File("")); when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(startTime); when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn(""); when(mockStatArchiveHandlerConfig.getProductDescription()) .thenReturn(getClass().getSimpleName()); final StatisticsSampler sampler = new TestStatisticsSampler(manager); this.sampleCollector = new SampleCollector(sampler); this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime(), new MainWithChildrenRollingFileHandler()); }
@Test public void testAddHandlerBeforeSample() { TestSampleHandler handler = new TestSampleHandler(); this.sampleCollector.addSampleHandler(handler); Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1_text", 1); this.sampleCollector.sample(NanoTimer.getTime());
"StatArchiveHandler#changeArchiveFile removing handler"); this.collector.removeSampleHandler(this); "StatArchiveHandler#changeArchiveFile removing handler"); this.collector.removeSampleHandler(this); "StatArchiveHandler#changeArchiveFile adding handler"); this.collector.addSampleHandler(this);
@After public void tearDown() throws Exception { if (this.sampleCollector != null) { this.sampleCollector.close(); this.sampleCollector = null; } this.manager = null; }
StatMonitorHandler getStatMonitorHandler() { return SampleCollector.getStatMonitorHandler(); }
public void changeArchive(File newFile) { this.sampleCollector.changeArchive(newFile, timer.getTime()); }
@Before public void setUp() throws Exception { final long startTime = System.currentTimeMillis(); this.manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime); final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName()); when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File("")); when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn(""); when(mockStatArchiveHandlerConfig.getProductDescription()) .thenReturn(getClass().getSimpleName()); StatisticsSampler sampler = new TestStatisticsSampler(manager); this.sampleCollector = new SampleCollector(sampler); this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime(), new MainWithChildrenRollingFileHandler()); }
st2_1.incInt("ST2_1_name", 1); long sampleTime = NanoTimer.getTime(); this.sampleCollector.sample(sampleTime); this.sampleCollector.sample(sampleTime); this.sampleCollector.sample(sampleTime); this.sampleCollector.addSampleHandler(handler); st2_1.incInt("ST2_1_name", 1); sampleTime += NanoTimer.millisToNanos(1000); this.sampleCollector.sample(sampleTime);
@After public void tearDown() throws Exception { if (this.sampleCollector != null) { this.sampleCollector.close(); this.sampleCollector = null; } this.manager = null; }
@Test public void testGetStatMonitorHandler() { StatMonitorHandler handler = SampleCollector.getStatMonitorHandler(); assertNotNull(handler); assertTrue(handler.getMonitorsSnapshot().isEmpty()); assertNull(handler.getStatMonitorNotifier()); }
@Before public void setUp() { final long startTime = System.currentTimeMillis(); TestStatisticsManager manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime); StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName()); when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File("")); when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L); when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(startTime); when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn(""); when(mockStatArchiveHandlerConfig.getProductDescription()) .thenReturn(getClass().getSimpleName()); StatisticsSampler sampler = new TestStatisticsSampler(manager); SampleCollector sampleCollector = new SampleCollector(sampler); sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime(), new MainWithChildrenRollingFileHandler()); gatewaySenderOverflowMonitor = spy(new GatewaySenderOverflowMonitor(this.testName.getMethodName())); assertThat(gatewaySenderOverflowMonitor).isNotNull(); assertThat(gatewaySenderOverflowMonitor.getMonitors()).isEmpty(); assertThat(gatewaySenderOverflowMonitor.getListeners()).isEmpty(); assertThat(gatewaySenderOverflowMonitor.getLruEvictions()).isEqualTo(0); assertThat(gatewaySenderOverflowMonitor.getBytesOverflowedToDisk()).isEqualTo(0); assertThat(gatewaySenderOverflowMonitor.getEntriesOverflowedToDisk()).isEqualTo(0); }
@Test public void testGetStatMonitorHandlerBeforeAndAfterClose() { StatMonitorHandler handler = SampleCollector.getStatMonitorHandler(); assertNotNull(handler); this.sampleCollector.close(); try { handler = SampleCollector.getStatMonitorHandler(); fail( "getStatMonitorHandler should throw IllegalStateException when SampleCollector is closed"); } catch (IllegalStateException expected) { // passed } }
/** * 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); } } }
SampleCollector sampleCollector = new SampleCollector(sampler); sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime(), new MainWithChildrenRollingFileHandler()); aggregateRegionStatsMonitor =