首页  

temporal 工作流注册关键代码     所属分类 temporal 浏览量 801


io.temporal.internal.sync.POJOWorkflowImplementationFactory.registerWorkflowImplementationType(WorkflowImplementationOptions, Class<T>)

POJOWorkflowMethodMetadata methodMetadata = workflowMethod.get();
String workflowName = methodMetadata.getName();
      
workflowDefinitions.put(workflowName, factory);
implementationOptions.put(workflowName, options);
      
  private final Map<String, Functions.Func<SyncWorkflowDefinition>> workflowDefinitions =
      Collections.synchronizedMap(new HashMap<>());

  private final Map<String, WorkflowImplementationOptions> implementationOptions =
      Collections.synchronizedMap(new HashMap<>());

  private final Map<Class<?>, 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<Method, Object, ActivityTaskExecutor>)

private final Map<String, ActivityTaskExecutor> activities = Collections.synchronizedMap(new HashMap<>());
      
      
 private void registerActivityImplementation(
      Object activity, BiFunction<Method, Object, ActivityTaskExecutor> 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 虚拟线程