|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.base; |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| public class EntryUpdateState { |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| public static final int NOT_YET_UPDATING = -1; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public static final int UPDATE_IN_PROGRESS = 0; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public static final int UPDATE_COMPLETE = 1; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| public static final int UPDATE_CANCELLED = 2; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| int state = NOT_YET_UPDATING; |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| private int nbConcurrentUses = 1; |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
2012163
| public boolean isAwaitingUpdate() {
|
|
56 |
2012163
| return state == NOT_YET_UPDATING;
|
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
2034206
| public boolean isCancelled() {
|
|
66 |
2034206
| return state == UPDATE_CANCELLED;
|
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
17
| public boolean isComplete() {
|
|
73 |
17
| return state == UPDATE_COMPLETE;
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
1618751
| public boolean isUpdating() {
|
|
81 |
1618751
| return state == UPDATE_IN_PROGRESS;
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
2008121
| public int cancelUpdate() {
|
|
90 |
2008121
| if (state != UPDATE_IN_PROGRESS) {
|
|
91 |
0
| throw new IllegalStateException("Cannot cancel cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
|
|
92 |
| } |
|
93 |
| |
|
94 |
2008121
| state = UPDATE_CANCELLED;
|
|
95 |
2008121
| return decrementUsageCounter();
|
|
96 |
| } |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
4021
| public int completeUpdate() {
|
|
104 |
4021
| if (state != UPDATE_IN_PROGRESS) {
|
|
105 |
0
| throw new IllegalStateException("Cannot complete cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
|
|
106 |
| } |
|
107 |
| |
|
108 |
4021
| state = UPDATE_COMPLETE;
|
|
109 |
4021
| return decrementUsageCounter();
|
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
2012142
| public int startUpdate() {
|
|
118 |
2012142
| if ((state != NOT_YET_UPDATING) && (state != UPDATE_CANCELLED)) {
|
|
119 |
0
| throw new IllegalStateException("Cannot begin cache update - current state (" + state + ") is not NOT_YET_UPDATING or UPDATE_CANCELLED");
|
|
120 |
| } |
|
121 |
| |
|
122 |
2012142
| state = UPDATE_IN_PROGRESS;
|
|
123 |
2012142
| return incrementUsageCounter();
|
|
124 |
| } |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
4008852
| public synchronized int incrementUsageCounter() {
|
|
131 |
4008852
| nbConcurrentUses++;
|
|
132 |
4008852
| return nbConcurrentUses;
|
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
0
| public synchronized int getUsageCounter() {
|
|
140 |
0
| return nbConcurrentUses;
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
4024305
| public synchronized int decrementUsageCounter() {
|
|
149 |
4024305
| if (nbConcurrentUses <=0) {
|
|
150 |
0
| throw new IllegalStateException("Cannot decrement usage counter, it is already equals to [" + nbConcurrentUses + "]");
|
|
151 |
| } |
|
152 |
4024305
| nbConcurrentUses--;
|
|
153 |
4024305
| return nbConcurrentUses;
|
|
154 |
| } |
|
155 |
| |
|
156 |
| |
|
157 |
| } |