mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Remove schedule() from XMPPConnection interface
The idea that we abstract the scheduling of tasks on Android over this method turned out to be unnecessary. schedule() was also not really part of the *public* XMPPConnection API, so it's good that it's gone.
This commit is contained in:
parent
3647a7fce5
commit
6fd4bb850e
3 changed files with 33 additions and 25 deletions
|
@ -21,7 +21,10 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -107,6 +110,24 @@ public class PingManager extends Manager {
|
|||
private final Set<PingFailedListener> pingFailedListeners = Collections
|
||||
.synchronizedSet(new HashSet<PingFailedListener>());
|
||||
|
||||
private final ScheduledExecutorService executorService;
|
||||
|
||||
private static class PingExecutorThreadFactory implements ThreadFactory {
|
||||
private final int connectionCounterValue;
|
||||
|
||||
public PingExecutorThreadFactory(int connectionCounterValue) {
|
||||
this.connectionCounterValue = connectionCounterValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
Thread thread = new Thread(runnable, "Smack Scheduled Ping Executor Service ("
|
||||
+ connectionCounterValue + ")");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* The interval in seconds between pings are send to the users server.
|
||||
*/
|
||||
|
@ -121,6 +142,8 @@ public class PingManager extends Manager {
|
|||
|
||||
private PingManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
executorService = new ScheduledThreadPoolExecutor(1,
|
||||
new PingExecutorThreadFactory(connection.getConnectionCounter()));
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(PingManager.NAMESPACE);
|
||||
INSTANCES.put(connection, this);
|
||||
|
@ -309,7 +332,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 = executorService.schedule(pingServerRunnable, pingInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,4 +409,13 @@ public class PingManager extends Manager {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
executorService.shutdown();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue