From 64d36a52e362bdd4baca0b6c120c3ad322f5847e Mon Sep 17 00:00:00 2001 From: rcollier Date: Mon, 21 Feb 2011 20:45:00 +0000 Subject: [PATCH] SMACK-328 Added patches to fix threading issue with usage of SimpleDateFormatter. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_2_0@12030 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/workgroup/packet/QueueDetails.java | 23 +++++++++---------- .../workgroup/packet/QueueOverview.java | 10 ++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java b/source/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java index f51c81fdb..86b3673e8 100644 --- a/source/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java +++ b/source/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java @@ -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(""); - buf.append(DATE_FORMATTER.format(timestamp)); + buf.append(dateFormat.format(timestamp)); buf.append(""); } @@ -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)); diff --git a/source/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java b/source/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java index ef44e9e01..a559579b4 100644 --- a/source/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java +++ b/source/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java @@ -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("").append(userCount).append(""); } if (oldestEntry != null) { - buf.append("").append(DATE_FORMATTER.format(oldestEntry)).append(""); + buf.append("").append(dateFormat.format(oldestEntry)).append(""); } if (averageWaitTime != -1) { buf.append(""); @@ -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()));