Browse Source

Polish

pull/1464/merge
Rossen Stoyanchev 8 years ago
parent
commit
eb0479dee8
  1. 1
      spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java
  2. 11
      spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java
  3. 12
      spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java
  4. 2
      spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java
  5. 12
      spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java
  6. 12
      spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java
  7. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java

1
spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java

@ -46,6 +46,7 @@ public interface AsyncWebRequest extends NativeWebRequest { @@ -46,6 +46,7 @@ public interface AsyncWebRequest extends NativeWebRequest {
/**
* Add a handler to invoke when an error occurred while concurrent
* handling of a request.
* @since 5.0
*/
void addErrorHandler(Consumer<Throwable> exceptionHandler);

11
spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java

@ -102,17 +102,18 @@ public interface CallableProcessingInterceptor { @@ -102,17 +102,18 @@ public interface CallableProcessingInterceptor {
<T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception;
/**
* Invoked from a container thread when an error occurred while processing the async request
* before the {@code Callable} task completes. Implementations may return a value,
* including an {@link Exception}, to use instead of the value the
* {@link Callable} did not return in time.
* Invoked from a container thread when an error occurred while processing
* the async request before the {@code Callable} task completes.
* Implementations may return a value, including an {@link Exception}, to
* use instead of the value the {@link Callable} did not return in time.
* @param request the current request
* @param task the task for the current async request
* @paramt t the error that occurred while request processing
* @param t the error that occurred while request processing
* @return a concurrent result value; if the value is anything other than
* {@link #RESULT_NONE} or {@link #RESPONSE_HANDLED}, concurrent processing
* is resumed and subsequent interceptors are not invoked
* @throws Exception in case of errors
* @since 5.0
*/
<T> Object handleError(NativeWebRequest request, Callable<T> task, Throwable t) throws Exception;

12
spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java

@ -154,11 +154,13 @@ public class DeferredResult<T> { @@ -154,11 +154,13 @@ public class DeferredResult<T> {
}
/**
* Register code to invoke when an error occurred while processing the async request.
* <p>This method is called from a container thread when an error occurred while
* processing an async request before the {@code DeferredResult} has been populated.
* It may invoke {@link DeferredResult#setResult setResult} or
* {@link DeferredResult#setErrorResult setErrorResult} to resume processing.
* Register code to invoke when an error occurred during the async request.
* <p>This method is called from a container thread when an error occurs
* while processing an async request before the {@code DeferredResult} has
* been populated. It may invoke {@link DeferredResult#setResult setResult}
* or {@link DeferredResult#setErrorResult setErrorResult} to resume
* processing.
* @since 5.0
*/
public void onError(Consumer<Throwable> callback) {
this.errorCallback = callback;

2
spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java

@ -27,7 +27,7 @@ import org.springframework.web.context.request.NativeWebRequest; @@ -27,7 +27,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Violeta Georgieva
* @since 5.0
*/
public class ErrorCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter {
class ErrorCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter {
@Override
public <T> Object handleError(NativeWebRequest request, Callable<T> task, Throwable t) throws Exception {

12
spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java

@ -143,23 +143,17 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements @@ -143,23 +143,17 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
@Override
public void onError(AsyncEvent event) throws IOException {
for (Consumer<Throwable> handler : this.exceptionHandlers) {
handler.accept(event.getThrowable());
}
this.exceptionHandlers.forEach(consumer -> consumer.accept(event.getThrowable()));
}
@Override
public void onTimeout(AsyncEvent event) throws IOException {
for (Runnable handler : this.timeoutHandlers) {
handler.run();
}
this.timeoutHandlers.forEach(Runnable::run);
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
for (Runnable handler : this.completionHandlers) {
handler.run();
}
this.completionHandlers.forEach(Runnable::run);
this.asyncContext = null;
this.asyncCompleted.set(true);
}

12
spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java

@ -153,12 +153,14 @@ public class WebAsyncTask<V> implements BeanFactoryAware { @@ -153,12 +153,14 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
}
/**
* Register code to invoke when an error occurred while processing the async request.
* <p>This method is called from a container thread when an error occurred while processing
* an async request before the {@code Callable} has completed. The callback is executed in
* the same thread and therefore should return without blocking. It may return
* an alternative value to use, including an {@link Exception} or return
* Register code to invoke for an error during async request processing.
* <p>This method is called from a container thread when an error occurred
* while processing an async request before the {@code Callable} has
* completed. The callback is executed in the same thread and therefore
* should return without blocking. It may return an alternative value to
* use, including an {@link Exception} or return
* {@link CallableProcessingInterceptor#RESULT_NONE RESULT_NONE}.
* @since 5.0
*/
public void onError(Callable<V> callback) {
this.errorCallback = callback;

7
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java

@ -217,9 +217,10 @@ public class ResponseBodyEmitter { @@ -217,9 +217,10 @@ public class ResponseBodyEmitter {
}
/**
* Register code to invoke when an error occurred while processing the async request.
* This method is called from a container thread when an error occurred while processing
* an async request.
* Register code to invoke for an error during async request processing.
* This method is called from a container thread when an error occurred
* while processing an async request.
* @since 5.0
*/
public synchronized void onError(Consumer<Throwable> callback) {
this.errorCallback.setDelegate(callback);

Loading…
Cancel
Save