1 17 package org.apache.servicemix.store.memory; 18 19 import java.io.IOException ; 20 import java.util.Map ; 21 22 import org.apache.servicemix.id.IdGenerator; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.servicemix.store.Store; 26 27 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; 28 29 35 public class MemoryStore implements Store { 36 37 private static final Log log = LogFactory.getLog(MemoryStore.class); 38 39 private Map datas = new ConcurrentHashMap(); 40 private IdGenerator idGenerator; 41 42 public MemoryStore(IdGenerator idGenerator) { 43 this.idGenerator = idGenerator; 44 } 45 46 public boolean hasFeature(String name) { 47 return false; 48 } 49 50 public void store(String id, Object data) throws IOException { 51 log.debug("Storing object with id: " + id); 52 datas.put(id, data); 53 } 54 55 public String store(Object data) throws IOException { 56 String id = idGenerator.generateId(); 57 store(id, data); 58 return id; 59 } 60 61 public Object load(String id) throws IOException { 62 log.debug("Loading object with id: " + id); 63 return datas.remove(id); 64 } 65 66 } 67 | Popular Tags |