|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.extra; |
|
6 |
| |
|
7 |
| import com.opensymphony.oscache.base.events.ScopeEvent; |
|
8 |
| import com.opensymphony.oscache.base.events.ScopeEventListener; |
|
9 |
| import com.opensymphony.oscache.base.events.ScopeEventType; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| public class ScopeEventListenerImpl implements ScopeEventListener { |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| public static final String[] SCOPE_NAMES = { |
|
25 |
| null, "page", "request", "session", "application" |
|
26 |
| }; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public static final int NB_SCOPES = SCOPE_NAMES.length - 1; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| public static final int PAGE_SCOPE = 1; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| public static final int REQUEST_SCOPE = 2; |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| public static final int SESSION_SCOPE = 3; |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public static final int APPLICATION_SCOPE = 4; |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| private int[] scopeFlushCount = new int[NB_SCOPES + 1]; |
|
59 |
| |
|
60 |
5
| public ScopeEventListenerImpl() {
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
5
| public int getApplicationScopeFlushCount() {
|
|
69 |
5
| return scopeFlushCount[APPLICATION_SCOPE];
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
5
| public int getPageScopeFlushCount() {
|
|
77 |
5
| return scopeFlushCount[PAGE_SCOPE];
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
5
| public int getRequestScopeFlushCount() {
|
|
85 |
5
| return scopeFlushCount[REQUEST_SCOPE];
|
|
86 |
| } |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
5
| public int getSessionScopeFlushCount() {
|
|
93 |
5
| return scopeFlushCount[SESSION_SCOPE];
|
|
94 |
| } |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
5
| public int getTotalScopeFlushCount() {
|
|
101 |
5
| int total = 0;
|
|
102 |
| |
|
103 |
5
| for (int count = 1; count <= NB_SCOPES; count++) {
|
|
104 |
20
| total += scopeFlushCount[count];
|
|
105 |
| } |
|
106 |
| |
|
107 |
5
| return total;
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
10
| public void scopeFlushed(ScopeEvent event) {
|
|
115 |
| |
|
116 |
10
| ScopeEventType eventType = event.getEventType();
|
|
117 |
| |
|
118 |
10
| if (eventType == ScopeEventType.ALL_SCOPES_FLUSHED) {
|
|
119 |
| |
|
120 |
5
| for (int count = 1; count <= NB_SCOPES; count++) {
|
|
121 |
20
| scopeFlushCount[count]++;
|
|
122 |
| } |
|
123 |
5
| } else if (eventType == ScopeEventType.SCOPE_FLUSHED) {
|
|
124 |
| |
|
125 |
5
| scopeFlushCount[event.getScope()]++;
|
|
126 |
| } else { |
|
127 |
| |
|
128 |
0
| throw new IllegalArgumentException("Unknown Scope Event type received");
|
|
129 |
| } |
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
0
| public String toString() {
|
|
136 |
0
| StringBuffer returnString = new StringBuffer("Flush count for ");
|
|
137 |
| |
|
138 |
0
| for (int count = 1; count <= NB_SCOPES; count++) {
|
|
139 |
0
| returnString.append("scope " + SCOPE_NAMES[count] + " = " + scopeFlushCount[count] + ", ");
|
|
140 |
| } |
|
141 |
| |
|
142 |
| |
|
143 |
0
| returnString.setLength(returnString.length() - 2);
|
|
144 |
| |
|
145 |
0
| return returnString.toString();
|
|
146 |
| } |
|
147 |
| } |