/** * Returns real full jid, that was assigned while login. * * @return <code>null</code> if connection is not established. */ public String getRealJid() { ConnectionThread connectionThread = getConnectionThread(); if (connectionThread == null) return null; XMPPConnection xmppConnection = connectionThread.getXMPPConnection(); if (xmppConnection == null) return null; String user = xmppConnection.getUser(); if (user == null) return null; return user; }
/** * Called when disconnect should occur. * * @param connectionThread * @return <code>true</code> if connection thread was managed. */ private boolean onDisconnect(ConnectionThread connectionThread) { XMPPConnection xmppConnection = connectionThread.getXMPPConnection(); boolean acceptable = isManaged(connectionThread); if (xmppConnection == null) LogManager.i(this, "onClose " + acceptable); else LogManager.i( this, "onClose " + xmppConnection.hashCode() + " - " + xmppConnection.connectionCounterValue + ", " + acceptable); ConnectionManager.getInstance().onDisconnect(connectionThread); if (acceptable) connectionThread.shutdown(); return acceptable; }
/** * Send packet to authenticated connection. * * @param account * @param packet */ public void sendPacket(String account, Packet packet) throws NetworkException { ConnectionThread connectionThread = null; for (ConnectionThread check : managedConnections) if (check.getConnectionItem() instanceof AccountItem && ((AccountItem) check.getConnectionItem()).getAccount().equals(account)) { connectionThread = check; break; } if (connectionThread == null || !connectionThread.getConnectionItem().getState().isConnected()) throw new NetworkException(R.string.NOT_CONNECTED); XMPPConnection xmppConnection = connectionThread.getXMPPConnection(); try { xmppConnection.sendPacket(packet); } catch (IllegalStateException e) { throw new NetworkException(R.string.XMPP_EXCEPTION); } }
@Override public void onTimer() { if (NetworkManager.getInstance().getState() != NetworkState.suspended) { Collection<ConnectionItem> reconnect = new ArrayList<ConnectionItem>(); for (ConnectionThread connectionThread : managedConnections) if (connectionThread.getConnectionItem().getState().isConnected() // XMPPConnection can`t be null here && !connectionThread.getXMPPConnection().isAlive()) { LogManager.i(connectionThread.getConnectionItem(), "forceReconnect on checkAlive"); reconnect.add(connectionThread.getConnectionItem()); } for (ConnectionItem connection : reconnect) connection.forceReconnect(); } long now = new Date().getTime(); Iterator<NestedMap.Entry<RequestHolder>> iterator = requests.iterator(); while (iterator.hasNext()) { NestedMap.Entry<RequestHolder> entry = iterator.next(); if (entry.getValue().isExpired(now)) { entry.getValue().getListener().onTimeout(entry.getFirst(), entry.getSecond()); iterator.remove(); } } }