Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~ricin/play/ricin |
Merge into: | lp:play |
Diff against target: |
312 lines (+147/-95) 1 file modified
framework/src/play/cache/MemcachedImpl.java (+147/-95) |
To merge this branch: | bzr merge lp:~ricin/play/ricin |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guillaume Bort | Needs Information | ||
Review via email: mp+14530@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
ricin (ricin) wrote : | # |
Revision history for this message
Guillaume Bort (guillaume-bort) wrote : | # |
Fine, thank you.
Are you sure that we can safely remove spy-2.4.jar ? It is not needed anymore ?
review:
Needs Information
Revision history for this message
ricin (ricin) wrote : | # |
Correct. It's no longer needed.
-------
From dsallings:
spy.jar should no longer be necessary, but it's all in my github account: http://
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'framework/lib/memcached-2.1.jar' |
2 | Binary files framework/lib/memcached-2.1.jar 2009-10-15 14:21:12 +0000 and framework/lib/memcached-2.1.jar 1970-01-01 00:00:00 +0000 differ |
3 | === added file 'framework/lib/memcached-2.4.2.jar' |
4 | Binary files framework/lib/memcached-2.4.2.jar 1970-01-01 00:00:00 +0000 and framework/lib/memcached-2.4.2.jar 2009-11-06 06:45:21 +0000 differ |
5 | === removed file 'framework/lib/spy-2.4.jar' |
6 | Binary files framework/lib/spy-2.4.jar 2008-06-23 19:00:19 +0000 and framework/lib/spy-2.4.jar 1970-01-01 00:00:00 +0000 differ |
7 | === modified file 'framework/src/play/cache/MemcachedImpl.java' |
8 | --- framework/src/play/cache/MemcachedImpl.java 2009-08-12 19:00:35 +0000 |
9 | +++ framework/src/play/cache/MemcachedImpl.java 2009-11-06 06:45:21 +0000 |
10 | @@ -21,155 +21,207 @@ |
11 | /** |
12 | * Memcached implementation (using http://code.google.com/p/spymemcached/) |
13 | */ |
14 | -public class MemcachedImpl implements CacheImpl { |
15 | +public class MemcachedImpl implements CacheImpl |
16 | +{ |
17 | |
18 | private static MemcachedImpl uniqueInstance; |
19 | |
20 | - public static MemcachedImpl getInstance() throws IOException { |
21 | - if (uniqueInstance == null) { |
22 | + public static MemcachedImpl getInstance() throws IOException |
23 | + { |
24 | + if (uniqueInstance == null) |
25 | + { |
26 | uniqueInstance = new MemcachedImpl(); |
27 | } |
28 | return uniqueInstance; |
29 | } |
30 | - |
31 | + |
32 | MemcachedClient client; |
33 | - |
34 | - private MemcachedImpl() throws IOException { |
35 | - System.setProperty("net.spy.log.LoggerImpl", "net.spy.log.Log4JLogger"); |
36 | - if (Play.configuration.containsKey("memcached.host")) { |
37 | + SerializingTranscoder tc; |
38 | + |
39 | + private MemcachedImpl() throws IOException |
40 | + { |
41 | + tc = new SerializingTranscoder() { |
42 | + @Override |
43 | + protected Object deserialize(byte[] data) |
44 | + { |
45 | + try |
46 | + { |
47 | + return new ObjectInputStream(new ByteArrayInputStream(data)) { |
48 | + @Override |
49 | + protected Class<?> resolveClass(ObjectStreamClass desc) |
50 | + throws IOException, ClassNotFoundException |
51 | + { |
52 | + return Play.classloader.loadClass(desc.getName()); |
53 | + } |
54 | + }.readObject(); |
55 | + } |
56 | + catch (Exception e) |
57 | + { |
58 | + Logger.error(e, "Could not deserialize"); |
59 | + } |
60 | + return null; |
61 | + } |
62 | + |
63 | + @Override |
64 | + protected byte[] serialize(Object object) |
65 | + { |
66 | + try |
67 | + { |
68 | + ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
69 | + new ObjectOutputStream(bos).writeObject(object); |
70 | + return bos.toByteArray(); |
71 | + } |
72 | + catch (IOException e) |
73 | + { |
74 | + Logger.error(e, "Could not serialize"); |
75 | + } |
76 | + return null; |
77 | + } |
78 | + }; |
79 | + |
80 | + System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger"); |
81 | + if (Play.configuration.containsKey("memcached.host")) |
82 | + { |
83 | client = new MemcachedClient(AddrUtil.getAddresses(Play.configuration.getProperty("memcached.host"))); |
84 | - client.setTranscoder(new SerializingTranscoder() { |
85 | - |
86 | - @Override |
87 | - protected Object deserialize(byte[] data) { |
88 | - try { |
89 | - return new ObjectInputStream(new ByteArrayInputStream(data)) { |
90 | - |
91 | - @Override |
92 | - protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { |
93 | - return Play.classloader.loadClass(desc.getName()); |
94 | - } |
95 | - }.readObject(); |
96 | - } catch (Exception e) { |
97 | - Logger.error(e, "Could not deserialize"); |
98 | - } |
99 | - return null; |
100 | - } |
101 | - |
102 | - @Override |
103 | - protected byte[] serialize(Object object) { |
104 | - try { |
105 | - ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
106 | - new ObjectOutputStream(bos).writeObject(object); |
107 | - return bos.toByteArray(); |
108 | - } catch (IOException e) { |
109 | - Logger.error(e, "Could not serialize"); |
110 | - } |
111 | - return null; |
112 | - } |
113 | - }); |
114 | - } else if (Play.configuration.containsKey("memcached.1.host")) { |
115 | + } |
116 | + else if (Play.configuration.containsKey("memcached.1.host")) |
117 | + { |
118 | int nb = 1; |
119 | String addresses = ""; |
120 | - while (Play.configuration.containsKey("memcached." + nb + ".host")) { |
121 | + while (Play.configuration.containsKey("memcached." + nb + ".host")) |
122 | + { |
123 | addresses += Play.configuration.get("memcached." + nb + ".host") + " "; |
124 | nb++; |
125 | } |
126 | client = new MemcachedClient(AddrUtil.getAddresses(addresses)); |
127 | - } else { |
128 | + } |
129 | + else |
130 | + { |
131 | throw new ConfigurationException(("Bad configuration for memcached")); |
132 | } |
133 | } |
134 | |
135 | - public void add(String key, Object value, int expiration) { |
136 | - client.add(key, expiration, value); |
137 | + public void add(String key, Object value, int expiration) |
138 | + { |
139 | + client.add(key, expiration, value, tc); |
140 | } |
141 | |
142 | - public Object get(String key) { |
143 | - Future<Object> future = client.asyncGet(key); |
144 | - try { |
145 | + public Object get(String key) |
146 | + { |
147 | + Future<Object> future = client.asyncGet(key, tc); |
148 | + try |
149 | + { |
150 | return future.get(1, TimeUnit.SECONDS); |
151 | - } catch (Exception e) { |
152 | + } |
153 | + catch (Exception e) |
154 | + { |
155 | future.cancel(false); |
156 | } |
157 | return null; |
158 | } |
159 | |
160 | - public void clear() { |
161 | + public void clear() |
162 | + { |
163 | client.flush(); |
164 | } |
165 | |
166 | - public void delete(String key) { |
167 | + public void delete(String key) |
168 | + { |
169 | client.delete(key); |
170 | } |
171 | |
172 | - public Map<String, Object> get(String[] keys) { |
173 | - Future<Map<String, Object>> future = client.asyncGetBulk(keys); |
174 | - try { |
175 | + public Map<String, Object> get(String[] keys) |
176 | + { |
177 | + Future<Map<String, Object>> future = client.asyncGetBulk(tc, keys); |
178 | + try |
179 | + { |
180 | return future.get(1, TimeUnit.SECONDS); |
181 | - } catch (Exception e) { |
182 | + } |
183 | + catch (Exception e) |
184 | + { |
185 | future.cancel(false); |
186 | } |
187 | return new HashMap<String, Object>(); |
188 | } |
189 | |
190 | - public long incr(String key, int by) { |
191 | + public long incr(String key, int by) |
192 | + { |
193 | return client.incr(key, by); |
194 | } |
195 | |
196 | - public long decr(String key, int by) { |
197 | + public long decr(String key, int by) |
198 | + { |
199 | return client.decr(key, by); |
200 | } |
201 | |
202 | - public void replace(String key, Object value, int expiration) { |
203 | - client.replace(key, expiration, value); |
204 | + public void replace(String key, Object value, int expiration) |
205 | + { |
206 | + client.replace(key, expiration, value, tc); |
207 | } |
208 | |
209 | - public boolean safeAdd(String key, Object value, int expiration) { |
210 | - Future<Boolean> future = client.add(key, expiration, value); |
211 | - try { |
212 | + public boolean safeAdd(String key, Object value, int expiration) |
213 | + { |
214 | + Future<Boolean> future = client.add(key, expiration, value, tc); |
215 | + try |
216 | + { |
217 | return future.get(1, TimeUnit.SECONDS); |
218 | - } catch (Exception e) { |
219 | + } |
220 | + catch (Exception e) |
221 | + { |
222 | future.cancel(false); |
223 | } |
224 | return false; |
225 | } |
226 | |
227 | - public boolean safeDelete(String key) { |
228 | + public boolean safeDelete(String key) |
229 | + { |
230 | Future<Boolean> future = client.delete(key); |
231 | - try { |
232 | - return future.get(1, TimeUnit.SECONDS); |
233 | - } catch (Exception e) { |
234 | - future.cancel(false); |
235 | - } |
236 | - return false; |
237 | - } |
238 | - |
239 | - public boolean safeReplace(String key, Object value, int expiration) { |
240 | - Future<Boolean> future = client.replace(key, expiration, value); |
241 | - try { |
242 | - return future.get(1, TimeUnit.SECONDS); |
243 | - } catch (Exception e) { |
244 | - future.cancel(false); |
245 | - } |
246 | - return false; |
247 | - } |
248 | - |
249 | - public boolean safeSet(String key, Object value, int expiration) { |
250 | - Future<Boolean> future = client.set(key, expiration, value); |
251 | - try { |
252 | - return future.get(1, TimeUnit.SECONDS); |
253 | - } catch (Exception e) { |
254 | - future.cancel(false); |
255 | - } |
256 | - return false; |
257 | - } |
258 | - |
259 | - public void set(String key, Object value, int expiration) { |
260 | - client.set(key, expiration, value); |
261 | - } |
262 | - |
263 | - public void stop() { |
264 | + try |
265 | + { |
266 | + return future.get(1, TimeUnit.SECONDS); |
267 | + } |
268 | + catch (Exception e) |
269 | + { |
270 | + future.cancel(false); |
271 | + } |
272 | + return false; |
273 | + } |
274 | + |
275 | + public boolean safeReplace(String key, Object value, int expiration) |
276 | + { |
277 | + Future<Boolean> future = client.replace(key, expiration, value, tc); |
278 | + try |
279 | + { |
280 | + return future.get(1, TimeUnit.SECONDS); |
281 | + } |
282 | + catch (Exception e) |
283 | + { |
284 | + future.cancel(false); |
285 | + } |
286 | + return false; |
287 | + } |
288 | + |
289 | + public boolean safeSet(String key, Object value, int expiration) |
290 | + { |
291 | + Future<Boolean> future = client.set(key, expiration, value, tc); |
292 | + try |
293 | + { |
294 | + return future.get(1, TimeUnit.SECONDS); |
295 | + } |
296 | + catch (Exception e) |
297 | + { |
298 | + future.cancel(false); |
299 | + } |
300 | + return false; |
301 | + } |
302 | + |
303 | + public void set(String key, Object value, int expiration) |
304 | + { |
305 | + client.set(key, expiration, value, tc); |
306 | + } |
307 | + |
308 | + public void stop() |
309 | + { |
310 | client.shutdown(); |
311 | } |
312 | } |
Updated to spymemcached 2.4.2.
This update fixed all of my issues with memcached running against memcached 1.2.2, 1.3.3, and 1.4.1 hosts.