From a19181ce04bb70a0ff1c5637406497de6593d662 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 21 May 2014 21:43:16 +0200 Subject: [PATCH] Make XMPPConnection.schedule() protected This method was never intended to be part of the public API. It's also critical that the given Runnables complete within a reasonable time frame so that they don't block following ones. --- .../src/main/java/org/jivesoftware/smack/Manager.java | 6 ++++++ .../main/java/org/jivesoftware/smack/XMPPConnection.java | 2 +- .../main/java/org/jivesoftware/smackx/ping/PingManager.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Manager.java b/smack-core/src/main/java/org/jivesoftware/smack/Manager.java index 0b6d1315d..da00235f0 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Manager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/Manager.java @@ -17,6 +17,8 @@ package org.jivesoftware.smack; import java.lang.ref.WeakReference; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; public abstract class Manager { @@ -29,4 +31,8 @@ public abstract class Manager { protected final XMPPConnection connection() { return weakConnection.get(); } + + protected ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { + return connection().schedule(command, delay, unit); + } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index ca3742763..6f47e5d47 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -1275,7 +1275,7 @@ public abstract class XMPPConnection { } } - public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { + protected ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { return executorService.schedule(command, delay, unit); } 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 47ff08bd9..af201ff32 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 @@ -308,7 +308,7 @@ public class PingManager extends Manager { int nextPingIn = pingInterval - delta; LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval=" + pingInterval + ", delta=" + delta + ")"); - nextAutomaticPing = connection().schedule(pingServerRunnable, pingInterval, TimeUnit.SECONDS); + nextAutomaticPing = schedule(pingServerRunnable, pingInterval, TimeUnit.SECONDS); } }