Added timeout

This commit is contained in:
Jens 2021-02-26 23:09:24 +01:00
parent 016dbb5406
commit 4f5db24e76
3 changed files with 58 additions and 4 deletions

View File

@ -6,12 +6,12 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_191/lib/missioncontrol/plugins/com.jrockit.mc.rjmx_5.5.2.174165/lib/mailapi.jar">
<classpathentry kind="lib" path="C:/Users/Jens/Documents/Entwicklung/Eclipse workspace/libs/mailapi-1.5.0.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_191/lib/missioncontrol/plugins/com.jrockit.mc.rjmx_5.5.2.174165/lib/smtp.jar">
<classpathentry kind="lib" path="C:/Users/Jens/Documents/Entwicklung/Eclipse workspace/libs/smtp-1.5.0.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>

View File

@ -212,14 +212,16 @@ public class GUI
if(MqttTopic.isMatched(Settings.topicNameWakewordRecognized, topic))
{
// Turn on screen....
turnScreenOn();
textEntriesList.clear();
textEntriesList.add(getMeString() + "Hello! What can I do for you?");
updateWindow();
}
else if(MqttTopic.isMatched(Settings.topicNameIntentsRecognized, topic))
{
JSONObject jo = new JSONObject(payload);
textEntriesList.clear();
textEntriesList.add(getYouString() + jo.getString("input"));
updateWindow();
}
@ -257,10 +259,17 @@ public class GUI
else if(MqttTopic.isMatched(Settings.topicNameSessionEnded, topic))
{
textEntriesList.clear();
textEntriesList.add("Waiting for session...");
updateWindow();
}
}
private void turnScreenOn()
{
// TODO Auto-generated method stub
}
static String getYouString()
{
return "You: \t";

View File

@ -1,6 +1,8 @@
package com.jens.rhasspy.visualtool;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
@ -9,6 +11,8 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import com.jens.rhasspy.visualtool.lib.JSONObject;
public class MQTT implements MqttCallbackExtended
@ -29,8 +33,13 @@ public class MQTT implements MqttCallbackExtended
final static String clientId = "RhasspyVisualConversationTool";
final static int maximumReconnectionAttempts = -1;
final static long timeout = 10000;
protected static boolean forceReconnection = false;
Timer timeoutTimer = null;
static String getServerUri()
{
if(Settings.mqttClientUseSsl)
@ -164,6 +173,11 @@ public class MQTT implements MqttCallbackExtended
MqttMessageDistributor mmd = new MqttMessageDistributor(topic, message);
Thread worker = new Thread(mmd);
worker.start();
if(MqttTopic.isMatched(Settings.topicNameSessionEnded, topic))
unscheduleTimeout();
else
scheduleTimeout();
}
class MqttMessageDistributor implements Runnable
@ -247,4 +261,35 @@ public class MQTT implements MqttCallbackExtended
GUI.getInstance().updateConnectionStatus(true);
}
void scheduleTimeout()
{
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
Object[] object = new Object[3];
object[0] = new MqttMessage();
object[1] = Settings.topicNameSessionEnded;
object[2] = Calendar.getInstance();
GUI.getInstance().handleNewMessage(object);
}
};
// if(timeoutTimer == null)
timeoutTimer = new Timer();
// else
// timeoutTimer.cancel();
timeoutTimer.schedule(timerTask, timeout);
}
void unscheduleTimeout()
{
if(timeoutTimer != null)
timeoutTimer.cancel();
}
}