protected boolean isArchiving() { return this.archiver != null && this.archiver.bytesWritten() > 0; }
private void handleArchiverException(GemFireException ex) { if (this.archiver.getSampleCount() > 0) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw, true)); logger.warn(LogMarker.STATISTICS_MARKER, "Statistic archiver shutting down because: {}", sw); } try { this.archiver.close(); } catch (GemFireException ignore) { if (this.archiver.getSampleCount() > 0) { logger.warn(LogMarker.STATISTICS_MARKER, "Statistic archiver shutdown failed because: {}", ignore.getMessage()); } } if (this.archiver.getSampleCount() == 0 && this.archiveId != -1) { // dec since we didn't use the file and close deleted it. this.archiveId--; } this.archiver = null; }
private long readCompactValue() throws IOException { return StatArchiveWriter.readCompactValue(this.dataIn); }
archiver.sampled(nanosTimeStamp, resourceInstances); if (archiver.getSampleCount() == 1) { logger.info(LogMarker.STATISTICS_MARKER, "Archiving statistics to {}.", archiver.getArchiveName()); long byteLimit = config.getArchiveFileSizeLimit(); if (byteLimit != 0) { long bytesWritten = archiver.bytesWritten(); if (bytesWritten > byteLimit) {
@Test public void shouldBeMockable() throws Exception { StatArchiveWriter mockStatArchiveWriter = mock(StatArchiveWriter.class); when(mockStatArchiveWriter.bytesWritten()).thenReturn(1L); mockStatArchiveWriter.close(); verify(mockStatArchiveWriter, times(1)).close(); assertThat(mockStatArchiveWriter.bytesWritten()).isEqualTo(1L); } }
archiver.close(); } catch (GemFireException ignore) { logger.warn(LogMarker.STATISTICS_MARKER, .setSystemDirectoryPath(this.config.getSystemDirectoryPath()) .setProductDescription(this.config.getProductDescription()).build(); newArchiver = new StatArchiveWriter(archiveDescriptor); newArchiver.initialize(nanosTimeStamp); } catch (GemFireIOException ex) { logger.warn(LogMarker.STATISTICS_MARKER, archiver.close(); } catch (GemFireException ignore) { logger.warn(LogMarker.STATISTICS_MARKER,
for (int offset : offsets) { long val = valueToTest + offset; StatArchiveWriter.writeCompactValue(val, out); for (int offset : offsets) { long expectedVal = valueToTest + offset; long val = StatArchiveWriter.readCompactValue(in); assertEquals(expectedVal, val); for (int offset : offsets) { long expectedVal = valueToTest + offset; long val = StatArchiveWriter.readCompactValue(in); assertEquals(expectedVal, val);
/** * Closes the statArchiver by flushing its data to disk a closing its output stream. * * @throws GemFireIOException if the archive file could not be closed. */ public void close() { try { this.dataOut.flush(); if (this.trace) { this.traceDataOut.flush(); } } catch (IOException ignore) { } try { outStream.close(); if (this.trace) { this.traceOutStream.close(); } } catch (IOException ex) { throw new GemFireIOException( "Could not close statArchiver file", ex); } if (getSampleCount() == 0) { // If we are closing an empty file go ahead and delete it. // This prevents the fix for 46917 from leaving a bunch of // empty gfs files around. deleteFileIfPossible(new File(getArchiveName())); } }
/** * Closes any {@link StatArchiveWriter} currently in use by this handler. * */ public void close() throws GemFireException { synchronized (this) { if (archiver != null) { archiver.close(); } } }
public static void writeStatValue(byte typeCode, long v, DataOutput dataOut) throws IOException { switch (typeCode) { case BYTE_CODE: dataOut.writeByte((int) v); break; case SHORT_CODE: dataOut.writeShort((int) v); break; case INT_CODE: case FLOAT_CODE: case LONG_CODE: case DOUBLE_CODE: writeCompactValue(v, dataOut); break; default: throw new InternalGemFireException(String.format("Unexpected type code %s", Byte.valueOf(typeCode))); } }
@Override public void allocatedResourceType(ResourceType resourceType) { if (logger.isTraceEnabled(LogMarker.STATISTICS_VERBOSE)) { logger.trace(LogMarker.STATISTICS_VERBOSE, "StatArchiveHandler#allocatedResourceType resourceType={}", resourceType); } if (archiver != null) { try { archiver.allocatedResourceType(resourceType); } catch (GemFireException ex) { handleArchiverException(ex); } } }
@Override public void allocatedResourceInstance(ResourceInstance resourceInstance) { if (logger.isTraceEnabled(LogMarker.STATISTICS_VERBOSE)) { logger.trace(LogMarker.STATISTICS_VERBOSE, "StatArchiveHandler#allocatedResourceInstance resourceInstance={}", resourceInstance); } if (archiver != null) { try { archiver.allocatedResourceInstance(resourceInstance); } catch (GemFireException ex) { handleArchiverException(ex); } } }
@Override public void destroyedResourceInstance(ResourceInstance resourceInstance) { if (logger.isTraceEnabled(LogMarker.STATISTICS_VERBOSE)) { logger.trace(LogMarker.STATISTICS_VERBOSE, "StatArchiveHandler#destroyedResourceInstance resourceInstance={}", resourceInstance); } if (archiver != null) { try { archiver.destroyedResourceInstance(resourceInstance); } catch (GemFireException ex) { handleArchiverException(ex); } } }
private void writeTimeStamp(long nanosTimeStamp) throws IOException { final long millisTimeStamp = NanoTimer.nanosToMillis(nanosTimeStamp); final long delta = calcDelta(this.previousMillisTimeStamp, millisTimeStamp); if (logger.isTraceEnabled(LogMarker.STATISTICS_VERBOSE)) { logger.trace(LogMarker.STATISTICS_VERBOSE, "StatArchiveWriter#writeTimeStamp millisTimeStamp={}, delta={}", millisTimeStamp, (int) delta); } if (delta > MAX_SHORT_TIMESTAMP) { if (delta > Integer.MAX_VALUE) { throw new InternalGemFireException( String.format("timeStamp delta %s was greater than %s", new Object[] {Long.valueOf(delta), Integer.valueOf(Integer.MAX_VALUE)})); } this.dataOut.writeShort(INT_TIMESTAMP_TOKEN); this.dataOut.writeInt((int) delta); if (this.trace) { this.traceDataOut .println("writeTimeStamp#writeShort INT_TIMESTAMP_TOKEN: " + INT_TIMESTAMP_TOKEN); this.traceDataOut.println("writeTimeStamp#writeInt (int)delta: " + (int) delta); } } else { this.dataOut.writeShort((int) delta); if (this.trace) { this.traceDataOut.println("writeTimeStamp#writeShort (int)delta: " + (int) delta); } } this.previousMillisTimeStamp = millisTimeStamp; }