|
1 | 1 | /*
|
| 2 | + * Modifications Copyright (c) 2017-2020 Uber Technologies Inc. |
| 3 | + * Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc. |
2 | 4 | * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 | 5 | *
|
4 |
| - * Modifications copyright (C) 2017 Uber Technologies, Inc. |
5 |
| - * |
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
7 | 7 | * use this file except in compliance with the License. A copy of the License is
|
8 | 8 | * located at
|
|
29 | 29 | /** Options used to configure how an activity is invoked. */
|
30 | 30 | public final class ActivityOptions {
|
31 | 31 |
|
32 |
| - /** |
33 |
| - * Used to merge annotation and options. Options takes precedence. Returns options with all |
34 |
| - * defaults filled in. |
35 |
| - */ |
36 |
| - public static ActivityOptions merge(ActivityMethod a, MethodRetry r, ActivityOptions o) { |
37 |
| - if (a == null) { |
38 |
| - if (r == null) { |
39 |
| - return new ActivityOptions.Builder(o).validateAndBuildWithDefaults(); |
40 |
| - } |
41 |
| - RetryOptions mergedR = RetryOptions.merge(r, o.getRetryOptions()); |
42 |
| - return new ActivityOptions.Builder().setRetryOptions(mergedR).validateAndBuildWithDefaults(); |
43 |
| - } |
44 |
| - if (o == null) { |
45 |
| - o = new ActivityOptions.Builder().build(); |
46 |
| - } |
47 |
| - return new ActivityOptions.Builder() |
48 |
| - .setScheduleToCloseTimeout( |
49 |
| - mergeDuration(a.scheduleToCloseTimeoutSeconds(), o.getScheduleToCloseTimeout())) |
50 |
| - .setScheduleToStartTimeout( |
51 |
| - mergeDuration(a.scheduleToStartTimeoutSeconds(), o.getScheduleToStartTimeout())) |
52 |
| - .setStartToCloseTimeout( |
53 |
| - mergeDuration(a.startToCloseTimeoutSeconds(), o.getStartToCloseTimeout())) |
54 |
| - .setHeartbeatTimeout(mergeDuration(a.heartbeatTimeoutSeconds(), o.getHeartbeatTimeout())) |
55 |
| - .setTaskList( |
56 |
| - o.getTaskList() != null |
57 |
| - ? o.getTaskList() |
58 |
| - : (a.taskList().isEmpty() ? null : a.taskList())) |
59 |
| - .setRetryOptions(RetryOptions.merge(r, o.getRetryOptions())) |
60 |
| - .setContextPropagators(o.getContextPropagators()) |
61 |
| - .validateAndBuildWithDefaults(); |
| 32 | + public static Builder newBuilder() { |
| 33 | + return new Builder(); |
| 34 | + } |
| 35 | + |
| 36 | + public static Builder newBuilder(ActivityOptions options) { |
| 37 | + return new Builder(options); |
| 38 | + } |
| 39 | + |
| 40 | + public static ActivityOptions getDefaultInstance() { |
| 41 | + return DEFAULT_INSTANCE; |
| 42 | + } |
| 43 | + |
| 44 | + private static final ActivityOptions DEFAULT_INSTANCE; |
| 45 | + |
| 46 | + static { |
| 47 | + DEFAULT_INSTANCE = ActivityOptions.newBuilder().build(); |
62 | 48 | }
|
63 | 49 |
|
64 | 50 | public static final class Builder {
|
@@ -155,6 +141,14 @@ public Builder setContextPropagators(List<ContextPropagator> contextPropagators)
|
155 | 141 | return this;
|
156 | 142 | }
|
157 | 143 |
|
| 144 | + /** |
| 145 | + * Properties that are set on this builder take precedence over ones found in the annotation. |
| 146 | + */ |
| 147 | + public Builder setMethodRetry(MethodRetry r) { |
| 148 | + retryOptions = RetryOptions.merge(r, retryOptions); |
| 149 | + return this; |
| 150 | + } |
| 151 | + |
158 | 152 | public ActivityOptions build() {
|
159 | 153 | return new ActivityOptions(
|
160 | 154 | heartbeatTimeout,
|
@@ -324,15 +318,4 @@ public int hashCode() {
|
324 | 318 | retryOptions,
|
325 | 319 | contextPropagators);
|
326 | 320 | }
|
327 |
| - |
328 |
| - static Duration mergeDuration(int annotationSeconds, Duration options) { |
329 |
| - if (options == null) { |
330 |
| - if (annotationSeconds == 0) { |
331 |
| - return null; |
332 |
| - } |
333 |
| - return Duration.ofSeconds(annotationSeconds); |
334 |
| - } else { |
335 |
| - return options; |
336 |
| - } |
337 |
| - } |
338 | 321 | }
|
0 commit comments