forked from temporalio/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
temporal-sdk/src/main/java/io/temporal/internal/common/ActivityOptionsWithDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.temporal.internal.common; | ||
|
||
import io.temporal.activity.ActivityOptions; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class ActivityOptionsWithDefault { | ||
private ActivityOptions defaultOptions; | ||
|
||
private Map<String, ActivityOptions> optionsMap; | ||
|
||
private final ActivityOptionsWithDefault overridden; | ||
|
||
public ActivityOptionsWithDefault( | ||
ActivityOptionsWithDefault overridden, | ||
ActivityOptions defaultOptions, | ||
Map<String, ActivityOptions> optionsMap) { | ||
this.overridden = overridden; | ||
this.defaultOptions = defaultOptions; | ||
this.optionsMap = new HashMap<>(optionsMap); | ||
} | ||
|
||
public ActivityOptionsWithDefault(ActivityOptionsWithDefault overridden) { | ||
this.overridden = overridden; | ||
defaultOptions = null; | ||
optionsMap = null; | ||
} | ||
|
||
public void setDefaultOptions(ActivityOptions defaultOptions) { | ||
this.defaultOptions = defaultOptions; | ||
} | ||
|
||
public void setOptionsMap(Map<String, ActivityOptions> optionsMap) { | ||
this.optionsMap = optionsMap; | ||
} | ||
|
||
public ActivityOptions getMergedOptions(String activityType) { | ||
ActivityOptions overrideOptions = overridden.getMergedOptions(activityType); | ||
return merge(overrideOptions, defaultOptions, optionsMap.get(activityType)); | ||
} | ||
|
||
/** later options override the previous ones */ | ||
private static ActivityOptions merge(ActivityOptions... options) { | ||
if (options == null || options.length == 0) { | ||
return null; | ||
} | ||
ActivityOptions result = options[0]; | ||
for (int i = 1; i < options.length; i++) { | ||
result = result.toBuilder().mergeActivityOptions(options[i]).build(); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters