mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Make synchronization point return the exception
instead of a boolean value.
This commit is contained in:
parent
72972dad82
commit
989076a166
1 changed files with 10 additions and 9 deletions
|
@ -68,9 +68,9 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
* @param request the plain stream element to send.
|
* @param request the plain stream element to send.
|
||||||
* @throws NoResponseException if no response was received.
|
* @throws NoResponseException if no response was received.
|
||||||
* @throws NotConnectedException if the connection is not connected.
|
* @throws NotConnectedException if the connection is not connected.
|
||||||
* @return <code>true</code> if synchronization point was successful, <code>false</code> on failure.
|
* @return <code>null</code> if synchronization point was successful, or the failure Exception.
|
||||||
*/
|
*/
|
||||||
public boolean sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
|
public E sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
|
||||||
NotConnectedException, InterruptedException {
|
NotConnectedException, InterruptedException {
|
||||||
assert (state == State.Initial);
|
assert (state == State.Initial);
|
||||||
connectionLock.lock();
|
connectionLock.lock();
|
||||||
|
@ -133,17 +133,17 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
* Check if this synchronization point is successful or wait the connections reply timeout.
|
* Check if this synchronization point is successful or wait the connections reply timeout.
|
||||||
* @throws NoResponseException if there was no response marking the synchronization point as success or failed.
|
* @throws NoResponseException if there was no response marking the synchronization point as success or failed.
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* @return <code>true</code> if synchronization point was successful, <code>false</code> on failure.
|
* @return <code>null</code> if synchronization point was successful, or the failure Exception.
|
||||||
*/
|
*/
|
||||||
public boolean checkIfSuccessOrWait() throws NoResponseException, InterruptedException {
|
public E checkIfSuccessOrWait() throws NoResponseException, InterruptedException {
|
||||||
connectionLock.lock();
|
connectionLock.lock();
|
||||||
try {
|
try {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
// Return immediately on success or failure
|
// Return immediately on success or failure
|
||||||
case Success:
|
case Success:
|
||||||
return true;
|
return null;
|
||||||
case Failure:
|
case Failure:
|
||||||
return false;
|
return failureException;
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
|
@ -249,18 +249,19 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
* <p>
|
* <p>
|
||||||
* The exception is thrown, if state is one of 'Initial', 'NoResponse' or 'RequestSent'
|
* The exception is thrown, if state is one of 'Initial', 'NoResponse' or 'RequestSent'
|
||||||
* </p>
|
* </p>
|
||||||
|
* @return <code>true</code> if synchronization point was successful, <code>false</code> on failure.
|
||||||
* @throws NoResponseException
|
* @throws NoResponseException
|
||||||
*/
|
*/
|
||||||
private boolean checkForResponse() throws NoResponseException {
|
private E checkForResponse() throws NoResponseException {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Initial:
|
case Initial:
|
||||||
case NoResponse:
|
case NoResponse:
|
||||||
case RequestSent:
|
case RequestSent:
|
||||||
throw NoResponseException.newWith(connection, waitFor);
|
throw NoResponseException.newWith(connection, waitFor);
|
||||||
case Success:
|
case Success:
|
||||||
return true;
|
return null;
|
||||||
case Failure:
|
case Failure:
|
||||||
return false;
|
return failureException;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError("Unknown state " + state);
|
throw new AssertionError("Unknown state " + state);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue