From 17103def0be85c4c9b61be3ecd22e9d06776ab2c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 22 Apr 2015 09:45:02 +0200 Subject: [PATCH] Change SmackExecutorthreadFactory constructor parameter to XMPPConnection --- .../org/jivesoftware/smack/AbstractXMPPConnection.java | 8 ++++---- .../smack/util/SmackExecutorThreadFactory.java | 6 ++++-- .../java/org/jivesoftware/smackx/ping/PingManager.java | 2 +- 3 files changed, 9 insertions(+), 7 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 b123d137e..b86343028 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -232,13 +232,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * PacketListeners are invoked in the same order the stanzas arrived. */ private final ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, - new ArrayBlockingQueue(100), new SmackExecutorThreadFactory(connectionCounterValue, "Incoming Processor")); + new ArrayBlockingQueue(100), new SmackExecutorThreadFactory(this, "Incoming Processor")); /** * This scheduled thread pool executor is used to remove pending callbacks. */ private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor( - new SmackExecutorThreadFactory(connectionCounterValue, "Remove Callbacks")); + new SmackExecutorThreadFactory(this, "Remove Callbacks")); /** * A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set @@ -247,7 +247,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool( // @formatter:off new SmackExecutorThreadFactory( // threadFactory - connectionCounterValue, + this, "Cached Executor" ) // @formatter:on @@ -259,7 +259,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * is the same as the order of the incoming stanzas. Therefore we use a single threaded executor service. */ private final ExecutorService singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory( - getConnectionCounter(), "Single Threaded Executor")); + this, "Single Threaded Executor")); /** * The used host to establish the connection to diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/SmackExecutorThreadFactory.java b/smack-core/src/main/java/org/jivesoftware/smack/util/SmackExecutorThreadFactory.java index c3c59d7f8..721b52a59 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/SmackExecutorThreadFactory.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/SmackExecutorThreadFactory.java @@ -18,6 +18,8 @@ package org.jivesoftware.smack.util; import java.util.concurrent.ThreadFactory; +import org.jivesoftware.smack.XMPPConnection; + /** * SmackExecutorThreadFactory creates daemon threads with a particular name. Note that you should * not use anonymous inner classes for thread factories in order to prevent threads from leaking. @@ -27,8 +29,8 @@ public final class SmackExecutorThreadFactory implements ThreadFactory { private final String name; private int count = 0; - public SmackExecutorThreadFactory(int connectionCounterValue, String name) { - this.connectionCounterValue = connectionCounterValue; + public SmackExecutorThreadFactory(XMPPConnection connection, String name) { + this.connectionCounterValue = connection.getConnectionCounter(); this.name = name; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index 4cdba66c7..99a2d576d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -119,7 +119,7 @@ public final class PingManager extends Manager { private PingManager(XMPPConnection connection) { super(connection); executorService = Executors.newSingleThreadScheduledExecutor( - new SmackExecutorThreadFactory(connection.getConnectionCounter(), "Ping")); + new SmackExecutorThreadFactory(connection, "Ping")); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Ping.NAMESPACE);