Parameterize AsyncTask type
This commit is contained in:
parent
e98dc50f99
commit
dbcbdace9e
|
@ -27,9 +27,9 @@ import org.springframework.util.Assert;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class AsyncTask {
|
public class AsyncTask<V> {
|
||||||
|
|
||||||
private final Callable<?> callable;
|
private final Callable<V> callable;
|
||||||
|
|
||||||
private final Long timeout;
|
private final Long timeout;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class AsyncTask {
|
||||||
* @param timeout timeout value in milliseconds
|
* @param timeout timeout value in milliseconds
|
||||||
* @param callable the callable for concurrent handling
|
* @param callable the callable for concurrent handling
|
||||||
*/
|
*/
|
||||||
public AsyncTask(long timeout, Callable<?> callable) {
|
public AsyncTask(long timeout, Callable<V> callable) {
|
||||||
this(timeout, null, null, callable);
|
this(timeout, null, null, callable);
|
||||||
Assert.notNull(timeout, "Timeout must not be null");
|
Assert.notNull(timeout, "Timeout must not be null");
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class AsyncTask {
|
||||||
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
||||||
* @param callable the callable for concurrent handling
|
* @param callable the callable for concurrent handling
|
||||||
*/
|
*/
|
||||||
public AsyncTask(Long timeout, String executorName, Callable<?> callable) {
|
public AsyncTask(Long timeout, String executorName, Callable<V> callable) {
|
||||||
this(timeout, null, executorName, callable);
|
this(timeout, null, executorName, callable);
|
||||||
Assert.notNull(executor, "Executor name must not be null");
|
Assert.notNull(executor, "Executor name must not be null");
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,12 @@ public class AsyncTask {
|
||||||
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
* @param timeout timeout value in milliseconds; ignored if {@code null}
|
||||||
* @param callable the callable for concurrent handling
|
* @param callable the callable for concurrent handling
|
||||||
*/
|
*/
|
||||||
public AsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<?> callable) {
|
public AsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<V> callable) {
|
||||||
this(timeout, executor, null, callable);
|
this(timeout, executor, null, callable);
|
||||||
Assert.notNull(executor, "Executor must not be null");
|
Assert.notNull(executor, "Executor must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
private AsyncTask(Long timeout, AsyncTaskExecutor executor, String executorName, Callable<?> callable) {
|
private AsyncTask(Long timeout, AsyncTaskExecutor executor, String executorName, Callable<V> callable) {
|
||||||
Assert.notNull(callable, "Callable must not be null");
|
Assert.notNull(callable, "Callable must not be null");
|
||||||
this.callable = callable;
|
this.callable = callable;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
|
|
@ -260,7 +260,7 @@ public final class WebAsyncManager {
|
||||||
* @param processingContext additional context to save that can be accessed
|
* @param processingContext additional context to save that can be accessed
|
||||||
* via {@link #getConcurrentResultContext()}
|
* via {@link #getConcurrentResultContext()}
|
||||||
*/
|
*/
|
||||||
public void startCallableProcessing(AsyncTask asyncTask, Object... processingContext) {
|
public void startCallableProcessing(AsyncTask<?> asyncTask, Object... processingContext) {
|
||||||
Assert.notNull(asyncTask, "AsyncTask must not be null");
|
Assert.notNull(asyncTask, "AsyncTask must not be null");
|
||||||
|
|
||||||
Long timeout = asyncTask.getTimeout();
|
Long timeout = asyncTask.getTimeout();
|
||||||
|
|
|
@ -124,7 +124,8 @@ public class WebAsyncManagerTests {
|
||||||
this.asyncWebRequest.startAsync();
|
this.asyncWebRequest.startAsync();
|
||||||
replay(this.asyncWebRequest);
|
replay(this.asyncWebRequest);
|
||||||
|
|
||||||
AsyncTask asyncTask = new AsyncTask(1000L, executor, createMock(Callable.class));
|
@SuppressWarnings("unchecked")
|
||||||
|
AsyncTask<Object> asyncTask = new AsyncTask<Object>(1000L, executor, createMock(Callable.class));
|
||||||
this.asyncManager.startCallableProcessing(asyncTask);
|
this.asyncManager.startCallableProcessing(asyncTask);
|
||||||
|
|
||||||
verify(executor, this.asyncWebRequest);
|
verify(executor, this.asyncWebRequest);
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnVal
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncTask asyncTask = (AsyncTask) returnValue;
|
AsyncTask<?> asyncTask = (AsyncTask<?>) returnValue;
|
||||||
asyncTask.setBeanFactory(this.beanFactory);
|
asyncTask.setBeanFactory(this.beanFactory);
|
||||||
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(asyncTask.getCallable(), mavContainer);
|
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(asyncTask, mavContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue