1 package org.apache.commons.jcs.auxiliary.remote.http.server;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.apache.commons.jcs.engine.behavior.ICacheElement;
27 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
28 import org.apache.commons.jcs.engine.control.CompositeCache;
29 import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
30
31
32
33
34
35
36
37
38 public class RemoteHttpCacheService<K, V>
39 extends AbstractRemoteCacheService<K, V>
40 {
41
42 private static final String EVENT_LOG_SOURCE_NAME = "RemoteHttpCacheServer";
43
44
45 private final RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes;
46
47
48
49
50
51
52
53
54 public RemoteHttpCacheService( ICompositeCacheManager cacheManager,
55 RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes,
56 ICacheEventLogger cacheEventLogger )
57 {
58 super( cacheManager, cacheEventLogger );
59 setEventLogSourceName( EVENT_LOG_SOURCE_NAME );
60 this.remoteHttpCacheServerAttributes = remoteHttpCacheServerAttributes;
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74 @Override
75 public ICacheElement<K, V> processGet( String cacheName, K key, long requesterId )
76 throws IOException
77 {
78 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
79
80 boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
81 if ( keepLocal )
82 {
83 return cache.localGet( key );
84 }
85 else
86 {
87 return cache.get( key );
88 }
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103 @Override
104 public Map<K, ICacheElement<K, V>> processGetMultiple( String cacheName, Set<K> keys, long requesterId )
105 throws IOException
106 {
107 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
108
109 boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
110 if ( keepLocal )
111 {
112 return cache.localGetMultiple( keys );
113 }
114 else
115 {
116 return cache.getMultiple( keys );
117 }
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131
132 @Override
133 public Map<K, ICacheElement<K, V>> processGetMatching( String cacheName, String pattern, long requesterId )
134 throws IOException
135 {
136 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
137
138 boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
139 if ( keepLocal )
140 {
141 return cache.localGetMatching( pattern );
142 }
143 else
144 {
145 return cache.getMatching( pattern );
146 }
147 }
148
149
150
151
152
153
154
155
156
157
158
159 @Override
160 public void processUpdate( ICacheElement<K, V> item, long requesterId )
161 throws IOException
162 {
163 CompositeCache<K, V> cache = getCacheManager().getCache( item.getCacheName() );
164
165 boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
166 if ( keepLocal )
167 {
168 cache.localUpdate( item );
169 }
170 else
171 {
172 cache.update( item );
173 }
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 @Override
188 public void processRemove( String cacheName, K key, long requesterId )
189 throws IOException
190 {
191 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
192
193 boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
194 if ( keepLocal )
195 {
196 cache.localRemove( key );
197 }
198 else
199 {
200 cache.remove( key );
201 }
202 }
203
204
205
206
207
208
209
210
211
212
213
214 @Override
215 public void processRemoveAll( String cacheName, long requesterId )
216 throws IOException
217 {
218 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
219
220 boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
221 if ( keepLocal )
222 {
223 cache.localRemoveAll();
224 }
225 else
226 {
227 cache.removeAll();
228 }
229 }
230
231
232
233
234
235
236
237
238 @Override
239 public void processDispose( String cacheName, long requesterId )
240 throws IOException
241 {
242 CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
243 cache.dispose();
244 }
245
246
247
248
249
250
251 @Override
252 public void release()
253 throws IOException
254 {
255
256 }
257
258
259
260
261
262
263
264 @Override
265 protected String getExtraInfoForRequesterId( long requesterId )
266 {
267 return requesterId + "";
268 }
269 }