mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
SMACK-279: The XMPPConnection extends the new abstract Connection class
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11613 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
11a41e79ca
commit
127319a821
102 changed files with 1420 additions and 1194 deletions
|
@ -26,7 +26,7 @@ import java.util.LinkedList;
|
|||
|
||||
/**
|
||||
* A variant of the {@link org.jivesoftware.smack.PacketCollector} class
|
||||
* that does not force attachment to an <code>XMPPConnection</code>
|
||||
* that does not force attachment to a <code>Connection</code>
|
||||
* on creation and no filter is required. Used to collect message
|
||||
* packets targeted to a group chat room.
|
||||
*
|
||||
|
|
|
@ -25,9 +25,9 @@ import org.jivesoftware.smackx.packet.DiscoverItems;
|
|||
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
|
||||
* directory . The information that may be discovered is the XMPP address of the room and the room
|
||||
* name. The address of the room may be used for obtaining more detailed information
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.XMPPConnection, String)}
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.Connection, String)}
|
||||
* or could be used for joining the room
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.XMPPConnection, String)}
|
||||
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.Connection, String)}
|
||||
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
/**
|
||||
|
@ -36,14 +36,14 @@ public interface InvitationListener {
|
|||
* If the room is password-protected, the invitee will receive a password to use to join
|
||||
* the room. If the room is members-only, the the invitee may be added to the member list.
|
||||
*
|
||||
* @param conn the XMPPConnection that received the invitation.
|
||||
* @param conn the Connection that received the invitation.
|
||||
* @param room the room that invitation refers to.
|
||||
* @param inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
|
||||
* @param reason the reason why the inviter sent the invitation.
|
||||
* @param password the password to use when joining the room.
|
||||
* @param message the message used by the inviter to send the invitation.
|
||||
*/
|
||||
public abstract void invitationReceived(XMPPConnection conn, String room, String inviter, String reason,
|
||||
public abstract void invitationReceived(Connection conn, String room, String inviter, String reason,
|
||||
String password, Message message);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.jivesoftware.smack.PacketCollector;
|
|||
import org.jivesoftware.smack.PacketInterceptor;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
||||
|
@ -79,10 +79,10 @@ public class MultiUserChat {
|
|||
private final static String discoNamespace = "http://jabber.org/protocol/muc";
|
||||
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
|
||||
|
||||
private static Map<XMPPConnection, List<String>> joinedRooms =
|
||||
new WeakHashMap<XMPPConnection, List<String>>();
|
||||
private static Map<Connection, List<String>> joinedRooms =
|
||||
new WeakHashMap<Connection, List<String>>();
|
||||
|
||||
private XMPPConnection connection;
|
||||
private Connection connection;
|
||||
private String room;
|
||||
private String subject;
|
||||
private String nickname = null;
|
||||
|
@ -106,8 +106,8 @@ public class MultiUserChat {
|
|||
private List<PacketListener> connectionListeners = new ArrayList<PacketListener>();
|
||||
|
||||
static {
|
||||
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
public void connectionCreated(final XMPPConnection connection) {
|
||||
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
public void connectionCreated(final Connection connection) {
|
||||
// Set on every established connection that this client supports the Multi-User
|
||||
// Chat protocol. This information will be used when another client tries to
|
||||
// discover whether this client supports MUC or not.
|
||||
|
@ -153,7 +153,7 @@ public class MultiUserChat {
|
|||
* "service" is the hostname at which the multi-user chat
|
||||
* service is running. Make sure to provide a valid JID.
|
||||
*/
|
||||
public MultiUserChat(XMPPConnection connection, String room) {
|
||||
public MultiUserChat(Connection connection, String room) {
|
||||
this.connection = connection;
|
||||
this.room = room.toLowerCase();
|
||||
init();
|
||||
|
@ -166,7 +166,7 @@ public class MultiUserChat {
|
|||
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
|
||||
* @return a boolean indicating whether the specified user supports the MUC protocol.
|
||||
*/
|
||||
public static boolean isServiceEnabled(XMPPConnection connection, String user) {
|
||||
public static boolean isServiceEnabled(Connection connection, String user) {
|
||||
try {
|
||||
DiscoverInfo result =
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(user);
|
||||
|
@ -186,7 +186,7 @@ public class MultiUserChat {
|
|||
* @param connection the connection used to join the rooms.
|
||||
* @return an Iterator on the rooms where the user has joined using a given connection.
|
||||
*/
|
||||
private static Iterator<String> getJoinedRooms(XMPPConnection connection) {
|
||||
private static Iterator<String> getJoinedRooms(Connection connection) {
|
||||
List<String> rooms = joinedRooms.get(connection);
|
||||
if (rooms != null) {
|
||||
return rooms.iterator();
|
||||
|
@ -203,7 +203,7 @@ public class MultiUserChat {
|
|||
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
|
||||
* @return an Iterator on the rooms where the requested user has joined.
|
||||
*/
|
||||
public static Iterator<String> getJoinedRooms(XMPPConnection connection, String user) {
|
||||
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
|
||||
try {
|
||||
ArrayList<String> answer = new ArrayList<String>();
|
||||
// Send the disco packet to the user
|
||||
|
@ -232,7 +232,7 @@ public class MultiUserChat {
|
|||
* @return the discovered information of a given room without actually having to join the room.
|
||||
* @throws XMPPException if an error occured while trying to discover information of a room.
|
||||
*/
|
||||
public static RoomInfo getRoomInfo(XMPPConnection connection, String room)
|
||||
public static RoomInfo getRoomInfo(Connection connection, String room)
|
||||
throws XMPPException {
|
||||
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(room);
|
||||
return new RoomInfo(info);
|
||||
|
@ -245,7 +245,7 @@ public class MultiUserChat {
|
|||
* @return a collection with the XMPP addresses of the Multi-User Chat services.
|
||||
* @throws XMPPException if an error occured while trying to discover MUC services.
|
||||
*/
|
||||
public static Collection<String> getServiceNames(XMPPConnection connection) throws XMPPException {
|
||||
public static Collection<String> getServiceNames(Connection connection) throws XMPPException {
|
||||
final List<String> answer = new ArrayList<String>();
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
|
||||
|
@ -275,7 +275,7 @@ public class MultiUserChat {
|
|||
* @return a collection of HostedRooms.
|
||||
* @throws XMPPException if an error occured while trying to discover the information.
|
||||
*/
|
||||
public static Collection<HostedRoom> getHostedRooms(XMPPConnection connection, String serviceName)
|
||||
public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName)
|
||||
throws XMPPException {
|
||||
List<HostedRoom> answer = new ArrayList<HostedRoom>();
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
@ -768,7 +768,7 @@ public class MultiUserChat {
|
|||
* @param inviter the inviter of the declined invitation.
|
||||
* @param reason the reason why the invitee is declining the invitation.
|
||||
*/
|
||||
public static void decline(XMPPConnection conn, String room, String inviter, String reason) {
|
||||
public static void decline(Connection conn, String room, String inviter, String reason) {
|
||||
Message message = new Message(room);
|
||||
|
||||
// Create the MUCUser packet that will include the rejection
|
||||
|
@ -790,7 +790,7 @@ public class MultiUserChat {
|
|||
* @param conn the connection where the listener will be applied.
|
||||
* @param listener an invitation listener.
|
||||
*/
|
||||
public static void addInvitationListener(XMPPConnection conn, InvitationListener listener) {
|
||||
public static void addInvitationListener(Connection conn, InvitationListener listener) {
|
||||
InvitationsMonitor.getInvitationsMonitor(conn).addInvitationListener(listener);
|
||||
}
|
||||
|
||||
|
@ -801,7 +801,7 @@ public class MultiUserChat {
|
|||
* @param conn the connection where the listener was applied.
|
||||
* @param listener an invitation listener.
|
||||
*/
|
||||
public static void removeInvitationListener(XMPPConnection conn, InvitationListener listener) {
|
||||
public static void removeInvitationListener(Connection conn, InvitationListener listener) {
|
||||
InvitationsMonitor.getInvitationsMonitor(conn).removeInvitationListener(listener);
|
||||
}
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ public class MultiUserChat {
|
|||
* group chat. Only "group chat" messages addressed to this group chat will
|
||||
* be delivered to the listener. If you wish to listen for other packets
|
||||
* that may be associated with this group chat, you should register a
|
||||
* PacketListener directly with the XMPPConnection with the appropriate
|
||||
* PacketListener directly with the Connection with the appropriate
|
||||
* PacketListener.
|
||||
*
|
||||
* @param listener a packet listener.
|
||||
|
@ -2555,12 +2555,12 @@ public class MultiUserChat {
|
|||
private static class InvitationsMonitor implements ConnectionListener {
|
||||
// We use a WeakHashMap so that the GC can collect the monitor when the
|
||||
// connection is no longer referenced by any object.
|
||||
private final static Map<XMPPConnection, WeakReference<InvitationsMonitor>> monitors =
|
||||
new WeakHashMap<XMPPConnection, WeakReference<InvitationsMonitor>>();
|
||||
private final static Map<Connection, WeakReference<InvitationsMonitor>> monitors =
|
||||
new WeakHashMap<Connection, WeakReference<InvitationsMonitor>>();
|
||||
|
||||
private final List<InvitationListener> invitationsListeners =
|
||||
new ArrayList<InvitationListener>();
|
||||
private XMPPConnection connection;
|
||||
private Connection connection;
|
||||
private PacketFilter invitationFilter;
|
||||
private PacketListener invitationPacketListener;
|
||||
|
||||
|
@ -2570,7 +2570,7 @@ public class MultiUserChat {
|
|||
* @param conn the connection to monitor for room invitations.
|
||||
* @return a new or existing InvitationsMonitor for a given connection.
|
||||
*/
|
||||
public static InvitationsMonitor getInvitationsMonitor(XMPPConnection conn) {
|
||||
public static InvitationsMonitor getInvitationsMonitor(Connection conn) {
|
||||
synchronized (monitors) {
|
||||
if (!monitors.containsKey(conn)) {
|
||||
// We need to use a WeakReference because the monitor references the
|
||||
|
@ -2589,7 +2589,7 @@ public class MultiUserChat {
|
|||
*
|
||||
* @param connection the connection to monitor for possible room invitations
|
||||
*/
|
||||
private InvitationsMonitor(XMPPConnection connection) {
|
||||
private InvitationsMonitor(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.jivesoftware.smackx.muc;
|
|||
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
@ -34,9 +34,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
/**
|
||||
* A <code>RoomListenerMultiplexor</code> multiplexes incoming packets on
|
||||
* an <code>XMPPConnection</code> using a single listener/filter pair.
|
||||
* a <code>Connection</code> using a single listener/filter pair.
|
||||
* A single <code>RoomListenerMultiplexor</code> is created for each
|
||||
* {@link org.jivesoftware.smack.XMPPConnection} that has joined MUC rooms
|
||||
* {@link org.jivesoftware.smack.Connection} that has joined MUC rooms
|
||||
* within its session.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
|
@ -45,10 +45,10 @@ class RoomListenerMultiplexor implements ConnectionListener {
|
|||
|
||||
// We use a WeakHashMap so that the GC can collect the monitor when the
|
||||
// connection is no longer referenced by any object.
|
||||
private static final Map<XMPPConnection, WeakReference<RoomListenerMultiplexor>> monitors =
|
||||
new WeakHashMap<XMPPConnection, WeakReference<RoomListenerMultiplexor>>();
|
||||
private static final Map<Connection, WeakReference<RoomListenerMultiplexor>> monitors =
|
||||
new WeakHashMap<Connection, WeakReference<RoomListenerMultiplexor>>();
|
||||
|
||||
private XMPPConnection connection;
|
||||
private Connection connection;
|
||||
private RoomMultiplexFilter filter;
|
||||
private RoomMultiplexListener listener;
|
||||
|
||||
|
@ -58,7 +58,7 @@ class RoomListenerMultiplexor implements ConnectionListener {
|
|||
* @param conn the connection to monitor for room invitations.
|
||||
* @return a new or existing RoomListenerMultiplexor for a given connection.
|
||||
*/
|
||||
public static RoomListenerMultiplexor getRoomMultiplexor(XMPPConnection conn) {
|
||||
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
|
||||
synchronized (monitors) {
|
||||
if (!monitors.containsKey(conn)) {
|
||||
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
|
||||
|
@ -78,9 +78,9 @@ class RoomListenerMultiplexor implements ConnectionListener {
|
|||
|
||||
/**
|
||||
* All access should be through
|
||||
* the static method {@link #getRoomMultiplexor(XMPPConnection)}.
|
||||
* the static method {@link #getRoomMultiplexor(Connection)}.
|
||||
*/
|
||||
private RoomListenerMultiplexor(XMPPConnection connection, RoomMultiplexFilter filter,
|
||||
private RoomListenerMultiplexor(Connection connection, RoomMultiplexFilter filter,
|
||||
RoomMultiplexListener listener) {
|
||||
if (connection == null) {
|
||||
throw new IllegalArgumentException("Connection is null");
|
||||
|
@ -146,11 +146,11 @@ class RoomListenerMultiplexor implements ConnectionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* The single <code>XMPPConnection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
|
||||
* for all muc chat rooms on an <code>XMPPConnection</code>.
|
||||
* The single <code>Connection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
|
||||
* for all muc chat rooms on an <code>Connection</code>.
|
||||
* Each time a muc chat room is added to/removed from an
|
||||
* <code>XMPPConnection</code> the address for that chat room
|
||||
* is added to/removed from that <code>XMPPConnection</code>'s
|
||||
* <code>Connection</code> the address for that chat room
|
||||
* is added to/removed from that <code>Connection</code>'s
|
||||
* <code>RoomMultiplexFilter</code>.
|
||||
*/
|
||||
private static class RoomMultiplexFilter implements PacketFilter {
|
||||
|
@ -181,12 +181,12 @@ class RoomListenerMultiplexor implements ConnectionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* The single <code>XMPPConnection</code>-level <code>PacketListener</code>
|
||||
* The single <code>Connection</code>-level <code>PacketListener</code>
|
||||
* used by a {@link RoomListenerMultiplexor}
|
||||
* for all muc chat rooms on an <code>XMPPConnection</code>.
|
||||
* for all muc chat rooms on an <code>Connection</code>.
|
||||
* Each time a muc chat room is added to/removed from an
|
||||
* <code>XMPPConnection</code> the address and listener for that chat room
|
||||
* are added to/removed from that <code>XMPPConnection</code>'s
|
||||
* <code>Connection</code> the address and listener for that chat room
|
||||
* are added to/removed from that <code>Connection</code>'s
|
||||
* <code>RoomMultiplexListener</code>.
|
||||
*
|
||||
* @author Larry Kirschner
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue