我有以下活动:
@ActivityRegistrationOptions(defaultTaskScheduleToStartTimeoutSeconds = 300, defaultTaskStartToCloseTimeoutSeconds = 10)
@Activities(version="1.0")
public interface MyActivities {
B first(A a) throws Exception;
void second(C c) throws Exception;
}
我有以下工作流程:
public class MyWorkflowImpl implements MyWorkflow {
@Autowired
private MyActivitiesClient operations;
@Override
public void start(SomeType input) {
A a = new A(...);
Promise<B> b = operations.first(a);
Promise<C> c = ...;
/* Here, I would like to create c based on b */
operations.second(c);
}
}
现在b
直到第一次操作完成,但是即使b
不可用,工作流程仍在继续。
有什么想法?
使用方法的@AsynChronous注释:
public void start(SomeType input) {
A a = new A(...);
Promise<B> b = operations.first(a);
Promise<C> c = ...;
operations.second(c);
}
@Asynchronous
private Promise<C> calculateC(Promise<B> b) {
Settable<C> result = new Settable<C>();
/* Here create c based on b */
result.set(b.get()....);
return result;
}
一种被注释为@AsynChronous的方法内部转换为回调,当它的所有类型Promise的参数都准备就绪时被调用。@AsynChronous实现依赖于ASPECJ,因此请确保仔细遵循设置说明以启用它。
另一个选择是使用任务:
@Override
public void start(SomeType input) {
A a = new A(...);
Promise<B> b = operations.first(a);
Promise<C> c = new Settable<C>();
new Task(b) {
protected void doExecute() {
/* Here c based on b */
c.set(b.get() ....);
}
}
operations.second(c);
}
任务doexecute方法将被调用。