View Javadoc

1   /*
2    * $Id: MemoryPersistenceStrategy.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 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  public class MemoryPersistenceStrategy implements QueuePersistenceStrategy
24  {
25      private Map map = Collections.synchronizedMap(new HashMap());
26  
27      protected Object getId(Object obj)
28      {
29          return UUID.getUUID();
30      }
31  
32      public Object store(String queue, Object obj) throws IOException
33      {
34          if (obj == null)
35          {
36              throw new IllegalArgumentException("Cannot store null object.");
37          }
38          Object id = getId(obj);
39          map.put(id, obj);
40          return id;
41      }
42  
43      public Object load(String queue, Object id) throws IOException
44      {
45          return map.get(id);
46      }
47  
48      public void remove(String queue, Object id) throws IOException
49      {
50          map.remove(id);
51      }
52  
53      public List restore() throws IOException
54      {
55          return new ArrayList();
56      }
57  
58      public void open() throws IOException
59      {
60          // nothing to do
61      }
62  
63      public void close() throws IOException
64      {
65          // nothing to do
66      }
67  
68      public boolean isTransient()
69      {
70          return true;
71      }
72  }