Commit 1d497c2b authored by Florian Fittkau's avatar Florian Fittkau

WiP

parent c1050e2e
......@@ -89,9 +89,9 @@ public class MonitoringController {
configuration.getIntProperty(ConfigurationFactory.LOAD_BALANCER_PORT, 9999),
configuration.getIntProperty(ConfigurationFactory.LOAD_BALANCER_WAIT_TIME,
20000),
configuration
configuration
.getStringProperty(ConfigurationFactory.LOAD_BALANCER_SCALING_GROUP),
tcpWriter);
tcpWriter);
} else {
try {
tcpWriter.connect();
......@@ -133,14 +133,15 @@ public class MonitoringController {
}
final long hiseq = ringBuffer.next();
final ByteBufferEvent valueEvent = ringBuffer.get(hiseq);
buffer.flip();
final ByteBufferEvent valueEvent = ringBuffer.get(hiseq);
final ByteBuffer oldBuffer = valueEvent.getValue();
oldBuffer.clear();
oldBuffer.put(buffer);
valueEvent.setValue(oldBuffer);
ringBuffer.publish(hiseq);
buffer.clear();
}
......@@ -163,7 +164,6 @@ public class MonitoringController {
buffer.putDouble(record.getCpuUtilization());
buffer.putLong(record.getUsedRAM());
buffer.putLong(record.getAbsoluteRAM());
valueEvent.setValue(buffer);
ringBuffer.publish(hiseq);
}
......
......@@ -16,6 +16,8 @@ public class MonitoringStringRegistry {
private static final ConcurrentHashMap<String, Integer> stringReg = new ConcurrentHashMap<String, Integer>();
private static final AtomicInteger stringRegIndex = new AtomicInteger(1);
private static final ByteBuffer sendOutSingleStringRecordBuffer = ByteBuffer
.allocate(Constants.SENDING_BUFFER_SIZE);
private static final ByteBuffer sendOutAllStringRecordsBuffer = ByteBuffer
.allocate(Constants.SENDING_BUFFER_SIZE);
......@@ -26,10 +28,10 @@ public class MonitoringStringRegistry {
final Integer wasPresent = stringReg.putIfAbsent(value, perhapsNewIndex);
if (wasPresent == null) {
final ByteBuffer stringRegistryRecord = buildStringRegistryRecord(value,
perhapsNewIndex);
MonitoringController.sendOutBuffer(stringRegistryRecord);
synchronized (sendOutSingleStringRecordBuffer) {
MonitoringController.sendOutBuffer(buildStringRegistryRecord(value,
perhapsNewIndex));
}
return perhapsNewIndex;
} else {
......@@ -50,20 +52,18 @@ public class MonitoringStringRegistry {
Integer result = stringReg.get(value);
if (result == null) {
result = stringRegIndex.getAndIncrement();
stringReg.put(value, result);
stringReg.putIfAbsent(value, result);
}
return result;
}
protected static ByteBuffer buildStringRegistryRecord(final String value, final int result) {
final byte[] valueAsBytes = value.getBytes();
final int regRecordLength = StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID
+ valueAsBytes.length;
final ByteBuffer buffer = ByteBuffer.allocate(regRecordLength);
final ByteBuffer buffer = sendOutSingleStringRecordBuffer;
buffer.put(StringRegistryRecord.CLAZZ_ID);
buffer.putInt(result);
final byte[] valueAsBytes = value.getBytes();
buffer.putInt(valueAsBytes.length);
buffer.put(valueAsBytes);
......@@ -79,9 +79,10 @@ public class MonitoringStringRegistry {
final ByteBuffer buffer = sendOutAllStringRecordsBuffer;
while (currentIndex < keyValues.size()) {
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);
final byte[] keyAsBytes = entry.getKey().getBytes();
Entry<String, Integer> entry = keyValues.get(currentIndex);
byte[] keyAsBytes = entry.getKey().getBytes();
while (buffer.remaining() >= (keyAsBytes.length + StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID)) {
buffer.put(StringRegistryRecord.CLAZZ_ID);
buffer.putInt(entry.getValue());
buffer.putInt(keyAsBytes.length);
......@@ -90,14 +91,16 @@ public class MonitoringStringRegistry {
if (currentIndex == keyValues.size()) {
break;
}
entry = keyValues.get(currentIndex);
keyAsBytes = entry.getKey().getBytes();
}
if (lastWrittenIndex == currentIndex) {
System.out
.println("No progress in sendOutAllStringRegistry. Buffer size: "
+ buffer.remaining()
+ " and wanted to write: "
+ (keyValues.get(currentIndex).getKey().getBytes().length + StringRegistryRecord.BYTE_LENGTH_WITHOUT_STRING_WITH_CLAZZ_ID));
.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;
......
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