-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathLocalActivityOptions.java
161 lines (134 loc) · 4.85 KB
/
LocalActivityOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
* Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.uber.cadence.activity;
import static com.uber.cadence.internal.common.OptionsUtils.roundUpToSeconds;
import com.uber.cadence.common.MethodRetry;
import com.uber.cadence.common.RetryOptions;
import com.uber.cadence.context.ContextPropagator;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
/** Options used to configure how an local activity is invoked. */
public final class LocalActivityOptions {
public static Builder newBuilder() {
return new Builder(null);
}
/** @param o null is allowed */
public static Builder newBuilder(LocalActivityOptions o) {
return new Builder(o);
}
public static LocalActivityOptions getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final LocalActivityOptions DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = LocalActivityOptions.newBuilder().build();
}
public static final class Builder {
private Duration scheduleToCloseTimeout;
private RetryOptions retryOptions;
private List<ContextPropagator> contextPropagators;
public Builder() {}
/** Copy Builder fields from the options. */
public Builder(LocalActivityOptions options) {
if (options == null) {
return;
}
this.scheduleToCloseTimeout = options.getScheduleToCloseTimeout();
this.retryOptions = options.retryOptions;
}
/** Overall timeout workflow is willing to wait for activity to complete. */
public Builder setScheduleToCloseTimeout(Duration scheduleToCloseTimeout) {
this.scheduleToCloseTimeout = scheduleToCloseTimeout;
return this;
}
/**
* RetryOptions that define how activity is retried in case of failure. Default is null which is
* no reties.
*/
public Builder setRetryOptions(RetryOptions retryOptions) {
this.retryOptions = retryOptions;
return this;
}
public Builder setContextPropagators(List<ContextPropagator> contextPropagators) {
this.contextPropagators = contextPropagators;
return this;
}
/**
* Merges MethodRetry annotation. The values of this builder take precedence over annotation
* ones.
*/
public Builder setMethodRetry(MethodRetry r) {
if (r != null) {
this.retryOptions = RetryOptions.merge(r, retryOptions);
}
return this;
}
public LocalActivityOptions build() {
return new LocalActivityOptions(scheduleToCloseTimeout, retryOptions, contextPropagators);
}
public LocalActivityOptions validateAndBuildWithDefaults() {
RetryOptions ro = null;
if (retryOptions != null) {
ro = new RetryOptions.Builder(retryOptions).validateBuildWithDefaults();
}
return new LocalActivityOptions(
roundUpToSeconds(scheduleToCloseTimeout), ro, contextPropagators);
}
}
private final Duration scheduleToCloseTimeout;
private final RetryOptions retryOptions;
private final List<ContextPropagator> contextPropagators;
private LocalActivityOptions(
Duration scheduleToCloseTimeout,
RetryOptions retryOptions,
List<ContextPropagator> contextPropagators) {
this.scheduleToCloseTimeout = scheduleToCloseTimeout;
this.retryOptions = retryOptions;
this.contextPropagators = contextPropagators;
}
public Duration getScheduleToCloseTimeout() {
return scheduleToCloseTimeout;
}
public RetryOptions getRetryOptions() {
return retryOptions;
}
public List<ContextPropagator> getContextPropagators() {
return contextPropagators;
}
@Override
public String toString() {
return "LocalActivityOptions{"
+ "scheduleToCloseTimeout="
+ scheduleToCloseTimeout
+ ", retryOptions="
+ retryOptions
+ '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LocalActivityOptions that = (LocalActivityOptions) o;
return Objects.equals(scheduleToCloseTimeout, that.scheduleToCloseTimeout)
&& Objects.equals(retryOptions, that.retryOptions);
}
@Override
public int hashCode() {
return Objects.hash(scheduleToCloseTimeout, retryOptions);
}
}