mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-16 04:12:04 +01:00
Rework SynchronizationPoint
- synchronize wasSuccessful() and requestSent() - Add comment - Clarify log message
This commit is contained in:
parent
ff2c71e042
commit
84ffa265ce
1 changed files with 19 additions and 3 deletions
|
@ -36,6 +36,8 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
private final Lock connectionLock;
|
private final Lock connectionLock;
|
||||||
private final Condition condition;
|
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 State state;
|
||||||
private E failureException;
|
private E failureException;
|
||||||
|
|
||||||
|
@ -47,8 +49,10 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
connectionLock.lock();
|
||||||
state = State.Initial;
|
state = State.Initial;
|
||||||
failureException = null;
|
failureException = null;
|
||||||
|
connectionLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
|
public void sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
|
||||||
|
@ -138,12 +142,24 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasSuccessful() {
|
public boolean wasSuccessful() {
|
||||||
|
connectionLock.lock();
|
||||||
|
try {
|
||||||
return state == State.Success;
|
return state == State.Success;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
connectionLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean requestSent() {
|
public boolean requestSent() {
|
||||||
|
connectionLock.lock();
|
||||||
|
try {
|
||||||
return state == State.RequestSent;
|
return state == State.RequestSent;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
connectionLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void waitForConditionOrTimeout() {
|
private void waitForConditionOrTimeout() {
|
||||||
long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getPacketReplyTimeout());
|
long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getPacketReplyTimeout());
|
||||||
|
@ -156,7 +172,7 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue