Deprecate adapter classes for async interceptors

This commit is contained in:
Rossen Stoyanchev
2017-06-26 15:34:51 -04:00
parent eb0479dee8
commit 5b8f7f503f
18 changed files with 91 additions and 76 deletions

View File

@@ -45,9 +45,9 @@ import org.springframework.web.context.request.NativeWebRequest;
*/
public interface CallableProcessingInterceptor {
static final Object RESULT_NONE = new Object();
Object RESULT_NONE = new Object();
static final Object RESPONSE_HANDLED = new Object();
Object RESPONSE_HANDLED = new Object();
/**
* Invoked <em>before</em> the start of concurrent handling in the original
@@ -62,7 +62,8 @@ public interface CallableProcessingInterceptor {
* @param task the task for the current async request
* @throws Exception in case of errors
*/
<T> void beforeConcurrentHandling(NativeWebRequest request, Callable<T> task) throws Exception;
default <T> void beforeConcurrentHandling(NativeWebRequest request, Callable<T> task) throws Exception {
}
/**
* Invoked <em>after</em> the start of concurrent handling in the async
@@ -72,7 +73,8 @@ public interface CallableProcessingInterceptor {
* @param task the task for the current async request
* @throws Exception in case of errors
*/
<T> void preProcess(NativeWebRequest request, Callable<T> task) throws Exception;
default <T> void preProcess(NativeWebRequest request, Callable<T> task) throws Exception {
}
/**
* Invoked <em>after</em> the {@code Callable} has produced a result in the
@@ -85,7 +87,9 @@ public interface CallableProcessingInterceptor {
* be a {@link Throwable} if the {@code Callable} raised an exception
* @throws Exception in case of errors
*/
<T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult) throws Exception;
default <T> void postProcess(NativeWebRequest request, Callable<T> task,
Object concurrentResult) throws Exception {
}
/**
* Invoked from a container thread when the async request times out before
@@ -99,7 +103,9 @@ public interface CallableProcessingInterceptor {
* is resumed and subsequent interceptors are not invoked
* @throws Exception in case of errors
*/
<T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception;
default <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
return RESULT_NONE;
}
/**
* Invoked from a container thread when an error occurred while processing
@@ -115,7 +121,9 @@ public interface CallableProcessingInterceptor {
* @throws Exception in case of errors
* @since 5.0
*/
<T> Object handleError(NativeWebRequest request, Callable<T> task, Throwable t) throws Exception;
default <T> Object handleError(NativeWebRequest request, Callable<T> task, Throwable t) throws Exception {
return RESULT_NONE;
}
/**
* Invoked from a container thread when async processing completes for any
@@ -124,6 +132,7 @@ public interface CallableProcessingInterceptor {
* @param task the task for the current async request
* @throws Exception in case of errors
*/
<T> void afterCompletion(NativeWebRequest request, Callable<T> task) throws Exception;
default <T> void afterCompletion(NativeWebRequest request, Callable<T> task) throws Exception {
}
}

View File

@@ -27,7 +27,9 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @author Rob Winch
* @since 3.2
* @deprecated as of 5.0 where CallableProcessingInterceptor has default methods
*/
@Deprecated
public abstract class CallableProcessingInterceptorAdapter implements CallableProcessingInterceptor {
/**

View File

@@ -268,7 +268,7 @@ public class DeferredResult<T> {
final DeferredResultProcessingInterceptor getInterceptor() {
return new DeferredResultProcessingInterceptorAdapter() {
return new DeferredResultProcessingInterceptor() {
@Override
public <S> boolean handleTimeout(NativeWebRequest request, DeferredResult<S> deferredResult) {
boolean continueProcessing = true;

View File

@@ -50,7 +50,9 @@ public interface DeferredResultProcessingInterceptor {
* @param deferredResult the DeferredResult for the current request
* @throws Exception in case of errors
*/
<T> void beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception;
default <T> void beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult)
throws Exception {
}
/**
* Invoked immediately after the start of concurrent handling, in the same
@@ -62,7 +64,9 @@ public interface DeferredResultProcessingInterceptor {
* @param deferredResult the DeferredResult for the current request
* @throws Exception in case of errors
*/
<T> void preProcess(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception;
default <T> void preProcess(NativeWebRequest request, DeferredResult<T> deferredResult)
throws Exception {
}
/**
* Invoked after a {@code DeferredResult} has been set, via
@@ -77,7 +81,9 @@ public interface DeferredResultProcessingInterceptor {
* @param concurrentResult the result to which the {@code DeferredResult}
* @throws Exception in case of errors
*/
<T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object concurrentResult) throws Exception;
default <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult,
Object concurrentResult) throws Exception {
}
/**
* Invoked from a container thread when an async request times out before
@@ -92,7 +98,11 @@ public interface DeferredResultProcessingInterceptor {
* other interceptors should not be invoked
* @throws Exception in case of errors
*/
<T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception;
default <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult)
throws Exception {
return true;
}
/**
* Invoked from a container thread when an error occurred while processing an async request
@@ -108,7 +118,11 @@ public interface DeferredResultProcessingInterceptor {
* other interceptors should not be invoked
* @throws Exception in case of errors
*/
<T> boolean handleError(NativeWebRequest request, DeferredResult<T> deferredResult, Throwable t) throws Exception;
default <T> boolean handleError(NativeWebRequest request, DeferredResult<T> deferredResult,
Throwable t) throws Exception {
return true;
}
/**
* Invoked from a container thread when an async request completed for any
@@ -118,6 +132,8 @@ public interface DeferredResultProcessingInterceptor {
* @param deferredResult the DeferredResult for the current request
* @throws Exception in case of errors
*/
<T> void afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception;
default <T> void afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult)
throws Exception {
}
}

View File

@@ -25,7 +25,9 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @author Rob Winch
* @since 3.2
* @deprecated as of 5.0 where DeferredResultProcessingInterceptor has default methods
*/
@Deprecated
public abstract class DeferredResultProcessingInterceptorAdapter implements DeferredResultProcessingInterceptor {
/**

View File

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

View File

@@ -25,11 +25,12 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Violeta Georgieva
* @since 5.0
*/
public class ErrorDeferredResultProcessingInterceptor extends DeferredResultProcessingInterceptorAdapter {
public class ErrorDeferredResultProcessingInterceptor implements DeferredResultProcessingInterceptor {
@Override
public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t)
throws Exception {
result.setErrorResult(t);
return false;
}

View File

@@ -37,7 +37,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.2
*/
public class TimeoutCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter {
public class TimeoutCallableProcessingInterceptor implements CallableProcessingInterceptor {
@Override
public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {

View File

@@ -35,7 +35,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.2
*/
public class TimeoutDeferredResultProcessingInterceptor extends DeferredResultProcessingInterceptorAdapter {
public class TimeoutDeferredResultProcessingInterceptor implements DeferredResultProcessingInterceptor {
@Override
public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {

View File

@@ -176,7 +176,7 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
}
CallableProcessingInterceptor getInterceptor() {
return new CallableProcessingInterceptorAdapter() {
return new CallableProcessingInterceptor() {
@Override
public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
return (timeoutCallback != null ? timeoutCallback.call() : CallableProcessingInterceptor.RESULT_NONE);