1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Make PingManager use Manager.schedule()

This commit is contained in:
Florian Schmaus 2018-02-26 10:24:35 +01:00
parent ecc53b1bc8
commit 27808e9e8c

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2012-2017 Florian Schmaus * Copyright 2012-2018 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@ -45,7 +43,6 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.ping.packet.Ping; import org.jivesoftware.smackx.ping.packet.Ping;
@ -112,8 +109,6 @@ public final class PingManager extends Manager {
private final Set<PingFailedListener> pingFailedListeners = new CopyOnWriteArraySet<>(); private final Set<PingFailedListener> pingFailedListeners = new CopyOnWriteArraySet<>();
private final ScheduledExecutorService executorService;
/** /**
* The interval in seconds between pings are send to the users server. * The interval in seconds between pings are send to the users server.
*/ */
@ -123,8 +118,6 @@ public final class PingManager extends Manager {
private PingManager(XMPPConnection connection) { private PingManager(XMPPConnection connection) {
super(connection); super(connection);
executorService = Executors.newSingleThreadScheduledExecutor(
new SmackExecutorThreadFactory(connection, "Ping"));
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(Ping.NAMESPACE); sdm.addFeature(Ping.NAMESPACE);
@ -391,7 +384,7 @@ public final class PingManager extends Manager {
int nextPingIn = pingInterval - delta; int nextPingIn = pingInterval - delta;
LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval=" LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval="
+ pingInterval + ", delta=" + delta + ")"); + pingInterval + ", delta=" + delta + ")");
nextAutomaticPing = executorService.schedule(pingServerRunnable, nextPingIn, TimeUnit.SECONDS); nextAutomaticPing = schedule(pingServerRunnable, nextPingIn, TimeUnit.SECONDS);
} }
} }
@ -479,16 +472,4 @@ public final class PingManager extends Manager {
} }
}; };
@Override
protected void finalize() throws Throwable {
LOGGER.fine("finalizing PingManager: Shutting down executor service");
try {
executorService.shutdown();
} catch (Throwable t) {
LOGGER.log(Level.WARNING, "finalize() threw throwable", t);
}
finally {
super.finalize();
}
}
} }