|
5 | 5 | import org.dataloader.Try; |
6 | 6 | import org.dataloader.fixtures.User; |
7 | 7 | import org.dataloader.fixtures.UserManager; |
| 8 | +import org.dataloader.stats.Statistics; |
| 9 | +import org.dataloader.stats.ThreadLocalStatisticsCollector; |
8 | 10 |
|
9 | 11 | import java.util.ArrayList; |
10 | 12 | import java.util.List; |
11 | 13 | import java.util.concurrent.CompletableFuture; |
12 | 14 | import java.util.concurrent.CompletionStage; |
13 | 15 | import java.util.stream.Collectors; |
14 | 16 |
|
| 17 | +import static java.lang.String.format; |
| 18 | + |
15 | 19 | @SuppressWarnings("ALL") |
16 | 20 | public class ReadmeExamples { |
17 | 21 |
|
@@ -75,7 +79,6 @@ public CompletionStage<List<User>> load(List<Long> userIds) { |
75 | 79 | } |
76 | 80 |
|
77 | 81 |
|
78 | | - |
79 | 82 | private void tryExample() { |
80 | 83 | Try<String> tryS = Try.tryCall(() -> { |
81 | 84 | if (rollDice()) { |
@@ -185,4 +188,19 @@ private boolean rollDice() { |
185 | 188 | } |
186 | 189 |
|
187 | 190 |
|
| 191 | + private void statsExample() { |
| 192 | + Statistics statistics = userDataLoader.getStatistics(); |
| 193 | + |
| 194 | + System.out.println(format("load : %d", statistics.getLoadCount())); |
| 195 | + System.out.println(format("batch load: %d", statistics.getBatchLoadCount())); |
| 196 | + System.out.println(format("cache hit: %d", statistics.getCacheHitCount())); |
| 197 | + System.out.println(format("cache hit ratio: %d", statistics.getCacheHitRatio())); |
| 198 | + } |
| 199 | + |
| 200 | + private void statsConfigExample() { |
| 201 | + |
| 202 | + DataLoaderOptions options = DataLoaderOptions.newOptions().setStatisticsCollector(() -> new ThreadLocalStatisticsCollector()); |
| 203 | + DataLoader<String,User> userDataLoader = DataLoader.newDataLoader(userBatchLoader,options); |
| 204 | + } |
| 205 | + |
188 | 206 | } |
0 commit comments