Commit b25581f7 authored by Florian Fittkau's avatar Florian Fittkau

WiP

parent e88c7f79
......@@ -36,6 +36,7 @@ IRecordSender {
private final ByteBuffer stringBuffer = ByteBuffer.allocate(Constants.SENDING_BUFFER_SIZE);
private volatile boolean shouldDisconnect = false;
private volatile boolean finishedSendingStrings = false;
private final SinglePipeConnector<IRecord> tcpConnectorConnector;
......@@ -73,16 +74,19 @@ IRecordSender {
} catch (final InterruptedException e) {
}
}
finishedSendingStrings = false;
socketChannel = SocketChannel.open(new InetSocketAddress(getProviderURL().getHost(),
getProviderURL().getPort()));
stringRegistry.sendOutAllStringRegistryRecords();
finishedSendingStrings = true;
}
@Override
public void sendOutStringRecord(final StringRegistryRecord record) {
record.putIntoByteBuffer(stringBuffer, stringRegistry, this);
send(stringBuffer);
prioritizedSend(stringBuffer);
}
@Override
......@@ -113,7 +117,8 @@ IRecordSender {
@Override
public void send(final ByteBuffer buffer) {
while ((socketChannel == null) || (!socketChannel.isConnected())) {
while ((socketChannel == null) || (!socketChannel.isConnected())
|| (!finishedSendingStrings)) {
try {
Thread.sleep(1);
} catch (final InterruptedException e) {
......@@ -137,6 +142,32 @@ IRecordSender {
}
}
public void prioritizedSend(final ByteBuffer buffer) {
while ((socketChannel == null) || (!socketChannel.isConnected())) {
try {
Thread.sleep(1);
} catch (final InterruptedException e) {
}
}
try {
buffer.flip();
while (buffer.hasRemaining()) {
socketChannel.write(buffer);
}
doDisconnectIfNessecary();
} catch (final IOException e) {
System.out
.println("WARNING: Connection was closed during String sending - possible data loss");
try {
socketChannel.close();
} catch (final IOException e1) {
}
} finally {
buffer.clear();
}
}
private void doDisconnectIfNessecary() {
if (shouldDisconnect) {
if ((socketChannel != null) && socketChannel.isConnected()) {
......
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