From ed66c838e18c7aa1d1f9e6ec0e23a3c2169a2562 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 29 Oct 2014 19:35:49 +0100 Subject: [PATCH] Invoke PacketCollectors in ListenerNotification Also make executorService a non-ScheduledExecutorService. This was an artifact from times where executorService as used to schedule Runnables. But now it's just used to queue the receive packets in Runnables and call the packet collectors and listeners. --- .../smack/AbstractXMPPConnection.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 4cf52260e..eea28bc93 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -25,11 +25,13 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; @@ -204,8 +206,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * important that we use a single threaded ExecutorService in order to guarantee that the * PacketListeners are invoked in the same order the stanzas arrived. */ - private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, - new SmackExecutorThreadFactory(connectionCounterValue)); + private final ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, + new ArrayBlockingQueue(100), new SmackExecutorThreadFactory(connectionCounterValue)); /** * SmackExecutorThreadFactory is a *static* inner class of XMPPConnection. Note that we must not @@ -840,12 +842,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * @param packet the packet to process. */ protected void processPacket(Packet packet) { - if (packet == null) { - return; - } - - invokePacketCollectors(packet); - // Deliver the incoming packet to listeners. executorService.submit(new ListenerNotification(packet)); } @@ -873,7 +869,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } /** - * A runnable to notify all listeners of a packet. + * A runnable to notify all listeners and packet collectors of a packet. */ private class ListenerNotification implements Runnable { @@ -884,6 +880,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } public void run() { + invokePacketCollectors(packet); notifiyReceivedListeners(packet); } }