1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.util.storage;
18
19 import java.util.Iterator;
20 import java.util.Set;
21 import java.util.Timer;
22 import java.util.TimerTask;
23
24
25
26
27 public class ExpiringObjectStorageServiceSweeper extends TimerTask {
28
29
30 private StorageService store;
31
32
33 private Set<String> partitions;
34
35
36
37
38
39
40
41
42 public ExpiringObjectStorageServiceSweeper(Timer taskTimer, long sweepInterval, StorageService sweptStore) {
43 store = sweptStore;
44 taskTimer.schedule(this, sweepInterval);
45 }
46
47
48
49
50
51
52
53
54
55 public ExpiringObjectStorageServiceSweeper(Timer taskTimer, long sweepInterval, StorageService sweptStore,
56 Set<String> sweptParitions) {
57 store = sweptStore;
58 if (sweptParitions != null || sweptParitions.isEmpty()) {
59 partitions = sweptParitions;
60 }
61 taskTimer.schedule(this, sweepInterval);
62 }
63
64
65 public void run() {
66 Iterator<String> sweepPartitions;
67 if (partitions != null) {
68 sweepPartitions = partitions.iterator();
69 } else {
70 sweepPartitions = store.getPartitions();
71 }
72
73 String currentParition;
74 Iterator<?> partitionKeys;
75 Object partitionKey;
76 Object partitionValue;
77 while (sweepPartitions.hasNext()) {
78 currentParition = sweepPartitions.next();
79 partitionKeys = store.getKeys(currentParition);
80 if (partitionKeys == null) {
81 continue;
82 }
83
84 while (partitionKeys.hasNext()) {
85 partitionKey = partitionKeys.next();
86 partitionValue = store.get(currentParition, partitionKey);
87 if (partitionValue instanceof ExpiringObject) {
88 if (((ExpiringObject) partitionValue).isExpired()) {
89 partitionKeys.remove();
90 }
91 }
92 }
93 }
94 }
95 }