001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smack;
019
020import org.jivesoftware.smack.SmackException.NotConnectedException;
021import org.jivesoftware.smack.SmackException.NotLoggedInException;
022import org.jivesoftware.smack.packet.Stanza;
023
024/**
025 * Provides a mechanism to listen for packets that pass a specified filter.
026 * This allows event-style programming -- every time a new stanza is found,
027 * the {@link #processStanza(Stanza)} method will be called. This is the
028 * opposite approach to the functionality provided by a {@link StanzaCollector}
029 * which lets you block while waiting for results.
030 *
031 * @see XMPPConnection#addAsyncStanzaListener(StanzaListener, org.jivesoftware.smack.filter.StanzaFilter)
032 * @author Matt Tucker
033 */
034public interface StanzaListener {
035
036    /**
037     * Process the next stanza sent to this stanza listener.
038     * <p>
039     * If this listener is synchronous, then a single thread is responsible for invoking all listeners, so
040     * it's very important that implementations of this method not block
041     * for any extended period of time.
042     * </p>
043     *
044     * @param packet the stanza to process.
045     * @throws NotConnectedException if the XMPP connection is not connected.
046     * @throws InterruptedException if the calling thread was interrupted.
047     * @throws NotLoggedInException if the XMPP connection is not authenticated.
048     */
049    void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException;
050
051}