Commit 6597f68d authored by Florian Fittkau's avatar Florian Fittkau

WiP Optimized String sending

parent b2caea5d
......@@ -10,7 +10,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import explorviz.live_trace_processing.Constants;
import explorviz.live_trace_processing.debug.DebugFileByteBufferWriter;
import explorviz.live_trace_processing.record.misc.StringRegistryRecord;
public class MonitoringStringRegistry {
......@@ -63,19 +62,21 @@ public class MonitoringStringRegistry {
return buffer;
}
public static final void sendOutAllStringRegistryRecords(final SocketChannel socketChannel,
final boolean debug, final DebugFileByteBufferWriter debugWriter) throws IOException {
public static final void sendOutAllStringRegistryRecords(final SocketChannel socketChannel)
throws IOException {
final List<Entry<String, Integer>> keyValues = new ArrayList<Entry<String, Integer>>(
stringReg.entrySet());
int currentIndex = 0;
int lastWrittenIndex = 0;
final ByteBuffer buffer = ByteBuffer.allocate(Constants.SENDING_BUFFER_SIZE);
while (currentIndex < keyValues.size()) {
final ByteBuffer buffer = ByteBuffer.allocate(Constants.SENDING_BUFFER_SIZE);
final Entry<String, Integer> entry = keyValues.get(currentIndex);
final byte[] keyAsBytes = entry.getKey().getBytes();
while (buffer.remaining() >= (keyValues.get(currentIndex).getKey().getBytes().length + StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID)) {
final Entry<String, Integer> entry = keyValues.get(currentIndex);
while (buffer.remaining() >= (keyAsBytes.length + StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID)) {
buffer.put(StringRegistryRecord.CLAZZ_ID);
buffer.putInt(entry.getValue());
final byte[] keyAsBytes = entry.getKey().getBytes();
buffer.putInt(keyAsBytes.length);
buffer.put(keyAsBytes);
currentIndex++;
......@@ -83,16 +84,27 @@ public class MonitoringStringRegistry {
break;
}
}
if (lastWrittenIndex == currentIndex) {
System.out
.println("No progress in sendOutAllStringRegistry. Buffer size: "
+ buffer.remaining()
+ " and wanted to write: "
+ (keyAsBytes.length + StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID));
}
lastWrittenIndex = currentIndex;
buffer.flip();
socketChannel.write(buffer);
if (debug) {
debugWriter.writeBuffer(buffer);
while (buffer.hasRemaining()) {
socketChannel.write(buffer);
}
buffer.clear();
}
}
public static void reset() {
stringReg.clear();
stringRegIndex.set(0);
stringRegIndex.set(1);
}
}
......@@ -20,7 +20,7 @@ import explorviz.live_trace_processing.main.MonitoringStringRegistry;
import explorviz.live_trace_processing.record.trace.HostApplicationMetaDataRecord;
public class TCPWriter implements IPipeReceiver<ByteBufferEvent>, IWriter,
EventHandler<ByteBufferEvent> {
EventHandler<ByteBufferEvent> {
private final boolean debug;
private DebugFileByteBufferWriter debugWriter;
......@@ -164,12 +164,7 @@ public class TCPWriter implements IPipeReceiver<ByteBufferEvent>, IWriter,
if (socketChannel.isConnected()) {
socketChannel.write(bufferForMetaData);
if (debug) {
bufferForMetaData.flip();
debugWriter.writeBuffer(bufferForMetaData);
}
MonitoringStringRegistry.sendOutAllStringRegistryRecords(socketChannel, debug,
debugWriter);
MonitoringStringRegistry.sendOutAllStringRegistryRecords(socketChannel);
metaDataSent = true;
} else {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment