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.
Fixed precedence of LocalActivityOptions
- Loading branch information
Showing
9 changed files
with
335 additions
and
113 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
temporal-sdk/src/main/java/io/temporal/internal/common/ActivityOptionUtils.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
temporal-sdk/src/main/java/io/temporal/internal/common/MergedLocalActivityOptions.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,100 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 io.temporal.internal.common; | ||
|
||
import io.temporal.activity.LocalActivityOptions; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* The chain of LocalActivityOptions and per type options maps. Used to merge options specified at | ||
* the following layers: | ||
* | ||
* <pre> | ||
* * WorkflowImplementationOptions | ||
* * Workflow | ||
* * ActivityStub | ||
* </pre> | ||
* | ||
* Each next layer overrides specific options specified at the previous layer. | ||
*/ | ||
public final class MergedLocalActivityOptions { | ||
|
||
/** Common options across all activity types. */ | ||
private LocalActivityOptions defaultOptions; | ||
|
||
/** Per activity type options. These override defaultOptions. */ | ||
private final Map<String, LocalActivityOptions> optionsMap = new HashMap<>(); | ||
|
||
/** The options specified at the previous layer. They are overriden by this object. */ | ||
private final MergedLocalActivityOptions overridden; | ||
|
||
public MergedLocalActivityOptions( | ||
MergedLocalActivityOptions overridden, | ||
LocalActivityOptions defaultOptions, | ||
Map<String, LocalActivityOptions> optionsMap) { | ||
this.overridden = overridden; | ||
this.defaultOptions = defaultOptions; | ||
if (optionsMap != null) { | ||
this.optionsMap.putAll(optionsMap); | ||
} | ||
} | ||
|
||
public MergedLocalActivityOptions(MergedLocalActivityOptions overridden) { | ||
this.overridden = overridden; | ||
defaultOptions = null; | ||
} | ||
|
||
public void setDefaultOptions(LocalActivityOptions defaultOptions) { | ||
this.defaultOptions = defaultOptions; | ||
} | ||
|
||
public void applyOptionsMap(Map<String, LocalActivityOptions> optionsMap) { | ||
if (optionsMap != null) { | ||
this.optionsMap.putAll(optionsMap); | ||
} | ||
} | ||
|
||
/** Get merged options for the given activityType. */ | ||
public LocalActivityOptions getMergedOptions(String activityType) { | ||
LocalActivityOptions overrideOptions = null; | ||
if (overridden != null) { | ||
overrideOptions = overridden.getMergedOptions(activityType); | ||
} | ||
return merge(overrideOptions, defaultOptions, optionsMap.get(activityType)); | ||
} | ||
|
||
/** later options override the previous ones */ | ||
private static LocalActivityOptions merge(LocalActivityOptions... options) { | ||
if (options == null || options.length == 0) { | ||
return null; | ||
} | ||
LocalActivityOptions result = options[0]; | ||
for (int i = 1; i < options.length; i++) { | ||
if (result == null) { | ||
result = options[i]; | ||
} else { | ||
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
Oops, something went wrong.