Upon reviewer's request:
(FIX) Deleted .puml file (no longer required or used) (FIX) Removed @since annotations (they add noise)
This commit is contained in:
parent
10c0879d3b
commit
c1ea04e002
@ -1,38 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.retry {
|
|
||||||
class App {
|
|
||||||
- LOG : Logger {static}
|
|
||||||
- op : BusinessOperation<String> {static}
|
|
||||||
+ App()
|
|
||||||
- errorNoRetry() {static}
|
|
||||||
- errorWithRetry() {static}
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
- noErrors() {static}
|
|
||||||
}
|
|
||||||
interface BusinessOperation<T> {
|
|
||||||
+ perform() : T {abstract}
|
|
||||||
}
|
|
||||||
class FindCustomer {
|
|
||||||
- customerId : String
|
|
||||||
- errors : Deque<BusinessException>
|
|
||||||
+ FindCustomer(customerId : String, errors : BusinessException[])
|
|
||||||
+ perform() : String
|
|
||||||
}
|
|
||||||
class Retry<T> {
|
|
||||||
- attempts : AtomicInteger
|
|
||||||
- delay : long
|
|
||||||
- errors : List<Exception>
|
|
||||||
- maxAttempts : int
|
|
||||||
- op : BusinessOperation<T>
|
|
||||||
- test : Predicate<Exception>
|
|
||||||
+ Retry<T>(op : BusinessOperation<T>, maxAttempts : int, delay : long, ignoreTests : Predicate<Exception>[])
|
|
||||||
+ attempts() : int
|
|
||||||
+ errors() : List<Exception>
|
|
||||||
+ perform() : T
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Retry --> "-op" BusinessOperation
|
|
||||||
App --> "-op" BusinessOperation
|
|
||||||
FindCustomer ..|> BusinessOperation
|
|
||||||
Retry ..|> BusinessOperation
|
|
||||||
@enduml
|
|
50
retry/licenseheader.txt
Normal file
50
retry/licenseheader.txt
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
====
|
||||||
|
The MIT License
|
||||||
|
Copyright (c) 2014 Ilkka Seppälä
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
====
|
||||||
|
|
||||||
|
<#if licenseFirst??>
|
||||||
|
${licenseFirst}
|
||||||
|
</#if>
|
||||||
|
${licensePrefix}The MIT License (MIT)
|
||||||
|
${licensePrefix}
|
||||||
|
${licensePrefix}Copyright (c) 2014-2016 Ilkka Seppälä
|
||||||
|
${licensePrefix}
|
||||||
|
${licensePrefix}Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
${licensePrefix}of this software and associated documentation files (the "Software"), to deal
|
||||||
|
${licensePrefix}in the Software without restriction, including without limitation the rights
|
||||||
|
${licensePrefix}to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
${licensePrefix}copies of the Software, and to permit persons to whom the Software is
|
||||||
|
${licensePrefix}furnished to do so, subject to the following conditions:
|
||||||
|
${licensePrefix}
|
||||||
|
${licensePrefix}The above copyright notice and this permission notice shall be included in all
|
||||||
|
${licensePrefix}copies or substantial portions of the Software.
|
||||||
|
${licensePrefix}
|
||||||
|
${licensePrefix}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
${licensePrefix}IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
${licensePrefix}FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
${licensePrefix}AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
${licensePrefix}LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
${licensePrefix}OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
${licensePrefix}SOFTWARE.
|
||||||
|
<#if licenseLast??>
|
||||||
|
${licenseLast}
|
||||||
|
</#if>
|
18
retry/nb-configuration.xml
Normal file
18
retry/nb-configuration.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<netbeans.hint.licensePath>${project.basedir}/licenseheader.txt</netbeans.hint.licensePath>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
23
retry/nbproject/project.properties
Normal file
23
retry/nbproject/project.properties
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# The MIT License
|
||||||
|
# Copyright (c) 2014 Ilkka Seppälä
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
# THE SOFTWARE.
|
||||||
|
#
|
||||||
|
|
@ -56,7 +56,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @see <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/retry">Retry pattern (Microsoft Azure Docs)</a>
|
* @see <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/retry">Retry pattern (Microsoft Azure Docs)</a>
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public final class App {
|
public final class App {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(App.class);
|
private static final Logger LOG = LoggerFactory.getLogger(App.class);
|
||||||
@ -67,7 +66,6 @@ public final class App {
|
|||||||
*
|
*
|
||||||
* @param args not used
|
* @param args not used
|
||||||
* @throws Exception not expected
|
* @throws Exception not expected
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
noErrors();
|
noErrors();
|
||||||
|
@ -31,7 +31,6 @@ package com.iluwatar.retry;
|
|||||||
* be able to handle this error and should be reported to the maintainers immediately.
|
* be able to handle this error and should be reported to the maintainers immediately.
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public class BusinessException extends Exception {
|
public class BusinessException extends Exception {
|
||||||
private static final long serialVersionUID = 6235833142062144336L;
|
private static final long serialVersionUID = 6235833142062144336L;
|
||||||
@ -40,7 +39,6 @@ public class BusinessException extends Exception {
|
|||||||
* Ctor
|
* Ctor
|
||||||
*
|
*
|
||||||
* @param message the error message
|
* @param message the error message
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public BusinessException(String message) {
|
public BusinessException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -29,7 +29,6 @@ package com.iluwatar.retry;
|
|||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @param <T> the return type
|
* @param <T> the return type
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface BusinessOperation<T> {
|
public interface BusinessOperation<T> {
|
||||||
@ -40,7 +39,6 @@ public interface BusinessOperation<T> {
|
|||||||
* @return the return value
|
* @return the return value
|
||||||
* @throws BusinessException if the operation fails. Implementations are allowed to throw more
|
* @throws BusinessException if the operation fails. Implementations are allowed to throw more
|
||||||
* specific subtypes depending on the error conditions
|
* specific subtypes depending on the error conditions
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
T perform() throws BusinessException;
|
T perform() throws BusinessException;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ package com.iluwatar.retry;
|
|||||||
* by an input from some end user, or were the search parameters pulled from your database?
|
* by an input from some end user, or were the search parameters pulled from your database?
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public final class CustomerNotFoundException extends BusinessException {
|
public final class CustomerNotFoundException extends BusinessException {
|
||||||
private static final long serialVersionUID = -6972888602621778664L;
|
private static final long serialVersionUID = -6972888602621778664L;
|
||||||
@ -40,7 +39,6 @@ public final class CustomerNotFoundException extends BusinessException {
|
|||||||
* Ctor.
|
* Ctor.
|
||||||
*
|
*
|
||||||
* @param message the error message
|
* @param message the error message
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public CustomerNotFoundException(String message) {
|
public CustomerNotFoundException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -28,7 +28,6 @@ package com.iluwatar.retry;
|
|||||||
* Catastrophic error indicating that we have lost connection to our database.
|
* Catastrophic error indicating that we have lost connection to our database.
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public final class DatabaseNotAvailableException extends BusinessException {
|
public final class DatabaseNotAvailableException extends BusinessException {
|
||||||
private static final long serialVersionUID = -3750769625095997799L;
|
private static final long serialVersionUID = -3750769625095997799L;
|
||||||
@ -37,7 +36,6 @@ public final class DatabaseNotAvailableException extends BusinessException {
|
|||||||
* Ctor.
|
* Ctor.
|
||||||
*
|
*
|
||||||
* @param message the error message
|
* @param message the error message
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public DatabaseNotAvailableException(String message) {
|
public DatabaseNotAvailableException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -36,7 +36,6 @@ import java.util.Deque;
|
|||||||
* purposes of this example it fails in a programmed way depending on the constructor parameters.
|
* purposes of this example it fails in a programmed way depending on the constructor parameters.
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public final class FindCustomer implements BusinessOperation<String> {
|
public final class FindCustomer implements BusinessOperation<String> {
|
||||||
private final String customerId;
|
private final String customerId;
|
||||||
@ -47,7 +46,6 @@ public final class FindCustomer implements BusinessOperation<String> {
|
|||||||
*
|
*
|
||||||
* @param customerId the final result of the remote operation
|
* @param customerId the final result of the remote operation
|
||||||
* @param errors the errors to throw before returning {@code customerId}
|
* @param errors the errors to throw before returning {@code customerId}
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public FindCustomer(String customerId, BusinessException... errors) {
|
public FindCustomer(String customerId, BusinessException... errors) {
|
||||||
this.customerId = customerId;
|
this.customerId = customerId;
|
||||||
|
@ -36,7 +36,6 @@ import java.util.function.Predicate;
|
|||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @param <T> the remote op's return type
|
* @param <T> the remote op's return type
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public final class Retry<T> implements BusinessOperation<T> {
|
public final class Retry<T> implements BusinessOperation<T> {
|
||||||
private final BusinessOperation<T> op;
|
private final BusinessOperation<T> op;
|
||||||
@ -54,7 +53,6 @@ public final class Retry<T> implements BusinessOperation<T> {
|
|||||||
* @param delay delay (in milliseconds) between attempts
|
* @param delay delay (in milliseconds) between attempts
|
||||||
* @param ignoreTests tests to check whether the remote exception can be ignored. No exceptions
|
* @param ignoreTests tests to check whether the remote exception can be ignored. No exceptions
|
||||||
* will be ignored if no tests are given
|
* will be ignored if no tests are given
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public Retry(
|
public Retry(
|
||||||
@ -75,7 +73,6 @@ public final class Retry<T> implements BusinessOperation<T> {
|
|||||||
* The errors encountered while retrying, in the encounter order.
|
* The errors encountered while retrying, in the encounter order.
|
||||||
*
|
*
|
||||||
* @return the errors encountered while retrying
|
* @return the errors encountered while retrying
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public List<Exception> errors() {
|
public List<Exception> errors() {
|
||||||
return Collections.unmodifiableList(this.errors);
|
return Collections.unmodifiableList(this.errors);
|
||||||
@ -85,7 +82,6 @@ public final class Retry<T> implements BusinessOperation<T> {
|
|||||||
* The number of retries performed.
|
* The number of retries performed.
|
||||||
*
|
*
|
||||||
* @return the number of retries performed
|
* @return the number of retries performed
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public int attempts() {
|
public int attempts() {
|
||||||
return this.attempts.intValue();
|
return this.attempts.intValue();
|
||||||
|
@ -32,13 +32,10 @@ import org.junit.Test;
|
|||||||
* Unit tests for {@link FindCustomer}.
|
* Unit tests for {@link FindCustomer}.
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public class FindCustomerTest {
|
public class FindCustomerTest {
|
||||||
/**
|
/**
|
||||||
* Returns the given result with no exceptions.
|
* Returns the given result with no exceptions.
|
||||||
*
|
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void noExceptions() throws Exception {
|
public void noExceptions() throws Exception {
|
||||||
@ -52,7 +49,6 @@ public class FindCustomerTest {
|
|||||||
* Throws the given exception.
|
* Throws the given exception.
|
||||||
*
|
*
|
||||||
* @throws Exception the expected exception
|
* @throws Exception the expected exception
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = BusinessException.class)
|
@Test(expected = BusinessException.class)
|
||||||
public void oneException() throws Exception {
|
public void oneException() throws Exception {
|
||||||
@ -63,7 +59,6 @@ public class FindCustomerTest {
|
|||||||
* Should first throw the given exceptions, then return the given result.
|
* Should first throw the given exceptions, then return the given result.
|
||||||
*
|
*
|
||||||
* @throws Exception not an expected exception
|
* @throws Exception not an expected exception
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void resultAfterExceptions() throws Exception {
|
public void resultAfterExceptions() throws Exception {
|
||||||
|
@ -33,13 +33,10 @@ import static org.junit.Assert.*;
|
|||||||
* Unit tests for {@link Retry}.
|
* Unit tests for {@link Retry}.
|
||||||
*
|
*
|
||||||
* @author George Aristy (george.aristy@gmail.com)
|
* @author George Aristy (george.aristy@gmail.com)
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
public class RetryTest {
|
public class RetryTest {
|
||||||
/**
|
/**
|
||||||
* Should contain all errors thrown.
|
* Should contain all errors thrown.
|
||||||
*
|
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void errors() throws Exception {
|
public void errors() throws Exception {
|
||||||
@ -64,8 +61,6 @@ public class RetryTest {
|
|||||||
/**
|
/**
|
||||||
* No exceptions will be ignored, hence final number of attempts should be 1 even if we're asking
|
* No exceptions will be ignored, hence final number of attempts should be 1 even if we're asking
|
||||||
* it to attempt twice.
|
* it to attempt twice.
|
||||||
*
|
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void attempts() {
|
public void attempts() {
|
||||||
@ -90,8 +85,6 @@ public class RetryTest {
|
|||||||
/**
|
/**
|
||||||
* Final number of attempts should be equal to the number of attempts asked because we are
|
* Final number of attempts should be equal to the number of attempts asked because we are
|
||||||
* asking it to ignore the exception that will be thrown.
|
* asking it to ignore the exception that will be thrown.
|
||||||
*
|
|
||||||
* @since 1.18.0
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void ignore() throws Exception {
|
public void ignore() throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user