1 |
| package org.jboss.cache.pojo.test.propagation.impl; |
2 |
| |
3 |
| import org.jboss.cache.pojo.test.propagation.Node; |
4 |
| import org.jboss.cache.pojo.test.propagation.PropagationRule; |
5 |
| import org.jboss.cache.pojo.test.propagation.StateItem; |
6 |
| |
7 |
| public abstract class AbstractPropagtionRule implements PropagationRule |
8 |
| { |
9 |
6
| public void changeState(Node node, long itemId, long state)
|
10 |
| { |
11 |
6
| StateItem target = node.findStateItem(itemId);
|
12 |
6
| if (target == null)
|
13 |
| { |
14 |
0
| System.out.println("[Error] StateItem not found. : " + node + ":"
|
15 |
| + itemId); |
16 |
0
| return;
|
17 |
| } |
18 |
| |
19 |
6
| if (StateItem.STATE_CHANGED == target.setState(state))
|
20 |
| { |
21 |
6
| summaryUpperPropagate(node);
|
22 |
| } |
23 |
| } |
24 |
| |
25 |
20
| protected void upperPropagate(Node node)
|
26 |
| { |
27 |
20
| Node parentNode = (Node) node.getParentNode();
|
28 |
20
| if (parentNode != null)
|
29 |
| { |
30 |
16
| PropagationRule parentRule = parentNode.getPropagationRule();
|
31 |
16
| parentRule.summaryUpperPropagate(parentNode);
|
32 |
| } |
33 |
| } |
34 |
| |
35 |
92
| protected boolean isClear(StateItem item)
|
36 |
| { |
37 |
92
| long state = item.getState();
|
38 |
92
| if ((state % 10) == 0)
|
39 |
| { |
40 |
58
| return true;
|
41 |
| } else |
42 |
| { |
43 |
34
| return false;
|
44 |
| } |
45 |
| } |
46 |
| |
47 |
34
| protected long getSeverity(StateItem item)
|
48 |
| { |
49 |
34
| long state = item.getState();
|
50 |
34
| long severity = 0;
|
51 |
34
| if (isSummaryItem(item))
|
52 |
| { |
53 |
20
| severity = state % 1000;
|
54 |
| } else |
55 |
| { |
56 |
14
| severity = (state % 1000) / 10;
|
57 |
| } |
58 |
| |
59 |
34
| return severity;
|
60 |
| } |
61 |
| |
62 |
34
| protected boolean isSummaryItem(StateItem item)
|
63 |
| { |
64 |
34
| long state = item.getState();
|
65 |
34
| long summaryDigit = (state / 1000) % 10;
|
66 |
| |
67 |
34
| if (summaryDigit == 2)
|
68 |
| { |
69 |
20
| return true;
|
70 |
| } else |
71 |
| { |
72 |
14
| return false;
|
73 |
| } |
74 |
| } |
75 |
| |
76 |
92
| protected long updateMaxSeverity(long maxSeverity, StateItem stateItem)
|
77 |
| { |
78 |
92
| if (!isClear(stateItem))
|
79 |
| { |
80 |
34
| long severity = getSeverity(stateItem);
|
81 |
34
| if (severity > maxSeverity)
|
82 |
| { |
83 |
24
| maxSeverity = severity;
|
84 |
| } |
85 |
| } |
86 |
| |
87 |
92
| return maxSeverity;
|
88 |
| } |
89 |
| } |