1 package org.apache.commons.jcs3.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.jcs3.engine.behavior.ICacheElement;
27 import org.apache.commons.jcs3.engine.behavior.ICompositeCacheManager;
28 import org.apache.commons.jcs3.engine.control.CompositeCache;
29 import org.apache.commons.jcs3.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( final ICompositeCacheManager cacheManager,
55 final RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes,
56 final 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( final String cacheName, final K key, final long requesterId )
76 throws IOException
77 {
78 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
79
80 final boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
81 if ( keepLocal )
82 {
83 return cache.localGet( key );
84 }
85 return cache.get( key );
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100 @Override
101 public Map<K, ICacheElement<K, V>> processGetMultiple( final String cacheName, final Set<K> keys, final long requesterId )
102 throws IOException
103 {
104 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
105
106 final boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
107 if ( keepLocal )
108 {
109 return cache.localGetMultiple( keys );
110 }
111 return cache.getMultiple( keys );
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126 @Override
127 public Map<K, ICacheElement<K, V>> processGetMatching( final String cacheName, final String pattern, final long requesterId )
128 throws IOException
129 {
130 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
131
132 final boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
133 if ( keepLocal )
134 {
135 return cache.localGetMatching( pattern );
136 }
137 return cache.getMatching( pattern );
138 }
139
140
141
142
143
144
145
146
147
148
149
150 @Override
151 public void processUpdate( final ICacheElement<K, V> item, final long requesterId )
152 throws IOException
153 {
154 final CompositeCache<K, V> cache = getCacheManager().getCache( item.getCacheName() );
155
156 final boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
157 if ( keepLocal )
158 {
159 cache.localUpdate( item );
160 }
161 else
162 {
163 cache.update( item );
164 }
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178 @Override
179 public void processRemove( final String cacheName, final K key, final long requesterId )
180 throws IOException
181 {
182 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
183
184 final boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
185 if ( keepLocal )
186 {
187 cache.localRemove( key );
188 }
189 else
190 {
191 cache.remove( key );
192 }
193 }
194
195
196
197
198
199
200
201
202
203
204
205 @Override
206 public void processRemoveAll( final String cacheName, final long requesterId )
207 throws IOException
208 {
209 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
210
211 final boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
212 if ( keepLocal )
213 {
214 cache.localRemoveAll();
215 }
216 else
217 {
218 cache.removeAll();
219 }
220 }
221
222
223
224
225
226
227
228
229 @Override
230 public void processDispose( final String cacheName, final long requesterId )
231 throws IOException
232 {
233 final CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
234 cache.dispose();
235 }
236
237
238
239
240
241
242 @Override
243 public void release()
244 throws IOException
245 {
246
247 }
248
249
250
251
252
253
254
255 @Override
256 protected String getExtraInfoForRequesterId( final long requesterId )
257 {
258 return requesterId + "";
259 }
260 }