temporal 工作流注册关键代码
所属分类 temporal
浏览量 801
io.temporal.internal.sync.POJOWorkflowImplementationFactory.registerWorkflowImplementationType(WorkflowImplementationOptions, Class)
POJOWorkflowMethodMetadata methodMetadata = workflowMethod.get();
String workflowName = methodMetadata.getName();
workflowDefinitions.put(workflowName, factory);
implementationOptions.put(workflowName, options);
private final Map> workflowDefinitions =
Collections.synchronizedMap(new HashMap<>());
private final Map implementationOptions =
Collections.synchronizedMap(new HashMap<>());
private final Map, Functions.Func>> workflowImplementationFactories =
Collections.synchronizedMap(new HashMap<>());
@WorkflowInterface
public interface EchoWorkflow {
// 只能有一个 @WorkflowMethod
// java.lang.IllegalArgumentException: Duplicated @WorkflowMethod
// Name of the workflow type. Default is short class name
@WorkflowMethod
String echo(String msg,long rt);
}
io.temporal.internal.sync.POJOActivityTaskHandler.registerActivityImplementation(Object, BiFunction)
private final Map activities = Collections.synchronizedMap(new HashMap<>());
private void registerActivityImplementation(
Object activity, BiFunction newTaskExecutor) {
if (activity instanceof Class) {
throw new IllegalArgumentException("Activity object instance expected, not the class");
}
if (activity instanceof DynamicActivity) {
if (dynamicActivity != null) {
throw new IllegalStateException(
"An implementation of DynamicActivity is already registered with the worker");
}
dynamicActivity = new DynamicActivityImplementation((DynamicActivity) activity);
return;
}
Class> cls = activity.getClass();
POJOActivityImplMetadata activityImplMetadata = POJOActivityImplMetadata.newInstance(cls);
for (POJOActivityInterfaceMetadata activityInterface :
activityImplMetadata.getActivityInterfaces()) {
for (POJOActivityMethodMetadata activityMetadata : activityInterface.getMethodsMetadata()) {
String typeName = activityMetadata.getActivityTypeName();
if (activities.containsKey(typeName)) {
throw new IllegalArgumentException(
"\"" + typeName + "\" activity type is already registered with the worker");
}
Method method = activityMetadata.getMethod();
ActivityTaskExecutor implementation = newTaskExecutor.apply(method, activity);
activities.put(typeName, implementation);
}
}
}
// 一定要加该注解
// java.lang.IllegalArgumentException: Class doesn't implement any non empty interface annotated with @ActivityInterface: com.dyyx.temporal.demo.echo.multi.EchoActivityMultiMethodsImpl
@ActivityInterface
public interface EchoActivityMultiMethods {
@ActivityMethod(name = "echo1")
String echo1(String msg, long rt);
@ActivityMethod(name = "echo2")
String echo2(String msg, long rt);
}
上一篇
下一篇
temporal worker 线程信息 及 轮询获取工作流关键代码
不使用for和while 实现循环效果
temporal 多个 worker 实例 测试说明
PostgreSQL encode 函数
MySQL jdbc 版本问题导致 连接错误
java Virtual Threads 虚拟线程