Coverage Report - org.mule.util.store.AbstractMonitoredObjectStore
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractMonitoredObjectStore
0%
0/37
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: AbstractMonitoredObjectStore.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  
 package org.mule.util.store;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.context.MuleContextAware;
 14  
 import org.mule.api.lifecycle.Disposable;
 15  
 import org.mule.api.lifecycle.Initialisable;
 16  
 import org.mule.api.lifecycle.InitialisationException;
 17  
 import org.mule.api.store.ObjectStore;
 18  
 import org.mule.config.i18n.CoreMessages;
 19  
 import org.mule.util.UUID;
 20  
 import org.mule.util.concurrent.DaemonThreadFactory;
 21  
 
 22  
 import java.io.Serializable;
 23  
 
 24  
 import edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor;
 25  
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 26  
 
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 
 30  
 /**
 31  
  * TODO
 32  
  */
 33  0
 public abstract class AbstractMonitoredObjectStore<T extends Serializable> 
 34  
     implements ObjectStore<T>, Runnable, MuleContextAware, Initialisable, Disposable
 35  
 {
 36  0
     protected final Log logger = LogFactory.getLog(this.getClass());
 37  
 
 38  
     protected MuleContext context;
 39  
     protected ScheduledThreadPoolExecutor scheduler;
 40  
 
 41  
     /**
 42  
      * the maximum number of entries that this store keeps around. Specify <em>-1</em> if the store 
 43  
      * is supposed to be "unbounded".
 44  
      */
 45  0
     protected int maxEntries = 4000;
 46  
 
 47  
     /**
 48  
      * The time-to-live for each message ID, specified in milliseconds, or <em>-1</em> for entries 
 49  
      * that should never expire. <b>DO NOT</b> combine this with an unbounded store!
 50  
      */
 51  0
     protected int entryTTL = -1;
 52  
 
 53  
     /**
 54  
      * The interval for periodic bounded size enforcement and entry expiration, specified in 
 55  
      * milliseconds. Arbitrary positive values between 1 millisecond and several hours or days are 
 56  
      * possible, but should be chosen carefully according to the expected message rate to prevent 
 57  
      * out of memory conditions.
 58  
      */
 59  0
     protected int expirationInterval = 1000;
 60  
 
 61  
     /**
 62  
      * A name for this store, can be used for logging and identification purposes.
 63  
      */
 64  0
     protected String name = null;
 65  
 
 66  
     public void initialise() throws InitialisationException
 67  
     {
 68  0
         if (name == null)
 69  
         {
 70  0
             name = UUID.getUUID();
 71  
         }
 72  
 
 73  0
         if (expirationInterval <= 0)
 74  
         {
 75  0
             throw new IllegalArgumentException(CoreMessages.propertyHasInvalidValue("expirationInterval",
 76  
                     new Integer(expirationInterval)).toString());
 77  
         }
 78  
 
 79  0
         if (scheduler == null)
 80  
         {
 81  0
             this.scheduler = new ScheduledThreadPoolExecutor(1);
 82  0
             scheduler.setThreadFactory(new DaemonThreadFactory(name + "-Monitor", this.getClass().getClassLoader()));
 83  0
             scheduler.scheduleWithFixedDelay(this, 0, expirationInterval, TimeUnit.MILLISECONDS);
 84  
         }
 85  0
     }
 86  
 
 87  
     public final void run()
 88  
     {
 89  0
         expire();
 90  0
     }
 91  
 
 92  
     public void dispose()
 93  
     {
 94  0
         if (scheduler != null)
 95  
         {
 96  0
             scheduler.shutdown();
 97  
         }
 98  0
     }
 99  
 
 100  
     public void setEntryTTL(int entryTTL)
 101  
     {
 102  0
         this.entryTTL = entryTTL;
 103  0
     }
 104  
 
 105  
     public void setExpirationInterval(int expirationInterval)
 106  
     {
 107  0
         this.expirationInterval = expirationInterval;
 108  0
     }
 109  
 
 110  
     public void setMaxEntries(int maxEntries)
 111  
     {
 112  0
         this.maxEntries = maxEntries;
 113  0
     }
 114  
 
 115  
     public void setScheduler(ScheduledThreadPoolExecutor scheduler)
 116  
     {
 117  0
         this.scheduler = scheduler;
 118  0
     }
 119  
 
 120  
     public void setName(String id)
 121  
     {
 122  0
         this.name = id;
 123  0
     }
 124  
 
 125  
     public void setMuleContext(MuleContext context)
 126  
     {
 127  0
         this.context = context;
 128  0
     }
 129  
 
 130  
     public int getEntryTTL()
 131  
     {
 132  0
         return entryTTL;
 133  
     }
 134  
 
 135  
     public int getExpirationInterval()
 136  
     {
 137  0
         return expirationInterval;
 138  
     }
 139  
 
 140  
     public int getMaxEntries()
 141  
     {
 142  0
         return maxEntries;
 143  
     }
 144  
 
 145  
     public String getName()
 146  
     {
 147  0
         return name;
 148  
     }
 149  
 
 150  
     public ScheduledThreadPoolExecutor getScheduler()
 151  
     {
 152  0
         return scheduler;
 153  
     }
 154  
 
 155  
     protected abstract void expire();
 156  
 }