我有以下活动:
@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
不可用,工作流也会继续。
有什么想法吗?
答案 0 :(得分:0)
使用方法的@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);
}
当传递给Task构造函数的Promise类型的所有参数都准备就绪时,将调用任务doExecute方法。