forked from spring-projects/spring-retry
-
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
1 parent
c2c3acb
commit f2c98b7
Showing
4 changed files
with
163 additions
and
4 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
93 changes: 93 additions & 0 deletions
93
src/main/java/org/springframework/retry/policy/ExpressionRetryPolicy.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,93 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* 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 org.springframework.retry.policy; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.expression.Expression; | ||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
import org.springframework.retry.RetryContext; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* @author Gary Russell | ||
* @since 1.2 | ||
* | ||
*/ | ||
public class ExpressionRetryPolicy extends SimpleRetryPolicy { | ||
|
||
private final Expression expression; | ||
|
||
/** | ||
* Construct an instance with the provided {@link Expression}. | ||
* @param expression the expression | ||
*/ | ||
public ExpressionRetryPolicy(Expression expression) { | ||
super(); | ||
Assert.notNull(expression, "'expression' cannot be null"); | ||
this.expression = expression; | ||
} | ||
|
||
/** | ||
* Construct an instance with the provided expression. | ||
* @param expressionString the expression. | ||
*/ | ||
public ExpressionRetryPolicy(String expressionString) { | ||
super(); | ||
Assert.notNull(expressionString, "'expressionString' cannot be null"); | ||
this.expression = new SpelExpressionParser().parseExpression(expressionString); | ||
} | ||
|
||
/** | ||
* Construct an instance with the provided {@link Expression}. | ||
* @param maxAttempts the max attempts | ||
* @param retryableExceptions the exceptions | ||
* @param traverseCauses true to examine causes | ||
* @param expression the expression | ||
*/ | ||
public ExpressionRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions, | ||
boolean traverseCauses, Expression expression) { | ||
super(maxAttempts, retryableExceptions, traverseCauses); | ||
Assert.notNull(expression, "'expression' cannot be null"); | ||
this.expression = expression; | ||
} | ||
|
||
/** | ||
* Construct an instance with the provided expression. | ||
* @param maxAttempts the max attempts | ||
* @param retryableExceptions the exceptions | ||
* @param traverseCauses true to examine causes | ||
* @param expressionString the expression. | ||
*/ | ||
public ExpressionRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions, | ||
boolean traverseCauses, String expressionString) { | ||
super(maxAttempts, retryableExceptions, traverseCauses); | ||
Assert.notNull(expressionString, "'expressionString' cannot be null"); | ||
this.expression = new SpelExpressionParser().parseExpression(expressionString); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
garyrussell
Author
Owner
|
||
} | ||
|
||
@Override | ||
public boolean canRetry(RetryContext context) { | ||
Throwable lastThrowable = context.getLastThrowable(); | ||
if (lastThrowable == null) { | ||
return super.canRetry(context); | ||
} | ||
else { | ||
return super.canRetry(context) && this.expression.getValue(lastThrowable, Boolean.class); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
garyrussell
Author
Owner
|
||
} | ||
} | ||
|
||
} |
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
1 comment
on commit f2c98b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks for jumping on this!
Not sure how the error handling bubbles up in this mechanism, I would just make sure that any parse errors are properly logged.