01: /*
02: * $Id: MemoryPersistenceStrategy.java 8077 2007-08-27 20:15:25Z aperepel $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: public class MemoryPersistenceStrategy implements
23: QueuePersistenceStrategy {
24:
25: private UUIDGenerator gen = UUIDGenerator.getInstance();
26:
27: private Map map = Collections.synchronizedMap(new HashMap());
28:
29: protected Object getId(Object obj) {
30: return gen.generateRandomBasedUUID();
31: }
32:
33: /*
34: * (non-Javadoc)
35: *
36: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#store(java.lang.Object)
37: */
38: public Object store(String queue, Object obj) throws IOException {
39: if (obj == null) {
40: throw new IllegalArgumentException(
41: "Cannot store null object.");
42: }
43: Object id = getId(obj);
44: map.put(id, obj);
45: return id;
46: }
47:
48: /*
49: * (non-Javadoc)
50: *
51: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#load(java.lang.Object)
52: */
53: public Object load(String queue, Object id) throws IOException {
54: return map.get(id);
55: }
56:
57: /*
58: * (non-Javadoc)
59: *
60: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#remove(java.lang.Object)
61: */
62: public void remove(String queue, Object id) throws IOException {
63: map.remove(id);
64: }
65:
66: /*
67: * (non-Javadoc)
68: *
69: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#restore()
70: */
71: public List restore() throws IOException {
72: return new ArrayList();
73: }
74:
75: /*
76: * (non-Javadoc)
77: *
78: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#open()
79: */
80: public void open() throws IOException {
81: // nothing to do
82: }
83:
84: /*
85: * (non-Javadoc)
86: *
87: * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#close()
88: */
89: public void close() throws IOException {
90: // nothing to do
91: }
92:
93: public boolean isTransient() {
94: return true;
95: }
96: }
|