1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.eviction; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.cache.Fqn; |
12 |
| import org.jboss.cache.Region; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| public abstract class BaseSortedEvictionAlgorithm extends BaseEvictionAlgorithm implements EvictionAlgorithm |
27 |
| { |
28 |
| private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class); |
29 |
| |
30 |
73
| public void process(Region region) throws EvictionException
|
31 |
| { |
32 |
73
| super.process(region);
|
33 |
| } |
34 |
| |
35 |
73
| protected void processQueues(Region region) throws EvictionException
|
36 |
| { |
37 |
73
| boolean evictionNodesModified = false;
|
38 |
| |
39 |
73
| EvictedEventNode node;
|
40 |
73
| int count = 0;
|
41 |
?
| while ((node = region.takeLastEventNode()) != null)
|
42 |
| { |
43 |
61274
| Fqn fqn = node.getFqn();
|
44 |
| |
45 |
61274
| count++;
|
46 |
61274
| switch (node.getEventType())
|
47 |
| { |
48 |
10055
| case ADD_NODE_EVENT:
|
49 |
10055
| this.processAddedNodes(fqn, node.getElementDifference(), node.isResetElementCount());
|
50 |
10055
| evictionNodesModified = true;
|
51 |
10055
| break;
|
52 |
2005
| case REMOVE_NODE_EVENT:
|
53 |
2005
| this.processRemovedNodes(fqn);
|
54 |
2005
| break;
|
55 |
13150
| case VISIT_NODE_EVENT:
|
56 |
13150
| this.processVisitedNodes(fqn);
|
57 |
13150
| evictionNodesModified = true;
|
58 |
13150
| break;
|
59 |
36064
| case ADD_ELEMENT_EVENT:
|
60 |
36064
| this.processAddedElement(fqn);
|
61 |
36064
| evictionNodesModified = true;
|
62 |
36064
| break;
|
63 |
0
| case REMOVE_ELEMENT_EVENT:
|
64 |
0
| this.processRemovedElement(fqn);
|
65 |
0
| evictionNodesModified = true;
|
66 |
0
| break;
|
67 |
0
| default:
|
68 |
0
| throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
|
69 |
| } |
70 |
| } |
71 |
| |
72 |
73
| if (log.isTraceEnabled())
|
73 |
| { |
74 |
0
| log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified);
|
75 |
| } |
76 |
| |
77 |
73
| this.resortEvictionQueue(evictionNodesModified);
|
78 |
| |
79 |
| |
80 |
73
| if (log.isTraceEnabled())
|
81 |
| { |
82 |
0
| log.trace("processed " + count + " node events");
|
83 |
| } |
84 |
| |
85 |
| } |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
73
| protected void resortEvictionQueue(boolean evictionQueueModified)
|
96 |
| { |
97 |
73
| if (!evictionQueueModified)
|
98 |
| { |
99 |
42
| if (log.isDebugEnabled())
|
100 |
| { |
101 |
0
| log.debug("Eviction queue not modified. Resort unnecessary.");
|
102 |
| } |
103 |
42
| return;
|
104 |
| } |
105 |
31
| long begin = System.currentTimeMillis();
|
106 |
31
| ((SortedEvictionQueue) evictionQueue).resortEvictionQueue();
|
107 |
31
| long end = System.currentTimeMillis();
|
108 |
| |
109 |
31
| if (log.isTraceEnabled())
|
110 |
| { |
111 |
0
| long diff = end - begin;
|
112 |
0
| log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements");
|
113 |
| } |
114 |
| } |
115 |
| |
116 |
| } |