Skip to content

Commit

Permalink
Add sender thread restart to main look, fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian S. committed May 17, 2020
1 parent b19f99c commit 022fa8c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/de/csdev/ebus/core/EBusEbusdController.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,15 @@ private ByteBuffer parseLine(String readLine) throws IOException, InterruptedExc
if (readLine.startsWith("-s")) {

String tmp = readLine.substring(3, 5) + readLine.substring(6);
QueueEntry queueEntry = queue.getCurrent();

currentSendId = queue.getCurrent().id;
// maybe the command is direct from ebusd and the binding
if (queueEntry != null) {
currentSendId = queueEntry.id;

// remove this entry from queue
queue.resetSendQueue();
// remove this entry from queue
queue.resetSendQueue();
}

if (readLine.contains(":")) {
String[] split = tmp.split(":");
Expand Down Expand Up @@ -254,6 +258,11 @@ public void run() {
reconnect();
}

if (senderThread == null || !senderThread.isAlive()) {
// should not happened, but maybe it can help
startSenderThread();
}

String readLine = reader.readLine();

// reset send id before parsing
Expand All @@ -275,9 +284,6 @@ public void run() {
this.fireOnEBusDataException(e, currentSendId);

} catch (InterruptedIOException e) {
// re-enable the interrupt to stop the while loop
// Thread.currentThread().interrupt();

// disable the interrupt, can be a simple java.net.SocketTimeoutException: Read timed out

} catch (InterruptedException e) {
Expand Down

0 comments on commit 022fa8c

Please sign in to comment.