Java 类org.jivesoftware.smack.sm.StreamManagementException 实例源码

项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Add a new Stanza ID acknowledged listener for the given ID.
 * <p>
 * The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will
 * automatically be removed after the listener was run.
 * </p>
 * 
 * @param id the stanza ID.
 * @param listener the listener to invoke.
 * @return the previous listener for this stanza ID or null.
 * @throws StreamManagementNotEnabledException if Stream Management is not enabled.
 */
public StanzaListener addStanzaIdAcknowledgedListener(final String id, StanzaListener listener) throws StreamManagementNotEnabledException {
    // Prevent users from adding callbacks that will never get removed
    if (!smWasEnabledAtLeastOnce) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    // Remove the listener after max. 12 hours
    final int removeAfterSeconds = Math.min(getMaxSmResumptionTime(), 12 * 60 * 60);
    schedule(new Runnable() {
        @Override
        public void run() {
            stanzaIdAcknowledgedListeners.remove(id);
        }
    }, removeAfterSeconds, TimeUnit.SECONDS);
    return stanzaIdAcknowledgedListeners.put(id, listener);
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Add a new Stanza ID acknowledged listener for the given ID.
 * <p>
 * The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will
 * automatically be removed after the listener was run.
 * </p>
 *
 * @param id the stanza ID.
 * @param listener the listener to invoke.
 * @return the previous listener for this stanza ID or null.
 * @throws StreamManagementNotEnabledException if Stream Management is not enabled.
 */
public StanzaListener addStanzaIdAcknowledgedListener(final String id, StanzaListener listener) throws StreamManagementNotEnabledException {
    // Prevent users from adding callbacks that will never get removed
    if (!smWasEnabledAtLeastOnce) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    // Remove the listener after max. 12 hours
    final int removeAfterSeconds = Math.min(getMaxSmResumptionTime(), 12 * 60 * 60);
    schedule(new Runnable() {
        @Override
        public void run() {
            stanzaIdAcknowledgedListeners.remove(id);
        }
    }, removeAfterSeconds, TimeUnit.SECONDS);
    return stanzaIdAcknowledgedListeners.put(id, listener);
}
项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Send an unconditional Stream Management acknowledgement request to the server.
 *
 * @throws StreamManagementNotEnabledException if Stream Mangement is not enabled.
 * @throws NotConnectedException if the connection is not connected.
 */
public void requestSmAcknowledgement() throws StreamManagementNotEnabledException, NotConnectedException {
    if (!isSmEnabled()) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    requestSmAcknowledgementInternal();
}
项目:androidclient    文件:MessageCenterService.java   
boolean sendMessage(org.jivesoftware.smack.packet.Message message, long databaseId) {
    final KontalkConnection conn = mConnection;
    if (conn != null) {
        if (databaseId > 0) {
            // set up an ack listener so we can set message status to sent
            try {
                conn.addStanzaIdAcknowledgedListener(message.getStanzaId(),
                    new MessageAckListener(this, databaseId));
            }
            catch (StreamManagementException.StreamManagementNotEnabledException e) {
                return false;
            }

            // matching release is in SM ack listener
            mIdleHandler.hold(false);
            mWaitingReceipt.add(databaseId);
        }

        boolean sent = sendPacket(message);
        if (!sent && databaseId > 0) {
            // message was not sent, remove from waiting queue
            mWaitingReceipt.remove(databaseId);
            mIdleHandler.release();
        }

        return sent;
    }
    return false;
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Creates a new XMPP connection over TCP (optionally using proxies).
 * <p>
 * Note that XMPPTCPConnection constructors do not establish a connection to the server
 * and you must call {@link #connect()}.
 * </p>
 *
 * @param config the connection configuration.
 */
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
    super(config);
    this.config = config;
    addConnectionListener(new AbstractConnectionListener() {
        @Override
        public void connectionClosedOnError(Exception e) {
            if (e instanceof XMPPException.StreamErrorException || e instanceof StreamManagementException) {
                dropSmState();
            }
        }
    });
}
项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Send a unconditional Stream Management acknowledgment to the server.
 * <p>
 * See <a href="http://xmpp.org/extensions/xep-0198.html#acking">XEP-198: Stream Management § 4. Acks</a>:
 * "Either party MAY send an <a/> element at any time (e.g., after it has received a certain number of stanzas,
 * or after a certain period of time), even if it has not received an <r/> element from the other party."
 * </p>
 * 
 * @throws StreamManagementNotEnabledException if Stream Management is not enabled.
 * @throws NotConnectedException if the connection is not connected.
 */
public void sendSmAcknowledgement() throws StreamManagementNotEnabledException, NotConnectedException {
    if (!isSmEnabled()) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    sendSmAcknowledgementInternal();
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Send an unconditional Stream Management acknowledgement request to the server.
 *
 * @throws StreamManagementNotEnabledException if Stream Mangement is not enabled.
 * @throws NotConnectedException if the connection is not connected.
 * @throws InterruptedException
 */
public void requestSmAcknowledgement() throws StreamManagementNotEnabledException, NotConnectedException, InterruptedException {
    if (!isSmEnabled()) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    requestSmAcknowledgementInternal();
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Send a unconditional Stream Management acknowledgment to the server.
 * <p>
 * See <a href="http://xmpp.org/extensions/xep-0198.html#acking">XEP-198: Stream Management § 4. Acks</a>:
 * "Either party MAY send an <a/> element at any time (e.g., after it has received a certain number of stanzas,
 * or after a certain period of time), even if it has not received an <r/> element from the other party."
 * </p>
 *
 * @throws StreamManagementNotEnabledException if Stream Management is not enabled.
 * @throws NotConnectedException if the connection is not connected.
 * @throws InterruptedException
 */
public void sendSmAcknowledgement() throws StreamManagementNotEnabledException, NotConnectedException, InterruptedException {
    if (!isSmEnabled()) {
        throw new StreamManagementException.StreamManagementNotEnabledException();
    }
    sendSmAcknowledgementInternal();
}