Coverage Report - org.mule.util.queue.MemoryPersistenceStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
MemoryPersistenceStrategy
88%
14/16
50%
1/2
1.25
 
 1  
 /*
 2  
  * $Id: MemoryPersistenceStrategy.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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 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  112
 public class MemoryPersistenceStrategy implements QueuePersistenceStrategy
 23  
 {
 24  
 
 25  112
     private UUIDGenerator gen = UUIDGenerator.getInstance();
 26  
 
 27  112
     private Map map = Collections.synchronizedMap(new HashMap());
 28  
 
 29  
     protected Object getId(Object obj)
 30  
     {
 31  1040
         return gen.generateRandomBasedUUID();
 32  
     }
 33  
 
 34  
     /*
 35  
      * (non-Javadoc)
 36  
      * 
 37  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#store(java.lang.Object)
 38  
      */
 39  
     public Object store(String queue, Object obj) throws IOException
 40  
     {
 41  1040
         if (obj == null)
 42  
         {
 43  0
             throw new IllegalArgumentException("Cannot store null object.");
 44  
         }
 45  1040
         Object id = getId(obj);
 46  1040
         map.put(id, obj);
 47  1040
         return id;
 48  
     }
 49  
 
 50  
     /*
 51  
      * (non-Javadoc)
 52  
      * 
 53  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#load(java.lang.Object)
 54  
      */
 55  
     public Object load(String queue, Object id) throws IOException
 56  
     {
 57  1024
         return map.get(id);
 58  
     }
 59  
 
 60  
     /*
 61  
      * (non-Javadoc)
 62  
      * 
 63  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#remove(java.lang.Object)
 64  
      */
 65  
     public void remove(String queue, Object id) throws IOException
 66  
     {
 67  1026
         map.remove(id);
 68  1026
     }
 69  
 
 70  
     /*
 71  
      * (non-Javadoc)
 72  
      * 
 73  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#restore()
 74  
      */
 75  
     public List restore() throws IOException
 76  
     {
 77  18
         return new ArrayList();
 78  
     }
 79  
 
 80  
     /*
 81  
      * (non-Javadoc)
 82  
      * 
 83  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#open()
 84  
      */
 85  
     public void open() throws IOException
 86  
     {
 87  
         // nothing to do
 88  18
     }
 89  
 
 90  
     /*
 91  
      * (non-Javadoc)
 92  
      * 
 93  
      * @see org.mule.transaction.xa.queue.QueuePersistenceStrategy#close()
 94  
      */
 95  
     public void close() throws IOException
 96  
     {
 97  
         // nothing to do
 98  18
     }
 99  
 
 100  
     public boolean isTransient()
 101  
     {
 102  0
         return true;
 103  
     }
 104  
 }