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.packet.Packet;
022
023/**
024 * Provides a mechanism to listen for packets that pass a specified filter.
025 * This allows event-style programming -- every time a new packet is found,
026 * the {@link #processPacket(Packet)} method will be called. This is the
027 * opposite approach to the functionality provided by a {@link PacketCollector}
028 * which lets you block while waiting for results.
029 *
030 * @see XMPPConnection#addPacketListener(PacketListener, org.jivesoftware.smack.filter.PacketFilter)
031 * @author Matt Tucker
032 */
033public interface PacketListener {
034
035    /**
036     * Process the next packet sent to this packet listener.<p>
037     *
038     * A single thread is responsible for invoking all listeners, so
039     * it's very important that implementations of this method not block
040     * for any extended period of time.
041     *
042     * @param packet the packet to process.
043     */
044    public void processPacket(Packet packet) throws NotConnectedException;
045
046}