Skip to content

Commit

Permalink
+ create the exception once
Browse files Browse the repository at this point in the history
  • Loading branch information
tootedom committed May 19, 2014
1 parent ed14752 commit 7021050
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,21 @@ public void setExceptionIfResponseNotReceived(Exception e) {
/**
* Set an ISE if a response is not yet received otherwise skip it
*
* @param e A pre-generated exception. If this is null an ISE will be created and returned
* @param exceptionMessage The message for the ISE
*/
public void setIllegalStateExceptionIfResponseNotReceived(String exceptionMessage) {
public Exception setExceptionIfResponseNotReceived(Exception e, String exceptionMessage) {
Exception exception = e;
CollapsedRequestObservableFunction.ResponseHolder<T> r = rh.get();
// only proceed if neither response is set
if (!r.isResponseSet() && r.getException() == null) {
setExceptionIfResponseNotReceived(new IllegalStateException(exceptionMessage));
} else {
// return quietly instead of throwing an exception
return;
if(e==null) {
exception = new IllegalStateException(exceptionMessage);
}
setExceptionIfResponseNotReceived(exception);
}
// return any exception that was generated
return exception;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ public void call(Throwable e) {
@Override
public void call() {
// check that all requests had setResponse or setException invoked in case 'mapResponseToRequests' was implemented poorly
Exception e = null;
for (CollapsedRequest<ResponseType, RequestArgumentType> request : shardRequests) {
try {
((CollapsedRequestObservableFunction<ResponseType, RequestArgumentType>) request).setIllegalStateExceptionIfResponseNotReceived("No response set by " + commandCollapser.getCollapserKey().name() + " 'mapResponseToRequests' implementation.");
e = ((CollapsedRequestObservableFunction<ResponseType, RequestArgumentType>) request).setExceptionIfResponseNotReceived(e,"No response set by " + commandCollapser.getCollapserKey().name() + " 'mapResponseToRequests' implementation.");
} catch (IllegalStateException e2) {
logger.debug("Partial success of 'mapResponseToRequests' resulted in IllegalStateException while setting 'No response set' Exception. Continuing ... ", e2);
}
Expand Down

0 comments on commit 7021050

Please sign in to comment.