Enforce strong typing for getting result from AsyncMethod

This commit is contained in:
Kelven Yang 2013-01-02 15:48:45 -08:00
parent e2078ec6e4
commit 6504fc6b09
2 changed files with 11 additions and 11 deletions

View File

@ -175,7 +175,7 @@ public class VolumeServiceImpl implements VolumeService {
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOAD_IN_PROGRESS);
CreateBaseImageContext<VolumeInfo> context = new CreateBaseImageContext<VolumeInfo>(callback, volume, dataStore, templateOnPrimaryStoreObj);
AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createBaseImageCallback(null, null))
.setContext(context);
@ -183,7 +183,7 @@ public class VolumeServiceImpl implements VolumeService {
}
@DB
public Object createBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateBaseImageContext<VolumeInfo> context) {
public Object createBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, CreateBaseImageContext<VolumeInfo> context) {
CommandResult result = callback.getResult();
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = context.getTemplate();
if (result.isSuccess()) {
@ -222,7 +222,7 @@ public class VolumeServiceImpl implements VolumeService {
}
CreateVolumeFromBaseImageContext<VolumeInfo> context = new CreateVolumeFromBaseImageContext<VolumeInfo>(callback, vo);
AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallback(null, null))
.setContext(context);
@ -230,7 +230,7 @@ public class VolumeServiceImpl implements VolumeService {
}
@DB
public Object createVolumeFromBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateVolumeFromBaseImageContext<VolumeInfo> context) {
public Object createVolumeFromBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, CreateVolumeFromBaseImageContext<VolumeInfo> context) {
VolumeObject vo = context.getVolumeObject();
CommandResult result = callback.getResult();
if (result.isSuccess()) {

View File

@ -29,7 +29,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@SuppressWarnings("rawtypes")
public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
public class AsyncCallbackDispatcher<T, R> implements AsyncCompletionCallback {
private Method _callbackMethod;
private T _targetObject;
private Object _contextObject;
@ -41,7 +41,7 @@ public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
_targetObject = target;
}
public AsyncCallbackDispatcher<T> attachDriver(AsyncCallbackDriver driver) {
public AsyncCallbackDispatcher<T, R> attachDriver(AsyncCallbackDriver driver) {
assert(driver != null);
_driver = driver;
@ -83,11 +83,11 @@ public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
return (T)en.create();
}
public AsyncCallbackDispatcher<T> setCallback(Object useless) {
public AsyncCallbackDispatcher<T, R> setCallback(Object useless) {
return this;
}
public AsyncCallbackDispatcher<T> setContext(Object context) {
public AsyncCallbackDispatcher<T, R> setContext(Object context) {
_contextObject = context;
return this;
}
@ -103,7 +103,7 @@ public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
}
@SuppressWarnings("unchecked")
public <R> R getResult() {
public R getResult() {
return (R)_resultObject;
}
@ -112,8 +112,8 @@ public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
return _targetObject;
}
public static <P> AsyncCallbackDispatcher<P> create(P target) {
return new AsyncCallbackDispatcher<P>(target);
public static <P, R> AsyncCallbackDispatcher<P, R> create(P target) {
return new AsyncCallbackDispatcher<P, R>(target);
}
public static boolean dispatch(Object target, AsyncCallbackDispatcher callback) {