Skip to content

Commit 2a92369

Browse files
committed
introducing gradle and Retry
1 parent 8d6be77 commit 2a92369

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apply plugin: 'java'
2+
3+
repositories {
4+
mavenCentral()
5+
}
6+
7+
sourceCompatibility = "1.8"
8+
targetCompatibility = "1.8"
9+
10+
dependencies {
11+
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
12+
testCompile 'org.hamcrest:hamcrest-all:1.3'
13+
testCompile 'org.mockito:mockito-all:1.9.5'
14+
testCompile 'junit:junit:4.12'
15+
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.lambdista.util;
2+
3+
import java.util.function.Consumer;
4+
5+
/**
6+
* Created by armin on 06/08/15.
7+
*/
8+
public class Retry {
9+
10+
static int someCounter = 5;
11+
public static void main(String[] args) {
12+
String x = "trying...";
13+
FailableSupplier<Integer> integerFailableSupplier = () -> {
14+
System.out.println(x + someCounter--);
15+
if (someCounter > 3) {
16+
throw new RuntimeException();
17+
}
18+
return someCounter;
19+
};
20+
System.out.println(retry(5, 0, integerFailableSupplier));
21+
}
22+
23+
private static <T> T retry(int maxRetries, int retryCount, FailableSupplier<T> supplier) {
24+
25+
Try<T> aTry = Try.apply(supplier);
26+
if (aTry.isFailure() && maxRetries > retryCount) {
27+
return retry(maxRetries, retryCount++, supplier);
28+
} else {
29+
return aTry.get();
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)