use of org.awesomeapp.messenger.model.ImErrorInfo in project Zom-Android by zom.
the class XmppConnection method reconnect.
/*
* Retry connecting
*
* Runs in executor thread
*/
private void reconnect() {
if (getState() == SUSPENDED) {
debug(TAG, "reconnect during suspend, ignoring");
return;
}
if (mConnection != null) {
// It is safe to ask mConnection whether it is connected, because either:
// - We detected an error using ping and called force_reconnect, which did a shutdown
// - Smack detected an error, so it knows it is not connected
// so there are no cases where mConnection can be confused about being connected here.
// The only left over cases are reconnect() being called too many times due to errors
// reported multiple times or errors reported during a forced reconnect.
// The analysis above is incorrect in the case where Smack loses connectivity
// while trying to log in. This case is handled in a future heartbeat
// by checking ping responses.
clearPing();
if (mConnection != null && mConnection.isAuthenticated()) {
debug(TAG, "reconnect while already connected, assuming good: " + mConnection);
mNeedReconnect = false;
setState(LOGGED_IN, null);
return;
}
debug(TAG, "reconnect");
try {
if (mStreamHandler.isResumePossible()) {
// Connect without binding, will automatically trigger a resume
debug(TAG, "mStreamHandler resume");
mConnection.connect();
initServiceDiscovery();
initPacketProcessor();
} else {
debug(TAG, "reconnection on network change failed: " + mUser.getAddress().getAddress());
mConnection = null;
mNeedReconnect = true;
setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, null));
do_login();
}
} catch (Exception e) {
if (mStreamHandler != null)
mStreamHandler.quickShutdown();
mConnection = null;
debug(TAG, "reconnection attempt failed", e);
// Smack incorrectly notified us that reconnection was successful, reset in case it fails
mNeedReconnect = false;
setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, e.getMessage()));
do_login();
}
} else {
mNeedReconnect = false;
mConnection = null;
debug(TAG, "reconnection on network change failed");
setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, "reconnection on network change failed"));
do_login();
}
}
use of org.awesomeapp.messenger.model.ImErrorInfo in project Zom-Android by zom.
the class ChatSessionManagerAdapter method createChatSession.
public IChatSession createChatSession(String contactAddress, boolean isNewSession) {
ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
Contact contact = listManager.getContactByAddress(Address.stripResource(contactAddress));
if (contact == null) {
try {
contact = new Contact(new XmppAddress(contactAddress), contactAddress, Imps.Contacts.TYPE_NORMAL);
// long contactId = listManager.queryOrInsertContact(contact);
// String[] address = {Address.stripResource(contactAddress)};
// contact = listManager.createTemporaryContacts(address)[0];
} catch (IllegalArgumentException e) {
mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress, new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
return null;
}
}
if (contact != null) {
ChatSession session = getChatSessionManager().createChatSession(contact, isNewSession);
return getChatSessionAdapter(session, isNewSession);
} else
return null;
}
Aggregations