Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MemoryPersistenceStrategy |
|
| 1.25;1.25 |
1 | /* | |
2 | * $Id: MemoryPersistenceStrategy.java 7976 2007-08-21 14:26:13Z dirk.olmes $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.util.queue; | |
12 | ||
13 | import java.io.IOException; | |
14 | import java.util.ArrayList; | |
15 | import java.util.Collections; | |
16 | import java.util.HashMap; | |
17 | import java.util.List; | |
18 | import java.util.Map; | |
19 | ||
20 | import org.safehaus.uuid.UUIDGenerator; | |
21 | ||
22 | /** | |
23 | * @author <a href="mailto:gnt@codehaus.org">Guillaume Nodet</a> | |
24 | * @version $Revision: 7976 $ | |
25 | */ | |
26 | 0 | public class MemoryPersistenceStrategy implements QueuePersistenceStrategy |
27 | { | |
28 | ||
29 | 0 | private UUIDGenerator gen = UUIDGenerator.getInstance(); |
30 | ||
31 | 0 | private Map map = Collections.synchronizedMap(new HashMap()); |
32 | ||
33 | protected Object getId(Object obj) | |
34 | { | |
35 | 0 | return gen.generateRandomBasedUUID(); |
36 | } | |
37 | ||
38 | /* | |
39 | * (non-Javadoc) | |
40 | * | |
41 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#store(java.lang.Object) | |
42 | */ | |
43 | public Object store(String queue, Object obj) throws IOException | |
44 | { | |
45 | 0 | if (obj == null) |
46 | { | |
47 | 0 | throw new IllegalArgumentException("Cannot store null object."); |
48 | } | |
49 | 0 | Object id = getId(obj); |
50 | 0 | map.put(id, obj); |
51 | 0 | return id; |
52 | } | |
53 | ||
54 | /* | |
55 | * (non-Javadoc) | |
56 | * | |
57 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#load(java.lang.Object) | |
58 | */ | |
59 | public Object load(String queue, Object id) throws IOException | |
60 | { | |
61 | 0 | return map.get(id); |
62 | } | |
63 | ||
64 | /* | |
65 | * (non-Javadoc) | |
66 | * | |
67 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#remove(java.lang.Object) | |
68 | */ | |
69 | public void remove(String queue, Object id) throws IOException | |
70 | { | |
71 | 0 | map.remove(id); |
72 | 0 | } |
73 | ||
74 | /* | |
75 | * (non-Javadoc) | |
76 | * | |
77 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#restore() | |
78 | */ | |
79 | public List restore() throws IOException | |
80 | { | |
81 | 0 | return new ArrayList(); |
82 | } | |
83 | ||
84 | /* | |
85 | * (non-Javadoc) | |
86 | * | |
87 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#open() | |
88 | */ | |
89 | public void open() throws IOException | |
90 | { | |
91 | // nothing to do | |
92 | 0 | } |
93 | ||
94 | /* | |
95 | * (non-Javadoc) | |
96 | * | |
97 | * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#close() | |
98 | */ | |
99 | public void close() throws IOException | |
100 | { | |
101 | // nothing to do | |
102 | 0 | } |
103 | ||
104 | public boolean isTransient() | |
105 | { | |
106 | 0 | return true; |
107 | } | |
108 | } |