mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
fix topic; don't try to unsubscribe or disconnect if not connected
This commit is contained in:
parent
e05a18bdbb
commit
29a6ededda
1 changed files with 19 additions and 8 deletions
|
@ -23,6 +23,7 @@ package org.eehouse.android.xw4;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
|
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
|
||||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||||
|
@ -469,16 +470,22 @@ public class MQTTUtils extends Thread
|
||||||
String action = null;
|
String action = null;
|
||||||
IMqttToken token = null;
|
IMqttToken token = null;
|
||||||
try {
|
try {
|
||||||
|
boolean isConnected = client.isConnected();
|
||||||
switch ( ii ) {
|
switch ( ii ) {
|
||||||
case 0:
|
case 0:
|
||||||
|
if ( isConnected ) {
|
||||||
action = "unsubscribe";
|
action = "unsubscribe";
|
||||||
token = client.unsubscribe( mDevID );
|
token = client.unsubscribe( mTopics );
|
||||||
|
}
|
||||||
break; // not continue, which skips the Log() below
|
break; // not continue, which skips the Log() below
|
||||||
case 1:
|
case 1:
|
||||||
|
if ( isConnected ) {
|
||||||
action = "disconnect";
|
action = "disconnect";
|
||||||
token = client.disconnect();
|
token = client.disconnect();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
Assert.assertTrueNR( !isConnected );
|
||||||
action = "close";
|
action = "close";
|
||||||
client.close();
|
client.close();
|
||||||
break;
|
break;
|
||||||
|
@ -489,13 +496,17 @@ public class MQTTUtils extends Thread
|
||||||
Log.d( TAG, "%H.disconnect(): %s() waiting", this, action );
|
Log.d( TAG, "%H.disconnect(): %s() waiting", this, action );
|
||||||
token.waitForCompletion();
|
token.waitForCompletion();
|
||||||
}
|
}
|
||||||
Log.d( TAG, "%H.disconnect(): %s() succeeded", this, action );
|
if ( null != action ) {
|
||||||
|
Log.d( TAG, "%H.run(): client.%s() succeeded", this, action );
|
||||||
|
}
|
||||||
} catch ( MqttException mex ) {
|
} catch ( MqttException mex ) {
|
||||||
Log.e( TAG, "%H.disconnect(): %s(): got mex %s",
|
Log.e( TAG, "%H.run(): client.%s(): got mex: %s",
|
||||||
this, action, mex );
|
this, action, mex );
|
||||||
|
Assert.failDbg(); // is this happening?
|
||||||
} catch ( Exception ex ) {
|
} catch ( Exception ex ) {
|
||||||
Log.e( TAG, "%H.disconnect(): %s(): got ex %s",
|
Log.e( TAG, "%H.run(): client.%s(): got ex %s",
|
||||||
this, action, ex );
|
this, action, ex );
|
||||||
|
Assert.failDbg(); // is this happening?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,7 +628,7 @@ public class MQTTUtils extends Thread
|
||||||
setState( State.SUBSCRIBING );
|
setState( State.SUBSCRIBING );
|
||||||
try {
|
try {
|
||||||
mClient.subscribe( mTopics, qoss, null, this );
|
mClient.subscribe( mTopics, qoss, null, this );
|
||||||
// Log.d( TAG, "subscribed to %s", mTopic );
|
// Log.d( TAG, "subscribed to %s", TextUtils.join( ", ", mTopics ) );
|
||||||
} catch ( MqttException ex ) {
|
} catch ( MqttException ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} catch ( Exception ex ) {
|
} catch ( Exception ex ) {
|
||||||
|
|
Loading…
Reference in a new issue