1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Merged the 3.2 Beta branch into trunk.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12107 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2011-03-14 01:53:42 +00:00
parent 67a5e6b98d
commit 2150d07435
9 changed files with 387 additions and 38 deletions

View file

@ -20,6 +20,13 @@
package org.jivesoftware.smack;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromContainsFilter;
import org.jivesoftware.smack.filter.PacketFilter;
@ -29,9 +36,6 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.collections.ReferenceMap;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* The chat manager keeps track of references to all current chats. It will not hold any references
* in memory on its own so it is neccesary to keep a reference to the chat object itself. To be
@ -65,14 +69,20 @@ public class ChatManager {
/**
* Maps thread ID to chat.
*/
private Map<String, Chat> threadChats = new ReferenceMap<String, Chat>(ReferenceMap.HARD,
ReferenceMap.WEAK);
private Map<String, Chat> threadChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
ReferenceMap.WEAK));
/**
* Maps jids to chats
*/
private Map<String, Chat> jidChats = new ReferenceMap<String, Chat>(ReferenceMap.HARD,
ReferenceMap.WEAK);
private Map<String, Chat> jidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
ReferenceMap.WEAK));
/**
* Maps base jids to chats
*/
private Map<String, Chat> baseJidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
ReferenceMap.WEAK));
private Set<ChatManagerListener> chatManagerListeners
= new CopyOnWriteArraySet<ChatManagerListener>();
@ -161,6 +171,7 @@ public class ChatManager {
Chat chat = new Chat(this, userJID, threadID);
threadChats.put(threadID, chat);
jidChats.put(userJID, chat);
baseJidChats.put(StringUtils.parseBareAddress(userJID), chat);
for(ChatManagerListener listener : chatManagerListeners) {
listener.chatCreated(chat, createdLocally);
@ -179,8 +190,21 @@ public class ChatManager {
return createChat(userJID, threadID, false);
}
/**
* Try to get a matching chat for the given user JID. Try the full
* JID map first, the try to match on the base JID if no match is
* found.
*
* @param userJID
* @return
*/
private Chat getUserChat(String userJID) {
return jidChats.get(userJID);
Chat match = jidChats.get(userJID);
if (match == null) {
match = baseJidChats.get(StringUtils.parseBareAddress(userJID));
}
return match;
}
public Chat getThreadChat(String thread) {

View file

@ -44,7 +44,7 @@ import java.util.*;
*/
public final class SmackConfiguration {
private static final String SMACK_VERSION = "3.2.0 Beta 2";
private static final String SMACK_VERSION = "3.2.0 Beta2";
private static int packetReplyTimeout = 5000;
private static int keepAliveInterval = 30000;

View file

@ -46,8 +46,9 @@ public class QueueDetails implements PacketExtension {
*/
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
private static final String DATE_FORMAT = "yyyyMMdd'T'HH:mm:ss";
private SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* The list of users in the queue.
*/
@ -124,7 +125,7 @@ public class QueueDetails implements PacketExtension {
if (timestamp != null) {
buf.append("<join-time>");
buf.append(DATE_FORMATTER.format(timestamp));
buf.append(dateFormat.format(timestamp));
buf.append("</join-time>");
}
@ -139,8 +140,10 @@ public class QueueDetails implements PacketExtension {
* Provider class for QueueDetails packet extensions.
*/
public static class Provider implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
QueueDetails queueDetails = new QueueDetails();
int eventType = parser.getEventType();
@ -163,7 +166,7 @@ public class QueueDetails implements PacketExtension {
eventType = parser.next();
while ((eventType != XmlPullParser.END_TAG)
|| (! "user".equals(parser.getName())))
{
{
if ("position".equals(parser.getName())) {
position = Integer.parseInt(parser.nextText());
}
@ -171,23 +174,19 @@ public class QueueDetails implements PacketExtension {
time = Integer.parseInt(parser.nextText());
}
else if ("join-time".equals(parser.getName())) {
joinTime = DATE_FORMATTER.parse(parser.nextText());
joinTime = dateFormat.parse(parser.nextText());
}
else if( parser.getName().equals( "waitTime" ) ) {
Date wait = DATE_FORMATTER.parse( parser.nextText() );
System.out.println( wait );
Date wait = dateFormat.parse(parser.nextText());
System.out.println( wait );
}
eventType = parser.next();
if (eventType != XmlPullParser.END_TAG) {
// throw exception
}
}
queueDetails.addUser(new QueueUser(uid, position, time, joinTime));

View file

@ -39,7 +39,8 @@ public class QueueOverview implements PacketExtension {
*/
public static String NAMESPACE = "http://jabber.org/protocol/workgroup";
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
private static final String DATE_FORMAT = "yyyyMMdd'T'HH:mm:ss";
private SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
private int averageWaitTime;
private Date oldestEntry;
@ -101,7 +102,7 @@ public class QueueOverview implements PacketExtension {
buf.append("<count>").append(userCount).append("</count>");
}
if (oldestEntry != null) {
buf.append("<oldest>").append(DATE_FORMATTER.format(oldestEntry)).append("</oldest>");
buf.append("<oldest>").append(dateFormat.format(oldestEntry)).append("</oldest>");
}
if (averageWaitTime != -1) {
buf.append("<time>").append(averageWaitTime).append("</time>");
@ -118,7 +119,8 @@ public class QueueOverview implements PacketExtension {
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
int eventType = parser.getEventType();
QueueOverview queueOverview = new QueueOverview();
QueueOverview queueOverview = new QueueOverview();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
if (eventType != XmlPullParser.START_TAG) {
// throw exception
@ -135,7 +137,7 @@ public class QueueOverview implements PacketExtension {
queueOverview.setAverageWaitTime(Integer.parseInt(parser.nextText()));
}
else if ("oldest".equals(parser.getName())) {
queueOverview.setOldestEntry((DATE_FORMATTER.parse(parser.nextText())));
queueOverview.setOldestEntry((dateFormat.parse(parser.nextText())));
}
else if ("status".equals(parser.getName())) {
queueOverview.setStatus(WorkgroupQueue.Status.fromString(parser.nextText()));