Skip to content

Commit

Permalink
Parameterize AsyncTask type
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Oct 15, 2012
1 parent e98dc50 commit dbcbdac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @author Rossen Stoyanchev
* @since 3.2
*/
public class AsyncTask {
public class AsyncTask<V> {

private final Callable<?> callable;
private final Callable<V> callable;

private final Long timeout;

Expand All @@ -45,7 +45,7 @@ public class AsyncTask {
* @param timeout timeout value in milliseconds
* @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);
Assert.notNull(timeout, "Timeout must not be null");
}
Expand All @@ -55,7 +55,7 @@ public AsyncTask(long timeout, Callable<?> callable) {
* @param timeout timeout value in milliseconds; ignored if {@code null}
* @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);
Assert.notNull(executor, "Executor name must not be null");
}
Expand All @@ -65,12 +65,12 @@ public AsyncTask(Long timeout, String executorName, Callable<?> callable) {
* @param timeout timeout value in milliseconds; ignored if {@code null}
* @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);
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");
this.callable = callable;
this.timeout = timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void run() {
* @param processingContext additional context to save that can be accessed
* 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");

Long timeout = asyncTask.getTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public void startCallableProcessingAsyncTask() {
this.asyncWebRequest.startAsync();
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);

verify(executor, this.asyncWebRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void handleReturnValue(Object returnValue,
return;
}

AsyncTask asyncTask = (AsyncTask) returnValue;
AsyncTask<?> asyncTask = (AsyncTask<?>) returnValue;
asyncTask.setBeanFactory(this.beanFactory);
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(asyncTask.getCallable(), mavContainer);
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(asyncTask, mavContainer);
}

}

0 comments on commit dbcbdac

Please sign in to comment.