mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
References to PacketWriterListener changed to PacketListener
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2172 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
4a8060c209
commit
7d7c02b750
6 changed files with 75 additions and 110 deletions
|
@ -55,6 +55,7 @@ package org.jivesoftware.smack;
|
|||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
||||
/**
|
||||
|
@ -122,25 +123,27 @@ class PacketWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Registers a packet writer listener with this writer. The listener will be
|
||||
* notified of every packet that this writer sends.
|
||||
* Registers a packet listener with this writer. The listener will be
|
||||
* notified of every packet that this writer sends. A packet filter determines
|
||||
* which packets will be delivered to the listener.
|
||||
*
|
||||
* @param packetWriterListener the packet writer listener to notify of sent packets.
|
||||
* @param packetListener the packet listener to notify of sent packets.
|
||||
* @param packetFilter the packet filter to use.
|
||||
*/
|
||||
public void addPacketListener(PacketWriterListener packetWriterListener) {
|
||||
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
|
||||
synchronized (listeners) {
|
||||
listeners.add(packetWriterListener);
|
||||
listeners.add(new ListenerWrapper(packetListener, packetFilter));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a packet writer listener.
|
||||
* Removes a packet listener.
|
||||
*
|
||||
* @param packetWriterListener the packet writer listener to remove.
|
||||
* @param packetListener the packet listener to remove.
|
||||
*/
|
||||
public void removePacketListener(PacketWriterListener packetWriterListener) {
|
||||
public void removePacketListener(PacketListener packetListener) {
|
||||
synchronized (listeners) {
|
||||
listeners.remove(packetWriterListener);
|
||||
listeners.remove(packetListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,11 +239,46 @@ class PacketWriter {
|
|||
// Notify the listeners of the new sent packet
|
||||
int size = listeners.size();
|
||||
for (int i=0; i<size; i++) {
|
||||
PacketWriterListener packetWriterListener = (PacketWriterListener)listeners.get(i);
|
||||
if (packetWriterListener != null) {
|
||||
packetWriterListener.processPacket(sentPacket);
|
||||
ListenerWrapper listenerWrapper = (ListenerWrapper)listeners.get(i);
|
||||
if (listenerWrapper != null) {
|
||||
listenerWrapper.notifyListener(sentPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper class to associate a packet filter with a listener.
|
||||
*/
|
||||
private static class ListenerWrapper {
|
||||
|
||||
private PacketListener packetListener;
|
||||
private PacketFilter packetFilter;
|
||||
|
||||
public ListenerWrapper(PacketListener packetListener,
|
||||
PacketFilter packetFilter)
|
||||
{
|
||||
this.packetListener = packetListener;
|
||||
this.packetFilter = packetFilter;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
if (object instanceof ListenerWrapper) {
|
||||
return ((ListenerWrapper)object).packetListener.equals(this.packetListener);
|
||||
}
|
||||
else if (object instanceof PacketListener) {
|
||||
return object.equals(this.packetListener);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void notifyListener(Packet packet) {
|
||||
if (packetFilter == null || packetFilter.accept(packet)) {
|
||||
packetListener.processPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
||||
/**
|
||||
* Provides a mechanism to listen for packets that are written to a XMPP server.
|
||||
* This allows event-style programming -- every time a new packet is written,
|
||||
* the {@link #processPacket(Packet)} method will be called.
|
||||
*
|
||||
* @see XMPPConnection#addPacketListener(PacketWriterListener)
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public interface PacketWriterListener {
|
||||
|
||||
/**
|
||||
* Process the next packet sent to this packet listener.<p>
|
||||
*
|
||||
* @param packet the packet to process.
|
||||
*/
|
||||
public void processPacket(Packet packet);
|
||||
|
||||
}
|
|
@ -570,25 +570,27 @@ public class XMPPConnection {
|
|||
}
|
||||
|
||||
/**
|
||||
* Registers a packet writer listener with this connection. The listener will be
|
||||
* notified of every packet that this connection sends.
|
||||
* Registers a packet listener with this connection. The listener will be
|
||||
* notified of every packet that this connection sends. A packet filter determines
|
||||
* which packets will be delivered to the listener.
|
||||
*
|
||||
* @param packetWriterListener the packet writer listener to notify of sent packets.
|
||||
* @param packetListener the packet listener to notify of sent packets.
|
||||
* @param packetFilter the packet filter to use.
|
||||
*/
|
||||
public void addPacketListener(PacketWriterListener packetWriterListener) {
|
||||
public void addPacketWriterListener(PacketListener packetListener, PacketFilter packetFilter) {
|
||||
if (!isConnected()) {
|
||||
throw new IllegalStateException("Not connected to server.");
|
||||
}
|
||||
packetWriter.addPacketListener(packetWriterListener);
|
||||
packetWriter.addPacketListener(packetListener, packetFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a packet writer listener from this connection.
|
||||
* Removes a packet listener from this connection.
|
||||
*
|
||||
* @param packetWriterListener the packet writer listener to remove.
|
||||
* @param packetListener the packet listener to remove.
|
||||
*/
|
||||
public void removePacketListener(PacketWriterListener packetWriterListener) {
|
||||
packetWriter.removePacketListener(packetWriterListener);
|
||||
public void removePacketWriterListener(PacketListener packetListener) {
|
||||
packetWriter.removePacketListener(packetListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -689,9 +691,9 @@ public class XMPPConnection {
|
|||
// If debugging is enabled, we should start the thread that will listen for
|
||||
// all packets and then log them.
|
||||
if (DEBUG_ENABLED) {
|
||||
packetReader.addPacketListener(debugger.getListener(), null);
|
||||
packetReader.addPacketListener(debugger.getReaderListener(), null);
|
||||
if (debugger.getWriterListener() != null) {
|
||||
packetWriter.addPacketListener(debugger.getWriterListener());
|
||||
packetWriter.addPacketListener(debugger.getWriterListener(), null);
|
||||
}
|
||||
}
|
||||
// Start the packet writer. This will open a XMPP stream to the server
|
||||
|
|
|
@ -415,11 +415,11 @@ public class LiteDebugger implements SmackDebugger {
|
|||
return writer;
|
||||
}
|
||||
|
||||
public PacketListener getListener() {
|
||||
public PacketListener getReaderListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public PacketWriterListener getWriterListener() {
|
||||
public PacketListener getWriterListener() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,13 +98,13 @@ public interface SmackDebugger {
|
|||
* @return the PacketListener that will listen for all incoming packets and write them to
|
||||
* the GUI
|
||||
*/
|
||||
public abstract PacketListener getListener();
|
||||
public abstract PacketListener getReaderListener();
|
||||
|
||||
/**
|
||||
* Returns the thread that will listen for all outgoing packets and write them to the GUI.
|
||||
*
|
||||
* @return the PacketWriterListener that will listen for all sent packets and write them to
|
||||
* @return the PacketListener that will listen for all sent packets and write them to
|
||||
* the GUI
|
||||
*/
|
||||
public abstract PacketWriterListener getWriterListener();
|
||||
public abstract PacketListener getWriterListener();
|
||||
}
|
|
@ -89,8 +89,8 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
|
||||
private XMPPConnection connection = null;
|
||||
|
||||
private PacketListener listener = null;
|
||||
private PacketWriterListener writerListener = null;
|
||||
private PacketListener readerListener = null;
|
||||
private PacketListener writerListener = null;
|
||||
private ConnectionListener connListener = null;
|
||||
|
||||
private Writer writer;
|
||||
|
@ -150,7 +150,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
// Create a thread that will listen for all incoming packets and write them to
|
||||
// the GUI. This is what we call "interpreted" packet data, since it's the packet
|
||||
// data as Smack sees it and not as it's coming in as raw XML.
|
||||
listener = new PacketListener() {
|
||||
readerListener = new PacketListener() {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");
|
||||
public void processPacket(Packet packet) {
|
||||
addReadPacketToTable(dateFormatter, packet);
|
||||
|
@ -159,7 +159,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
|
||||
// Create a thread that will listen for all outgoing packets and write them to
|
||||
// the GUI.
|
||||
writerListener = new PacketWriterListener() {
|
||||
writerListener = new PacketListener() {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa");
|
||||
public void processPacket(Packet packet) {
|
||||
addSentPacketToTable(dateFormatter, packet);
|
||||
|
@ -624,11 +624,11 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
return writer;
|
||||
}
|
||||
|
||||
public PacketListener getListener() {
|
||||
return listener;
|
||||
public PacketListener getReaderListener() {
|
||||
return readerListener;
|
||||
}
|
||||
|
||||
public PacketWriterListener getWriterListener() {
|
||||
public PacketListener getWriterListener() {
|
||||
return writerListener;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue