@Override
public void run() {
logger.info("SenderThread is running");
while (!this.shouldExit && this.jgbxc.isConnected()) {
try {
final RequestContainer requestC = this.requestQueue.poll(POLLING_TIMEOUT, TimeUnit.MILLISECONDS);
if (requestC == null) {
continue;
}
final String message = requestC.getRequest().toXML();
logger.debug("Sending request: [" + message.length() + "] [" + requestC.getHandle() + "] " + message);
final byte[] messageBytes = message.getBytes(Charset.forName("UTF-8"));
final Integer messageLength = messageBytes.length;
final byte[] messageLengthBytes = ByteOrderUtils.integerToLittleEndianess(messageLength);
final byte[] messageHandleBytes = ByteOrderUtils.integerToLittleEndianess(requestC.getHandle());
try {
this.outputStream.write(messageLengthBytes);
this.outputStream.write(messageHandleBytes);
this.outputStream.write(messageBytes);