Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defer the Creation of ISE, to when an exception needs to be created (Manual merge of #264) #371

Merged
merged 4 commits into from
Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ 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 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) {
if(e == null) {
exception = new IllegalStateException(exceptionMessage);
}
setExceptionIfResponseNotReceived(exception);
}
// return any exception that was generated
return exception;
}

/**
* When set any client thread blocking on get() will immediately be unblocked and receive the exception.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +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
IllegalStateException ie = new IllegalStateException("No response set by " + commandCollapser.getCollapserKey().name() + " 'mapResponseToRequests' implementation.");
Exception e = null;
for (CollapsedRequest<ResponseType, RequestArgumentType> request : shardRequests) {
try {
((CollapsedRequestObservableFunction<ResponseType, RequestArgumentType>) request).setExceptionIfResponseNotReceived(ie);
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