mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Enforce strong typing for getting result from AsyncMethod
This commit is contained in:
parent
e2078ec6e4
commit
6504fc6b09
@ -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()) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user