Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testMatchedTopicFilterWildcards() throws Exception {
String[][] matchingTopics = new String[][] { { "sport/tennis/player1/#", "sport/tennis/player1" },
{ "sport/tennis/player1/#", "sport/tennis/player1/ranking" },
{ "sport/tennis/player1/#", "sport/tennis/player1/score/wimbledon" }, { "sport/#", "sport" },
{ "#", "sport/tennis/player1" } };
{ "#", "sport/tennis/player1" } , {"sport/+/player1/ranking/#","sport/tennis/player1/ranking"} };

for (String[] pair : matchingTopics) {
Assert.assertTrue(pair[0] + " should match " + pair[1], MqttTopicValidator.isMatched(pair[0], pair[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*/
public class CommsCallback implements Runnable {
private static final String CLASS_NAME = CommsCallback.class.getName();
private static final int MAX_STOPPED_STATE_TO_STOP_THREAD = 300; //30s
private Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);

private static final int INBOUND_QUEUE_SIZE = 10;
Expand Down Expand Up @@ -119,8 +120,16 @@ public void start(String threadName, ExecutorService executorService) {
}
}
}
AtomicInteger stoppedStateCounter = new AtomicInteger(0);
while (!isRunning()) {
try { Thread.sleep(100); } catch (Exception e) { }
if (current_state == State.STOPPED) {
if (stoppedStateCounter.incrementAndGet() > MAX_STOPPED_STATE_TO_STOP_THREAD) {
break;
}
} else {
stoppedStateCounter.set(0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

import org.eclipse.paho.mqttv5.client.MqttClientException;
import org.eclipse.paho.mqttv5.client.MqttToken;
Expand All @@ -35,6 +36,7 @@
*/
public class CommsReceiver implements Runnable {
private static final String CLASS_NAME = CommsReceiver.class.getName();
private static final int MAX_STOPPED_STATE_TO_STOP_THREAD = 300; //30s
private Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);

private enum State {STOPPED, RUNNING, STARTING, RECEIVING}
Expand Down Expand Up @@ -82,8 +84,16 @@ public void start(String threadName, ExecutorService executorService) {
}
}
}
AtomicInteger stoppedStateCounter = new AtomicInteger(0);
while (!isRunning()) {
try { Thread.sleep(100); } catch (Exception e) { }
if (current_state == State.STOPPED) {
if (stoppedStateCounter.incrementAndGet() > MAX_STOPPED_STATE_TO_STOP_THREAD) {
break;
}
} else {
stoppedStateCounter.set(0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.OutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

import org.eclipse.paho.mqttv5.client.MqttClientException;
import org.eclipse.paho.mqttv5.client.MqttToken;
Expand All @@ -33,6 +34,7 @@

public class CommsSender implements Runnable {
private static final String CLASS_NAME = CommsSender.class.getName();
private static final int MAX_STOPPED_STATE_TO_STOP_THREAD = 300; //30s
private Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);

//Sends MQTT packets to the server on its own thread
Expand Down Expand Up @@ -76,8 +78,16 @@ public void start(String threadName, ExecutorService executorService) {
}
}
}
AtomicInteger stoppedStateCounter = new AtomicInteger(0);
while (!isRunning()) {
try { Thread.sleep(100); } catch (Exception e) { }
if (current_state == State.STOPPED) {
if (stoppedStateCounter.incrementAndGet() > MAX_STOPPED_STATE_TO_STOP_THREAD) {
break;
}
} else {
stoppedStateCounter.set(0);
}
}
}

Expand Down
Loading