mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-01-02 07:57:59 +01:00
Merge branch '4.4'
This commit is contained in:
commit
70abd8a182
2 changed files with 11 additions and 15 deletions
|
@ -694,10 +694,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitForConditionOrConnectionException(Supplier)}, because all state
|
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitFor(Supplier)}, because all state
|
||||||
* changing methods of the connection are synchronized using the connection instance as monitor. If we now would
|
* changing methods of the connection are synchronized using the connection instance as monitor. If we now would
|
||||||
* also use the connection instance for the internal process to wait for a condition, the {@link Object#wait()}
|
* also use the connection instance for the internal process to wait for a condition, the {@link Object#wait()}
|
||||||
* would leave the monitor when it waites, which would allow for another potential call to a state changing function
|
* would leave the monitor when it waits, which would allow for another potential call to a state changing function
|
||||||
* to proceed.
|
* to proceed.
|
||||||
*/
|
*/
|
||||||
private final Object internalMonitor = new Object();
|
private final Object internalMonitor = new Object();
|
||||||
|
@ -722,22 +722,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean waitForConditionOrConnectionException(Supplier<Boolean> condition) throws InterruptedException {
|
|
||||||
return waitFor(() -> condition.get().booleanValue() || hasCurrentConnectionException());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final void waitForConditionOrConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, NoResponseException {
|
|
||||||
boolean success = waitForConditionOrConnectionException(condition);
|
|
||||||
if (!success) {
|
|
||||||
throw NoResponseException.newWith(this, waitFor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException {
|
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException {
|
||||||
waitForConditionOrConnectionException(condition, waitFor);
|
boolean success = waitFor(() -> condition.get().booleanValue() || hasCurrentConnectionException());
|
||||||
if (hasCurrentConnectionException()) {
|
if (hasCurrentConnectionException()) {
|
||||||
throwCurrentConnectionException();
|
throwCurrentConnectionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there was no connection exception and we still did not successfully wait for the condition to hold, then
|
||||||
|
// we ran into a no-response timeout.
|
||||||
|
if (!success) {
|
||||||
|
throw NoResponseException.newWith(this, waitFor);
|
||||||
|
}
|
||||||
|
// Otherwise we successfully awaited the condition.
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource)
|
protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource)
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
if (isSmResumptionPossible()) {
|
if (isSmResumptionPossible()) {
|
||||||
smResumedSyncPoint = SyncPointState.request_sent;
|
smResumedSyncPoint = SyncPointState.request_sent;
|
||||||
sendNonza(new Resume(clientHandledStanzasCount, smSessionId));
|
sendNonza(new Resume(clientHandledStanzasCount, smSessionId));
|
||||||
waitForConditionOrConnectionException(() -> smResumedSyncPoint == SyncPointState.successful || smResumptionFailed != null, "resume previous stream");
|
waitForConditionOrThrowConnectionException(() -> smResumedSyncPoint == SyncPointState.successful || smResumptionFailed != null, "resume previous stream");
|
||||||
if (smResumedSyncPoint == SyncPointState.successful) {
|
if (smResumedSyncPoint == SyncPointState.successful) {
|
||||||
// We successfully resumed the stream, be done here
|
// We successfully resumed the stream, be done here
|
||||||
afterSuccessfulLogin(true);
|
afterSuccessfulLogin(true);
|
||||||
|
|
Loading…
Reference in a new issue