1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

[core] Synchronize notifyConnectionError()

Synchronize notifyConnectionError() so that only one exception is
handled and remove the ASYNC_BUT_ORDERED usage here. The
ASYNC_BUT_ORDERED was added with 7d2c3ac9f ("Do not call synchronized
methods in reader/writer thread"), but is no longer necessary, since
the Semaphores where replaced with conditions in the previous commit.
This commit is contained in:
Florian Schmaus 2020-05-31 12:34:02 +02:00
parent 57961a8cc1
commit 81f10b0c5b

View file

@ -963,6 +963,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
callConnectionClosedListener(); callConnectionClosedListener();
} }
private final Object notifyConnectionErrorMonitor = new Object();
/** /**
* Sends out a notification that there was an error with the connection * Sends out a notification that there was an error with the connection
* and closes the connection. * and closes the connection.
@ -970,14 +972,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param exception the exception that causes the connection close event. * @param exception the exception that causes the connection close event.
*/ */
protected final void notifyConnectionError(final Exception exception) { protected final void notifyConnectionError(final Exception exception) {
synchronized (notifyConnectionErrorMonitor) {
if (!isConnected()) { if (!isConnected()) {
LOGGER.log(Level.INFO, "Connection was already disconnected when attempting to handle " + exception, LOGGER.log(Level.INFO, "Connection was already disconnected when attempting to handle " + exception,
exception); exception);
return; return;
} }
// TODO: Remove this async but ordered?
ASYNC_BUT_ORDERED.performAsyncButOrdered(this, () -> {
// Note that we first have to set the current connection exception and notify waiting threads, as one of them // Note that we first have to set the current connection exception and notify waiting threads, as one of them
// could hold the instance lock, which we also need later when calling instantShutdown(). // could hold the instance lock, which we also need later when calling instantShutdown().
setCurrentConnectionExceptionAndNotify(exception); setCurrentConnectionExceptionAndNotify(exception);
@ -995,7 +996,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// Notify connection listeners of the error. // Notify connection listeners of the error.
callConnectionClosedOnErrorListener(exception); callConnectionClosedOnErrorListener(exception);
}, AbstractXMPPConnection.this + " callConnectionClosedOnErrorListener()"); }, AbstractXMPPConnection.this + " callConnectionClosedOnErrorListener()");
}); }
} }
/** /**