public void flush(final ByteBuffer buffer, final Log log) { this.bytesWritten += WriterUtil.flushBuffer(buffer, this.channel, log); }
@Override public void onTerminating() { // Always flush the registryBuffer before flushing the recordBuffer. // Otherwise the monitoring records could arrive before their string // records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOG); WriterUtil.flushBuffer(this.buffer, this.socketChannel, LOG); WriterUtil.close(this.socketChannel, LOG); } }
@Override public void onTerminating() { // Always flush the registryBuffer before flushing the recordBuffer. Otherwise // the monitoring records could arrive before their string records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOGGER); WriterUtil.flushBuffer(this.buffer, this.socketChannel, LOGGER); WriterUtil.close(this.socketChannel, LOGGER); } }
@Override public void onTerminating() { WriterUtil.flushBuffer(this.stringRegistryBuffer, this.registryRecordChannel, LOG); WriterUtil.flushBuffer(this.recordBuffer, this.monitoringRecordChannel, LOG); WriterUtil.close(this.registryRecordChannel, LOG); WriterUtil.close(this.monitoringRecordChannel, LOG); } }
@Override public void onTerminating() { WriterUtil.flushBuffer(this.stringRegistryBuffer, this.registryRecordChannel, LOGGER); WriterUtil.flushBuffer(this.recordBuffer, this.monitoringRecordChannel, LOGGER); WriterUtil.close(this.registryRecordChannel, LOGGER); WriterUtil.close(this.monitoringRecordChannel, LOGGER); } }
@Override public void onNewRegistryEntry(final String value, final int id) { final ByteBuffer localRegistryBuffer = this.registryBuffer; final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // logging timestamp + class id + RegistryRecord.SIZE + bytes.length final int requiredBufferSize = (2 * AbstractMonitoringRecord.TYPE_SIZE_INT) + RegistryRecord.SIZE + bytes.length; if (localRegistryBuffer.remaining() < requiredBufferSize) { WriterUtil.flushBuffer(localRegistryBuffer, this.socketChannel, LOG); } localRegistryBuffer.putInt(RegistryRecord.CLASS_ID); localRegistryBuffer.putInt(id); localRegistryBuffer.putInt(value.length()); localRegistryBuffer.put(bytes); }
@Override public void onTerminating() { WriterUtil.flushBuffer(this.stringRegistryBuffer, this.registryRecordChannel, LOG); WriterUtil.flushBuffer(this.recordBuffer, this.monitoringRecordChannel, LOG); WriterUtil.close(this.registryRecordChannel, LOG); WriterUtil.close(this.monitoringRecordChannel, LOG); }
/** * Flushes the buffer and closes the channel afterwards. */ public void close(final ByteBuffer buffer, final Log log) { this.bytesWritten += WriterUtil.flushBuffer(buffer, this.channel, log); WriterUtil.close(this.channel, log); } }
@Override public void onNewRegistryEntry(final String value, final int id) { final ByteBuffer localRegistryBuffer = this.registryBuffer; final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // logging timestamp + class id + RegistryRecord.SIZE + bytes.length final int requiredBufferSize = (2 * AbstractMonitoringRecord.TYPE_SIZE_INT) + RegistryRecord.SIZE + bytes.length; if (localRegistryBuffer.remaining() < requiredBufferSize) { WriterUtil.flushBuffer(localRegistryBuffer, this.socketChannel, LOGGER); } localRegistryBuffer.putInt(RegistryRecord.CLASS_ID); localRegistryBuffer.putInt(id); localRegistryBuffer.putInt(value.length()); localRegistryBuffer.put(bytes); }
@Override public void onNewRegistryEntry(final String value, final int id) { final ByteBuffer buffer = this.stringRegistryBuffer; final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // final ByteBuffer valueInByteBuffer = StandardCharsets.UTF_8.encode(value); final int requiredBufferSize = RegistryRecord.SIZE + bytes.length; if (buffer.capacity() < requiredBufferSize) { // stringRegistryBuffer = ByteBuffer.allocateDirect(RegistryRecord.SIZE + bytes.length); throw new IllegalStateException("Insufficient capacity for string registry buffer"); } // loggingTimestamp not transmitted by dual socket communication // class id not used by dual socket communication buffer.putInt(id); buffer.putInt(value.length()); buffer.put(bytes); // always flush so that on the reader side the records can be reconstructed WriterUtil.flushBuffer(buffer, this.registryRecordChannel, LOG); }
@Override public void onNewRegistryEntry(final String value, final int id) { final ByteBuffer buffer = this.stringRegistryBuffer; final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // final ByteBuffer valueInByteBuffer = StandardCharsets.UTF_8.encode(value); final int requiredBufferSize = RegistryRecord.SIZE + bytes.length; if (buffer.capacity() < requiredBufferSize) { // stringRegistryBuffer = ByteBuffer.allocateDirect(RegistryRecord.SIZE + bytes.length); throw new IllegalStateException("Insufficient capacity for string registry buffer"); } // loggingTimestamp not transmitted by dual socket communication // class id not used by dual socket communication buffer.putInt(id); buffer.putInt(value.length()); buffer.put(bytes); // always flush so that the stringRegistryBuffer is transmitted before the record buffer WriterUtil.flushBuffer(buffer, this.registryRecordChannel, LOG); }
@Override public void onNewRegistryEntry(final String value, final int id) { final ByteBuffer buffer = this.stringRegistryBuffer; final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // final ByteBuffer valueInByteBuffer = StandardCharsets.UTF_8.encode(value); final int requiredBufferSize = RegistryRecord.SIZE + bytes.length; if (buffer.capacity() < requiredBufferSize) { // stringRegistryBuffer = ByteBuffer.allocateDirect(RegistryRecord.SIZE + bytes.length); throw new IllegalStateException("Insufficient capacity for string registry buffer"); } // loggingTimestamp not transmitted by dual socket communication // class id not used by dual socket communication buffer.putInt(id); buffer.putInt(value.length()); buffer.put(bytes); // always flush so that the stringRegistryBuffer is transmitted before the record buffer WriterUtil.flushBuffer(buffer, this.registryRecordChannel, LOGGER); }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final ByteBuffer recordBuffer = this.buffer; if ((4 + 8 + monitoringRecord.getSize()) > recordBuffer.remaining()) { // Always flush the registryBuffer before flushing the recordBuffer. Otherwise // the monitoring records could arrive before their string records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOGGER); WriterUtil.flushBuffer(recordBuffer, this.socketChannel, LOGGER); } final String recordClassName = monitoringRecord.getClass().getName(); this.serializer.putString(recordClassName); this.serializer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(this.serializer); if (this.flush) { // Always flush the registryBuffer before flushing the recordBuffer. Otherwise // the monitoring records could arrive before their string records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOGGER); WriterUtil.flushBuffer(recordBuffer, this.socketChannel, LOGGER); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord monitoringRecord) { final ByteBuffer recordBuffer = this.buffer; if ((4 + 8 + monitoringRecord.getSize()) > recordBuffer.remaining()) { // Always flush the registryBuffer before flushing the recordBuffer. // Otherwise the monitoring records could arrive before their string // records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOG); WriterUtil.flushBuffer(recordBuffer, this.socketChannel, LOG); } final String recordClassName = monitoringRecord.getClass().getName(); this.serializer.putString(recordClassName); this.serializer.putLong(monitoringRecord.getLoggingTimestamp()); monitoringRecord.serialize(this.serializer); if (this.flush) { // Always flush the registryBuffer before flushing the recordBuffer. // Otherwise the monitoring records could arrive before their string // records WriterUtil.flushBuffer(this.registryBuffer, this.socketChannel, LOG); WriterUtil.flushBuffer(recordBuffer, this.socketChannel, 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, 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, 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); } }