mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Merge branch '4.2'
This commit is contained in:
commit
7c9060c32b
3 changed files with 28 additions and 27 deletions
|
@ -81,6 +81,7 @@ import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
|
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
|
||||||
|
import org.jivesoftware.smack.util.Async;
|
||||||
import org.jivesoftware.smack.util.DNSUtil;
|
import org.jivesoftware.smack.util.DNSUtil;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
@ -240,8 +241,16 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
/**
|
/**
|
||||||
* This scheduled thread pool executor is used to remove pending callbacks.
|
* This scheduled thread pool executor is used to remove pending callbacks.
|
||||||
*/
|
*/
|
||||||
private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(
|
protected static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor(
|
||||||
new SmackExecutorThreadFactory(this, "Remove Callbacks"));
|
new ThreadFactory() {
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable runnable) {
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.setName("Smack Scheduled Executor Service");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
|
* A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
|
||||||
|
@ -1337,7 +1346,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
// reference to their ExecutorService which prevents the ExecutorService from being
|
// reference to their ExecutorService which prevents the ExecutorService from being
|
||||||
// gc'ed. It is possible that the XMPPConnection instance is gc'ed while the
|
// gc'ed. It is possible that the XMPPConnection instance is gc'ed while the
|
||||||
// listenerExecutor ExecutorService call not be gc'ed until it got shut down.
|
// listenerExecutor ExecutorService call not be gc'ed until it got shut down.
|
||||||
removeCallbacksService.shutdownNow();
|
|
||||||
singleThreadedExecutorService.shutdownNow();
|
singleThreadedExecutorService.shutdownNow();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LOGGER.log(Level.WARNING, "finalize() threw throwable", t);
|
LOGGER.log(Level.WARNING, "finalize() threw throwable", t);
|
||||||
|
@ -1574,7 +1582,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
} else {
|
} else {
|
||||||
exception = NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter);
|
exception = NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter);
|
||||||
}
|
}
|
||||||
exceptionCallback.processException(exception);
|
final Exception exceptionToProcess = exception;
|
||||||
|
Async.go(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
exceptionCallback.processException(exceptionToProcess);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, timeout, TimeUnit.MILLISECONDS);
|
}, timeout, TimeUnit.MILLISECONDS);
|
||||||
|
@ -1705,6 +1719,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
return removeCallbacksService.schedule(runnable, delay, unit);
|
return SCHEDULED_EXECUTOR_SERVICE.schedule(runnable, delay, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2014 Florian Schmaus
|
* Copyright 2014-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.
|
||||||
|
@ -17,6 +17,8 @@
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
|
@ -48,4 +50,8 @@ public abstract class Manager {
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
|
return AbstractXMPPConnection.SCHEDULED_EXECUTOR_SERVICE.schedule(runnable, delay, unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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.ExceptionCallback;
|
import org.jivesoftware.smack.util.ExceptionCallback;
|
||||||
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
|
|
||||||
import org.jivesoftware.smack.util.SuccessCallback;
|
import org.jivesoftware.smack.util.SuccessCallback;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -113,8 +110,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.
|
||||||
*/
|
*/
|
||||||
|
@ -124,8 +119,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);
|
||||||
|
|
||||||
|
@ -398,7 +391,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,16 +479,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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue