1 10 11 package org.mule.util.queue; 12 13 import org.safehaus.uuid.UUIDGenerator; 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 26 public class MemoryPersistenceStrategy implements QueuePersistenceStrategy 27 { 28 29 private UUIDGenerator gen = UUIDGenerator.getInstance(); 30 31 private Map map = Collections.synchronizedMap(new HashMap ()); 32 33 protected Object getId(Object obj) 34 { 35 return gen.generateRandomBasedUUID(); 36 } 37 38 43 public Object store(String queue, Object obj) throws IOException 44 { 45 if (obj == null) 46 { 47 throw new IllegalArgumentException ("Cannot store null object."); 48 } 49 Object id = getId(obj); 50 map.put(id, obj); 51 return id; 52 } 53 54 59 public Object load(String queue, Object id) throws IOException 60 { 61 return map.get(id); 62 } 63 64 69 public void remove(String queue, Object id) throws IOException 70 { 71 map.remove(id); 72 } 73 74 79 public List restore() throws IOException 80 { 81 return new ArrayList (); 82 } 83 84 89 public void open() throws IOException 90 { 91 } 93 94 99 public void close() throws IOException 100 { 101 } 103 104 public boolean isTransient() 105 { 106 return true; 107 } 108 } 109 | Popular Tags |