public synchronized void disableAutomaticReconnection() { if (this.automaticReconnectEnabled) { XMPPConnection xMPPConnection = (XMPPConnection) this.weakRefConnection.get(); if (xMPPConnection == null) { throw new IllegalStateException("Connection instance no longer available"); } xMPPConnection.removeConnectionListener(this.connectionListener); this.automaticReconnectEnabled = false; } }
public void cleanupConnection() { if (con != null) { con.removePacketListener(messagePacketListener); con.removePacketListener(presencePacketListener); if (connectionListener != null) { con.removeConnectionListener(connectionListener); } } if (isConnected()) { try { con.disconnect(); } catch (NotConnectedException e) { } } }
/** * Deletes the session agent account, frees all resources and disconnects the XMPP connection. * * @throws org.jivesoftware.smack.XMPPException */ public void shutdown() throws XMPPException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection); // ServiceDiscovery (feature) http://rn.inf.tu-dresden.de/mobilis try { sdm.removeFeature(MobilisManager.discoNamespace); } catch (Exception e) { MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " + e.getMessage()); } // ServiceDiscovery (info+items) http://rn.inf.tu-dresden.de/mobilis#services try { sdm.removeNodeInformationProvider(MobilisManager.discoServicesNode); } catch (Exception e) { MobilisManager.getLogger() .warning( "Problem with NodeInformationProvider: " + MobilisManager.discoServicesNode + " (" + getIdent() + ") " + e.getMessage()); } for (MobilisService service : mServices) { try { sdm.removeNodeInformationProvider(service.getNode()); service.shutdown(); } catch (Exception e) { // TODO Auto-generated catch block } } if ((mConnection != null) && mConnection.isConnected()) { mConnection.removeConnectionListener(this); mConnection.disconnect(); } mConnection = null; // logging MobilisManager.getLogger().info("Mobilis Agent (" + getIdent() + ") shut down."); }
@Override public void run() { if (xmppManager.isConnected() && !xmppManager.isRunning()) { Log.d(LOG_TAG, "terminatePersistentConnection()... run()"); XMPPConnection connection = xmppManager.getConnection(); try { xmppManager.setRunning(true); connection.disconnect(); connection.removePacketListener(xmppManager.getNotificationPacketListener()); connection.removeConnectionListener(xmppManager.getConnectionListener()); callback.onSuccess(); } catch (Exception e) { Log.e(LOG_TAG, "XMPP disconnection failed", e); callback.onFailed("XMPP disconnection failed"); } finally { xmppManager.setRunning(false); } } else { Log.w(LOG_TAG, "XMPP is not connected or is running"); callback.onFailed("XMPP is not connected or is running"); } }
/** @see net.sf.kraken.session.TransportSession#cleanUp() */ @Override public void cleanUp() { if (timer != null) { try { timer.cancel(); } catch (Exception e) { // Ignore } timer = null; } if (mailCheck != null) { try { mailCheck.cancel(); } catch (Exception e) { // Ignore } mailCheck = null; } if (conn != null) { try { conn.removeConnectionListener(listener); } catch (Exception e) { // Ignore } try { conn.removePacketListener(listener); } catch (Exception e) { // Ignore } try { conn.removePacketListener(presenceHandler); } catch (Exception e) { // Ignore } try { conn.getChatManager().removeChatListener(listener); } catch (Exception e) { // Ignore } try { conn.getRoster().removeRosterListener(listener); } catch (Exception e) { // Ignore } try { conn.disconnect(); } catch (Exception e) { // Ignore } } conn = null; listener = null; presenceHandler = null; if (runThread != null) { try { runThread.interrupt(); } catch (Exception e) { // Ignore } runThread = null; } }