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

Rework SynchronizationPoint

- synchronize wasSuccessful() and requestSent()
- Add comment
- Clarify log message
This commit is contained in:
Florian Schmaus 2014-12-17 10:29:48 +01:00
parent ff2c71e042
commit 84ffa265ce

View file

@ -36,6 +36,8 @@ public class SynchronizationPoint<E extends Exception> {
private final Lock connectionLock;
private final Condition condition;
// Note that there is no need to make 'state' and 'failureException' volatile. Since 'lock' and 'unlock' have the
// same memory synchronization effects as synchronization block enter and leave.
private State state;
private E failureException;
@ -47,8 +49,10 @@ public class SynchronizationPoint<E extends Exception> {
}
public void init() {
connectionLock.lock();
state = State.Initial;
failureException = null;
connectionLock.unlock();
}
public void sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
@ -138,12 +142,24 @@ public class SynchronizationPoint<E extends Exception> {
}
public boolean wasSuccessful() {
connectionLock.lock();
try {
return state == State.Success;
}
finally {
connectionLock.unlock();
}
}
public boolean requestSent() {
connectionLock.lock();
try {
return state == State.RequestSent;
}
finally {
connectionLock.unlock();
}
}
private void waitForConditionOrTimeout() {
long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getPacketReplyTimeout());
@ -156,7 +172,7 @@ public class SynchronizationPoint<E extends Exception> {
break;
}
} catch (InterruptedException e) {
LOGGER.log(Level.FINE, "was interrupted while waiting, this should not happen", e);
LOGGER.log(Level.FINE, "Spurious interrupt while waiting for condition or timeout", e);
}
}
}