Search in sources :

Example 1 with Condition

use of org.jivesoftware.smack.packet.StanzaError.Condition in project Smack by igniterealtime.

the class Roster method reload.

/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * @throws NotLoggedInException If not logged in.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void reload() throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    RosterPacket packet = new RosterPacket();
    if (rosterStore != null && isRosterVersioningSupported()) {
        packet.setVersion(rosterStore.getRosterVersion());
    }
    rosterState = RosterState.loading;
    SmackFuture<IQ, Exception> future = connection.sendIqRequestAsync(packet);
    future.onSuccess(new RosterResultListener()).onError(new ExceptionCallback<Exception>() {

        @Override
        public void processException(Exception exception) {
            rosterState = RosterState.uninitialized;
            Level logLevel = Level.SEVERE;
            if (exception instanceof NotConnectedException) {
                logLevel = Level.FINE;
            } else if (exception instanceof XMPPErrorException) {
                Condition condition = ((XMPPErrorException) exception).getStanzaError().getCondition();
                if (condition == Condition.feature_not_implemented || condition == Condition.service_unavailable) {
                    logLevel = Level.FINE;
                }
            }
            LOGGER.log(logLevel, "Exception reloading roster", exception);
            for (RosterLoadedListener listener : rosterLoadedListeners) {
                listener.onRosterLoadingFailed(exception);
            }
        }
    });
}
Also used : Condition(org.jivesoftware.smack.packet.StanzaError.Condition) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection) SmackException(org.jivesoftware.smack.SmackException) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) Level(java.util.logging.Level)

Aggregations

Level (java.util.logging.Level)1 SmackException (org.jivesoftware.smack.SmackException)1 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 IQ (org.jivesoftware.smack.packet.IQ)1 Condition (org.jivesoftware.smack.packet.StanzaError.Condition)1 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)1