1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.queue; |
12 | |
|
13 | |
import org.mule.util.UUID; |
14 | |
|
15 | |
import java.io.IOException; |
16 | |
import java.util.ArrayList; |
17 | |
import java.util.Collections; |
18 | |
import java.util.HashMap; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
|
23 | 0 | public class MemoryPersistenceStrategy implements QueuePersistenceStrategy |
24 | |
{ |
25 | 0 | private Map map = Collections.synchronizedMap(new HashMap()); |
26 | |
|
27 | |
protected Object getId(Object obj) |
28 | |
{ |
29 | 0 | return UUID.getUUID(); |
30 | |
} |
31 | |
|
32 | |
public Object store(String queue, Object obj) throws IOException |
33 | |
{ |
34 | 0 | if (obj == null) |
35 | |
{ |
36 | 0 | throw new IllegalArgumentException("Cannot store null object."); |
37 | |
} |
38 | 0 | Object id = getId(obj); |
39 | 0 | map.put(id, obj); |
40 | 0 | return id; |
41 | |
} |
42 | |
|
43 | |
public Object load(String queue, Object id) throws IOException |
44 | |
{ |
45 | 0 | return map.get(id); |
46 | |
} |
47 | |
|
48 | |
public void remove(String queue, Object id) throws IOException |
49 | |
{ |
50 | 0 | map.remove(id); |
51 | 0 | } |
52 | |
|
53 | |
public List restore() throws IOException |
54 | |
{ |
55 | 0 | return new ArrayList(); |
56 | |
} |
57 | |
|
58 | |
public void open() throws IOException |
59 | |
{ |
60 | |
|
61 | 0 | } |
62 | |
|
63 | |
public void close() throws IOException |
64 | |
{ |
65 | |
|
66 | 0 | } |
67 | |
|
68 | |
public boolean isTransient() |
69 | |
{ |
70 | 0 | return true; |
71 | |
} |
72 | |
} |