@Override protected long getRecordSpecificTimestamp(final IMonitoringRecord record) { return record.getLoggingTimestamp(); }
private StringBuilder appendSingleRecord(final IMonitoringRecord record, final StringBuilder builder) { builder.append(record.getClass().getName()); builder.append(';'); builder.append(record.getLoggingTimestamp()); builder.append(';'); builder.append(record.toString()); builder.append('\n'); return builder; }
private StringBuilder appendSingleRecord(final IMonitoringRecord record, final StringBuilder builder) { builder.append(record.getClass().getName()); builder.append(';'); builder.append(record.getLoggingTimestamp()); builder.append(';'); builder.append(record.toString()); builder.append('\n'); return builder; }
private int encodeRecords(final Collection<IMonitoringRecord> records, final ByteBuffer buffer, final IWriterRegistry<String> writerRegistry) { final int offsetBefore = buffer.position(); for (final IMonitoringRecord record : records) { // Since writeBytes does not contain the type name and the logging timestamp, // these two fields must be serialized separately final String typeName = record.getClass().getName(); final int typeNameId = writerRegistry.getId(typeName); buffer.putInt(typeNameId); buffer.putLong(record.getLoggingTimestamp()); record.serialize(BinaryValueSerializer.create(buffer, writerRegistry)); } final int offsetAfter = buffer.position(); return (offsetAfter - offsetBefore); }
private int encodeRecords(final Collection<IMonitoringRecord> records, final ByteBuffer buffer, final IRegistry<String> stringRegistry) { final int offsetBefore = buffer.position(); for (final IMonitoringRecord record : records) { // Since writeBytes does not contain the type name and the logging timestamp, // these two fields must be serialized separately final String typeName = record.getClass().getName(); final int typeNameId = stringRegistry.get(typeName); buffer.putInt(typeNameId); buffer.putLong(record.getLoggingTimestamp()); record.serialize(DefaultValueSerializer.create(buffer, stringRegistry)); } final int offsetAfter = buffer.position(); return (offsetAfter - offsetBefore); }
@Override protected void execute(final IMonitoringRecord record) { final long loggingTimestamp = record.getLoggingTimestamp(); if (loggingTimestamp < this.beginTimestamp) { this.beginTimestamp = loggingTimestamp; } if (loggingTimestamp > this.endTimestamp) { this.endTimestamp = loggingTimestamp; } super.getOutputPort().send(record); }
/** * This method represents the input port for new records. * * @param record * The next record. */ @InputPort(name = INPUT_PORT_NAME_NEW_RECORD, eventTypes = { IMonitoringRecord.class }, description = "Receives a new record and extracts the logging timestamp as a time event") public void inputRecord(final IMonitoringRecord record) { this.inputTimestamp(record.getLoggingTimestamp()); }
@Override public void serialize(final IMonitoringRecord record, final int id) throws IOException { this.requestBufferSpace(4 + 8 + record.getSize()); this.buffer.putInt(id); this.buffer.putLong(record.getLoggingTimestamp()); record.serialize(this.serializer); this.numOfEntries++; }
/** * This method represents the input port for new records. * * @param record * The next record. */ @InputPort(name = INPUT_PORT_NAME_NEW_RECORD, eventTypes = { IMonitoringRecord.class }, description = "Receives a new record and extracts the logging timestamp as a time event") public void inputRecord(final IMonitoringRecord record) { this.inputTimestamp(record.getLoggingTimestamp()); }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { monitoringRecord.registerStrings(this.registerStringsAdapter); final ByteBuffer recordBuffer = this.buffer; final int requiredBufferSize = SIZE_OF_ENVELOPE + 4 + 8 + monitoringRecord.getSize(); if (recordBuffer.capacity() < requiredBufferSize) { throw new IllegalStateException("Insufficient buffer capacity for string registry data"); } // register monitoringRecord class name final String recordClassName = monitoringRecord.getClass().getName(); this.writerRegistry.register(recordClassName); // Prepend envelope data recordBuffer.put(REGULAR_RECORD_ID); recordBuffer.putLong(this.writerRegistry.getId()); // serialized monitoringRecord recordBuffer.putInt(this.writerRegistry.getId(recordClassName)); recordBuffer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(DefaultValueSerializer.create(recordBuffer, this.writeBytesAdapter)); this.publishBuffer(recordBuffer); }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final ByteBuffer buffer = this.recordBuffer; final int requiredBufferSize = 4 + 8 + monitoringRecord.getSize(); if (requiredBufferSize > buffer.remaining()) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOG); } final String recordClassName = monitoringRecord.getClass().getName(); this.serializer.putString(recordClassName); this.serializer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(this.serializer); if (this.flush) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOG); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final ByteBuffer buffer = this.recordBuffer; final int requiredBufferSize = 4 + 8 + monitoringRecord.getSize(); if (requiredBufferSize > buffer.remaining()) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOGGER); } final String recordClassName = monitoringRecord.getClass().getName(); this.serializer.putString(recordClassName); this.serializer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(this.serializer); if (this.flush) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOGGER); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final ByteBuffer buffer = this.recordBuffer; final int requiredBufferSize = 4 + 8 + monitoringRecord.getSize(); if (requiredBufferSize > buffer.remaining()) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOG); } final String recordClassName = monitoringRecord.getClass().getName(); this.serializer.putString(recordClassName); this.serializer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(this.serializer); if (this.flush) { WriterUtil.flushBuffer(buffer, this.monitoringRecordChannel, LOG); } }
@InputPort(name = INPUT_PORT_NAME_ANY_RECORD, description = "Receives records to be selected by their logging timestamps", eventTypes = { IMonitoringRecord.class }) public final void inputIMonitoringRecord(final IMonitoringRecord record) { if (this.inRange(record.getLoggingTimestamp())) { super.deliver(OUTPUT_PORT_NAME_WITHIN_PERIOD, record); } else { super.deliver(OUTPUT_PORT_NAME_OUTSIDE_PERIOD, record); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final PooledFileChannel channel = this.fileWriterPool.getFileWriter(this.buffer); monitoringRecord.registerStrings(this.registerStringsAdapter); final ByteBuffer recordBuffer = this.buffer; if ((4 + 8 + monitoringRecord.getSize()) > recordBuffer.remaining()) { channel.flush(recordBuffer, LOG); } final String recordClassName = monitoringRecord.getClass().getName(); this.writerRegistry.register(recordClassName); recordBuffer.putInt(this.writerRegistry.getId(recordClassName)); recordBuffer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(DefaultValueSerializer.create(recordBuffer, this.writeBytesAdapter)); if (this.flush) { channel.flush(recordBuffer, LOG); } }
@InputPort(name = INPUT_PORT_NAME_ANY_RECORD, description = "Receives records to be selected by their logging timestamps", eventTypes = { IMonitoringRecord.class }) public final void inputIMonitoringRecord(final IMonitoringRecord record) { if (this.inRange(record.getLoggingTimestamp())) { super.deliver(OUTPUT_PORT_NAME_WITHIN_PERIOD, record); } else { super.deliver(OUTPUT_PORT_NAME_OUTSIDE_PERIOD, record); } }
@Test public void testControllerSetsLoggingTimestamp() throws Exception { final List<IMonitoringRecord> eventsToWrite = this.provideEvents(); // The following line is an easy way to test the tests (given monitoringRecords includes at least one record). But don't forget to deactivate afterwards. // eventsToWrite.remove(eventsToWrite.size() - 1); final List<IMonitoringRecord> eventsFromRecordLoggerFilter = this.testIt(eventsToWrite, false); // includes Assert(s) Assert.assertEquals("Unexpected set of records relayed by filter", eventsToWrite, eventsFromRecordLoggerFilter); final List<IMonitoringRecord> eventsFromLog = this.readEvents(); Assert.assertEquals("Unexpected set of records in monitoring log", eventsToWrite, eventsFromLog); Assert.assertThat(eventsFromLog.get(0).getLoggingTimestamp(), CoreMatchers.is(eventsToWrite.get(0).getLoggingTimestamp())); }
@Test public void testControllerKeepsLoggingTimestamp() throws Exception { final List<IMonitoringRecord> eventsToWrite = this.provideEvents(); // The following line is an easy way to test the tests (given monitoringRecords includes at least one record). But don't forget to deactivate afterwards. // eventsToWrite.remove(eventsToWrite.size() - 1); final List<IMonitoringRecord> eventsFromRecordLoggerFilter = this.testIt(eventsToWrite, true); // includes Assert(s) Assert.assertEquals("Unexpected set of records relayed by filter", eventsToWrite, eventsFromRecordLoggerFilter); final List<IMonitoringRecord> eventsFromLog = this.readEvents(); Assert.assertEquals("Unexpected set of records in monitoring log", eventsToWrite, eventsFromLog); Assert.assertThat(eventsFromLog.get(0).getLoggingTimestamp(), CoreMatchers.is(eventsToWrite.get(0).getLoggingTimestamp())); }
@Test public void testSetLoggingTimestampEnabled() throws InterruptedException { final EmptyRecord record = new EmptyRecord(); final IMonitoringRecord receivedRecord = this.executeTestSetLoggingTimestamp(true); Assert.assertThat(record.getLoggingTimestamp(), CoreMatchers.is(CoreMatchers.not(receivedRecord.getLoggingTimestamp()))); }
@Test public void testSetLoggingTimestampDisabled() throws InterruptedException { final EmptyRecord record = new EmptyRecord(); final IMonitoringRecord receivedRecord = this.executeTestSetLoggingTimestamp(false); Assert.assertThat(record.getLoggingTimestamp(), CoreMatchers.is(receivedRecord.getLoggingTimestamp())); }