diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-06 04:15:40 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-06 04:15:40 +0100 |
commit | a73cc24c3f00b1e5f2fd5dc8237d8d4c699dd676 (patch) | |
tree | 3a7add992f728cd60c933c54d0de72e1d88aed6d /src/eu/siacs/conversations/xmpp/XmppConnection.java | |
parent | 1124ded2005fa5b0b9504bac383743e31212bab7 (diff) | |
parent | 0168f185ebb209dbfb69cb19bf221354c9a8561a (diff) |
Merge branch 'watchdog'
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/XmppConnection.java')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index c426a838..ec395de3 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -66,9 +66,17 @@ public class XmppConnection implements Runnable { tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); } + + protected void changeStatus(int nextStatus) { + account.setStatus(nextStatus); + if (statusListener != null) { + statusListener.onStatusChanged(account); + } + } protected void connect() { try { + this.changeStatus(Account.STATUS_CONNECTING); Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); String srvRecordServer = namePort.getString("name"); int srvRecordPort = namePort.getInt("port"); @@ -99,22 +107,23 @@ public class XmppConnection implements Runnable { socket.close(); } } catch (UnknownHostException e) { - account.setStatus(Account.STATUS_SERVER_NOT_FOUND); - if (statusListener != null) { - statusListener.onStatusChanged(account); + this.changeStatus(Account.STATUS_SERVER_NOT_FOUND); + if (wakeLock.isHeld()) { + wakeLock.release(); } return; } catch (IOException e) { - Log.d(LOGTAG, "bla " + e.getMessage()); - if (shouldConnect) { - Log.d(LOGTAG, account.getJid() + ": connection lost"); - account.setStatus(Account.STATUS_OFFLINE); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + this.changeStatus(Account.STATUS_OFFLINE); + if (wakeLock.isHeld()) { + wakeLock.release(); } + return; } catch (XmlPullParserException e) { + this.changeStatus(Account.STATUS_OFFLINE); Log.d(LOGTAG, "xml exception " + e.getMessage()); + if (wakeLock.isHeld()) { + wakeLock.release(); + } return; } @@ -122,18 +131,7 @@ public class XmppConnection implements Runnable { @Override public void run() { - shouldConnect = true; - while (shouldConnect) { - connect(); - try { - if (shouldConnect) { - Thread.sleep(30000); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + connect(); Log.d(LOGTAG, "end run"); } |