-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
c7550de
commit 0d0958d
Showing
92 changed files
with
940 additions
and
722 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
76 changes: 76 additions & 0 deletions
76
...live-governance-api/src/main/java/com/jd/live/agent/governance/exception/ErrorPolicy.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,76 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file 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 com.jd.live.agent.governance.exception; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* An interface representing an error policy. | ||
*/ | ||
public interface ErrorPolicy { | ||
|
||
/** | ||
* Checks if the feature or functionality is enabled. | ||
* | ||
* @return true if the feature or functionality is enabled, false otherwise. | ||
*/ | ||
boolean isEnabled(); | ||
|
||
/** | ||
* Checks if the specified error code is present in the list of error codes. | ||
* | ||
* @param errorCode the error code to check. | ||
* @return {@code true} if the error code is present, {@code false} otherwise. | ||
*/ | ||
boolean containsError(String errorCode); | ||
|
||
/** | ||
* Checks if the given class name is present in the list of exceptions. | ||
* | ||
* @param className The class name to check. | ||
* @return true if the class name is found in the list of exceptions, false otherwise. | ||
*/ | ||
boolean containsException(String className); | ||
|
||
/** | ||
* Checks if any of the given class names are present in the list of exceptions. | ||
* | ||
* @param classNames The set of class names to check. | ||
* @return true if any of the class names are found in the list of exceptions, false otherwise. | ||
*/ | ||
boolean containsException(Set<String> classNames); | ||
|
||
/** | ||
* Checks if any of the exception sources are present in the set of target exceptions. | ||
* | ||
* @param sources the set of exception sources to check. | ||
* @param targets the set of target exceptions to check against. | ||
* @return true if any of the exception sources are found in the set of target exceptions, false otherwise. | ||
*/ | ||
static boolean containsException(Set<String> sources, Set<String> targets) { | ||
if (targets == null || targets.isEmpty() || sources == null || sources.isEmpty()) { | ||
return false; | ||
} | ||
Set<String> lows = sources.size() < targets.size() ? sources : targets; | ||
Set<String> mores = sources.size() < targets.size() ? targets : sources; | ||
for (String low : lows) { | ||
if (mores.contains(low)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...e-governance-api/src/main/java/com/jd/live/agent/governance/exception/ErrorPredicate.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,73 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file 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 com.jd.live.agent.governance.exception; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* An interface that defines a retry predicate used to determine if a failed operation should be retried. | ||
*/ | ||
public interface ErrorPredicate { | ||
|
||
/** | ||
* Returns the predicate used to determine if a failed operation should be retried. | ||
* | ||
* @return the retry predicate. | ||
*/ | ||
Predicate<Throwable> getPredicate(); | ||
|
||
/** | ||
* Returns the set of exception names that should be retried. | ||
* | ||
* @return the set of exception names. | ||
*/ | ||
Set<String> getExceptions(); | ||
|
||
/** | ||
* A default implementation of the ErrorPredicate interface. | ||
*/ | ||
@Getter | ||
class DefaultErrorPredicate implements ErrorPredicate { | ||
|
||
private final Predicate<Throwable> predicate; | ||
|
||
private final Set<String> exceptions; | ||
|
||
/** | ||
* Creates a new instance of the DefaultErrorPredicate class. | ||
* | ||
* @param predicate the predicate used to determine if a failed operation should be retried. | ||
* @param exceptions the set of exception names that should be retried. | ||
*/ | ||
public DefaultErrorPredicate(Predicate<Throwable> predicate, Set<String> exceptions) { | ||
this.predicate = predicate; | ||
this.exceptions = exceptions; | ||
} | ||
|
||
@Override | ||
public Predicate<Throwable> getPredicate() { | ||
return predicate; | ||
} | ||
|
||
@Override | ||
public Set<String> getExceptions() { | ||
return exceptions; | ||
} | ||
} | ||
} |
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.