-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DROOLS-7480] Persist info to identify which activation is fired or not
- WIP Introduce PersistedSessionOption.ActivationStrategy
- Loading branch information
Showing
13 changed files
with
303 additions
and
29 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
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
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
68 changes: 68 additions & 0 deletions
68
...ols-reliability-core/src/main/java/org/drools/reliability/core/util/ReliabilityUtils.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,68 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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 org.drools.reliability.core.util; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; | ||
import org.drools.reliability.core.ReliabilityRuntimeException; | ||
import org.kie.api.runtime.rule.FactHandle; | ||
import org.kie.api.runtime.rule.Match; | ||
|
||
public class ReliabilityUtils { | ||
|
||
private ReliabilityUtils() { | ||
// no constructor | ||
} | ||
|
||
/** | ||
* Returns a String representation of the activation. | ||
*/ | ||
public static String getActivationKey(Match match) { | ||
return getActivationKey(match, null); | ||
} | ||
|
||
/** | ||
* Returns a String representation of the activation, replacing the new fact handle id with the old fact handle id. | ||
* Used to find an activation key in the persisted storage. | ||
*/ | ||
public static String getActivationKeyReplacingNewIdWithOldId(Match match, Map<Long, Long> factHandleIdMap) { | ||
return getActivationKey(match, factHandleIdMap); | ||
} | ||
|
||
private static String getActivationKey(Match match, Map<Long, Long> factHandleIdMap) { | ||
if (!(match instanceof RuleTerminalNodeLeftTuple)) { | ||
throw new ReliabilityRuntimeException("getActivationKey doesn't support " + match.getClass()); | ||
} | ||
RuleTerminalNodeLeftTuple ruleTerminalNodeLeftTuple = (RuleTerminalNodeLeftTuple) match; | ||
String packageName = ruleTerminalNodeLeftTuple.getRule().getPackageName(); | ||
String ruleName = ruleTerminalNodeLeftTuple.getRule().getName(); | ||
List<FactHandle> factHandles = ruleTerminalNodeLeftTuple.getFactHandles(); | ||
List<Long> factHandleIdList = factHandles.stream() | ||
.map(FactHandle::getId) | ||
.map(handleId -> { | ||
if (factHandleIdMap != null) { | ||
return factHandleIdMap.get(handleId); // replace new id with old id | ||
} else { | ||
return handleId; // don't replace | ||
} | ||
}) | ||
.collect(Collectors.toList()); | ||
return "ActivationKey [packageName=" + packageName + ", ruleName=" + ruleName + ", factHandleIdList=" + factHandleIdList + "]"; | ||
} | ||
} |
Oops, something went wrong.