17
17
18
18
package com .uber .cadence .internal .sync ;
19
19
20
+ import com .google .common .base .Strings ;
21
+ import com .uber .cadence .activity .ActivityMethod ;
20
22
import com .uber .cadence .activity .ActivityOptions ;
21
23
import com .uber .cadence .common .MethodRetry ;
22
24
import com .uber .cadence .workflow .ActivityStub ;
23
25
import com .uber .cadence .workflow .WorkflowInterceptor ;
24
26
import java .lang .reflect .InvocationHandler ;
25
27
import java .lang .reflect .Method ;
28
+ import java .time .Duration ;
26
29
import java .util .function .Function ;
27
30
28
31
class ActivityInvocationHandler extends ActivityInvocationHandlerBase {
@@ -41,12 +44,37 @@ private ActivityInvocationHandler(
41
44
init (activityInterface );
42
45
}
43
46
47
+ @ SuppressWarnings ("deprecation" )
44
48
@ Override
45
49
protected Function <Object [], Object > getActivityFunc (
46
- Method method , MethodRetry methodRetry , String activityName ) {
50
+ Method method , MethodRetry methodRetry , ActivityMethod activityMethod , String activityName ) {
47
51
Function <Object [], Object > function ;
48
- ActivityOptions mergedOptions =
49
- ActivityOptions .newBuilder (options ).setMethodRetry (methodRetry ).build ();
52
+ ActivityOptions .Builder optionsBuilder =
53
+ ActivityOptions .newBuilder (options ).setMethodRetry (methodRetry );
54
+ if (activityMethod != null ) {
55
+ // options always take precedence over activity method annotation.
56
+ if (options .getStartToCloseTimeout () == null ) {
57
+ optionsBuilder .setStartToCloseTimeout (
58
+ Duration .ofSeconds (activityMethod .startToCloseTimeoutSeconds ()));
59
+ }
60
+ if (options .getScheduleToStartTimeout () == null ) {
61
+ optionsBuilder .setScheduleToStartTimeout (
62
+ Duration .ofSeconds (activityMethod .scheduleToStartTimeoutSeconds ()));
63
+ }
64
+ if (options .getScheduleToCloseTimeout () == null ) {
65
+ optionsBuilder .setScheduleToCloseTimeout (
66
+ Duration .ofSeconds (activityMethod .scheduleToCloseTimeoutSeconds ()));
67
+ }
68
+ if (options .getHeartbeatTimeout () == null ) {
69
+ optionsBuilder .setHeartbeatTimeout (
70
+ Duration .ofSeconds (activityMethod .heartbeatTimeoutSeconds ()));
71
+ }
72
+ if (Strings .isNullOrEmpty (options .getTaskList ())
73
+ && !Strings .isNullOrEmpty (activityMethod .taskList ())) {
74
+ optionsBuilder .setTaskList (activityMethod .taskList ());
75
+ }
76
+ }
77
+ ActivityOptions mergedOptions = optionsBuilder .build ();
50
78
ActivityStub stub = ActivityStubImpl .newInstance (mergedOptions , activityExecutor );
51
79
52
80
function =
0 commit comments