1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package net.admin4j.exception; |
15 | |
|
16 | |
import java.util.Date; |
17 | |
import java.util.Set; |
18 | |
import java.util.concurrent.atomic.AtomicInteger; |
19 | |
|
20 | |
import net.admin4j.config.Admin4JConfiguration; |
21 | |
import net.admin4j.dao.DAOFactory; |
22 | |
import net.admin4j.deps.commons.lang3.Validate; |
23 | |
import net.admin4j.deps.commons.lang3.time.DateUtils; |
24 | |
import net.admin4j.entity.ExceptionInfo; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 15 | class ExceptionTrackerCleanupTask implements Runnable { |
32 | |
|
33 | |
static final int DEFAULT_PURGE_THRESHOLD_IN_DAYS = 30; |
34 | 15 | private AtomicInteger purgeThresholdInDays = new AtomicInteger(DEFAULT_PURGE_THRESHOLD_IN_DAYS); |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public void run() { |
40 | |
|
41 | |
Date purgeDt = DateUtils.addDays(new Date(), -1 * purgeThresholdInDays.get()); |
42 | |
|
43 | 3 | Set<ExceptionInfo> exceptionSet = ExceptionTracker.getExceptionInfoSet(); |
44 | 3 | for (ExceptionInfo eInfo: exceptionSet) { |
45 | 6 | if (purgeDt.getTime() > eInfo.getLastOccuranceDt().getTime()) { |
46 | 0 | ExceptionTracker.purgeException(eInfo); |
47 | |
} |
48 | |
} |
49 | |
|
50 | 3 | if (Admin4JConfiguration.isExceptionInfoStored()) { |
51 | 0 | DAOFactory.getExceptionInfoDAO().saveAll(exceptionSet); |
52 | |
} |
53 | |
|
54 | 3 | } |
55 | |
|
56 | |
public void setPurgeThresholdInDays(Integer days) { |
57 | |
Validate.notNull(days, "Purge threshhold cannot be null"); |
58 | 0 | Validate.isTrue(days > 0, "Purge threshhold must be larger than zero"); |
59 | 3 | purgeThresholdInDays.set(days); |
60 | 3 | } |
61 | |
|
62 | |
} |