View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util.queue;
8   
9   import org.mule.util.UUID;
10  
11  import java.io.IOException;
12  import java.util.ArrayList;
13  import java.util.Collections;
14  import java.util.HashMap;
15  import java.util.List;
16  import java.util.Map;
17  
18  
19  public class MemoryPersistenceStrategy implements QueuePersistenceStrategy
20  {
21      private Map map = Collections.synchronizedMap(new HashMap());
22  
23      protected Object getId(Object obj)
24      {
25          return UUID.getUUID();
26      }
27  
28      public Object store(String queue, Object obj) throws IOException
29      {
30          if (obj == null)
31          {
32              throw new IllegalArgumentException("Cannot store null object.");
33          }
34          Object id = getId(obj);
35          map.put(id, obj);
36          return id;
37      }
38  
39      public Object load(String queue, Object id) throws IOException
40      {
41          return map.get(id);
42      }
43  
44      public void remove(String queue, Object id) throws IOException
45      {
46          map.remove(id);
47      }
48  
49      public List restore() throws IOException
50      {
51          return new ArrayList();
52      }
53  
54      public void open() throws IOException
55      {
56          // nothing to do
57      }
58  
59      public void close() throws IOException
60      {
61          // nothing to do
62      }
63  
64      public boolean isTransient()
65      {
66          return true;
67      }
68  }