activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r567796 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/broker/jmx/ main/java/org/apache/activemq/broker/region/cursors/ main/java/org/apache/activemq/usage/ test/java/org/apache/a...
Date Mon, 20 Aug 2007 19:30:36 GMT
Author: chirino
Date: Mon Aug 20 12:30:33 2007
New Revision: 567796

URL: http://svn.apache.org/viewvc?rev=567796&view=rev
Log:
Made the SystemUsage and associated *Usage classes IOC friendly so that they can be configured
via xbean/spring.  Fixed the ConfigTest test case.


Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/MemoryUsage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/StoreUsage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/SystemUsage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/TempUsage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQDeadlockTestW4Brokers.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/example.xml

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Mon Aug 20 12:30:33 2007
@@ -118,7 +118,7 @@
     private ObjectName brokerObjectName;
     private TaskRunnerFactory taskRunnerFactory;
     private TaskRunnerFactory persistenceTaskRunnerFactory;
-    private SystemUsage usageManager;
+    private SystemUsage systemUsage;
     private SystemUsage producerSystemUsage;
     private SystemUsage consumerSystemUsage;
     private PersistenceAdapter persistenceAdapter;
@@ -646,23 +646,23 @@
         this.populateJMSXUserID = populateJMSXUserID;
     }
 
-    public SystemUsage getUsageManager() {
+    public SystemUsage getSystemUsage() {
         try {
-        if (usageManager == null) {
-            usageManager = new SystemUsage("Main",getPersistenceAdapter(),getTempDataStore());
-            usageManager.getMemoryUsage().setLimit(1024 * 1024 * 64); // Default to 64 Meg
-            usageManager.getTempDiskUsage().setLimit(1024 * 1024 * 1024 * 100);//10 Gb
-            usageManager.getStoreUsage().setLimit(1024 * 1024 * 1024 * 100); //100 GB
-        }
-        return usageManager;
-        }catch(IOException e) {
-            LOG.fatal("Cannot create SystemUsage",e);
+            if (systemUsage == null) {
+                systemUsage = new SystemUsage("Main", getPersistenceAdapter(), getTempDataStore());
+                systemUsage.getMemoryUsage().setLimit(1024 * 1024 * 64); // Default 64 Meg
+                systemUsage.getTempUsage().setLimit(1024 * 1024 * 1024 * 100); // 10 Gb
+                systemUsage.getStoreUsage().setLimit(1024 * 1024 * 1024 * 100); // 100 GB
+            }
+            return systemUsage;
+        } catch (IOException e) {
+            LOG.fatal("Cannot create SystemUsage", e);
             throw new RuntimeException("Fatally failed to create SystemUsage" + e.getMessage());
         }
     }
 
-    public void setUsageManager(SystemUsage memoryManager) {
-        this.usageManager = memoryManager;
+    public void setSystemUsage(SystemUsage memoryManager) {
+        this.systemUsage = memoryManager;
     }
 
     /**
@@ -671,7 +671,7 @@
      */
     public SystemUsage getConsumerSystemUsage() throws IOException {
         if (consumerSystemUsage == null) {
-            consumerSystemUsage = new SystemUsage(getUsageManager(), "Consumer");
+            consumerSystemUsage = new SystemUsage(getSystemUsage(), "Consumer");
             consumerSystemUsage.getMemoryUsage().setUsagePortion(0.5f);
         }
         return consumerSystemUsage;
@@ -690,7 +690,7 @@
      */
     public SystemUsage getProducerSystemUsage() throws IOException {
         if (producerSystemUsage == null) {
-            producerSystemUsage = new SystemUsage(getUsageManager(), "Producer");
+            producerSystemUsage = new SystemUsage(getSystemUsage(), "Producer");
             producerSystemUsage.getMemoryUsage().setUsagePortion(0.45f);
         }
         return producerSystemUsage;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
Mon Aug 20 12:30:33 2007
@@ -85,15 +85,15 @@
     }
 
     public int getMemoryPercentageUsed() {
-        return brokerService.getUsageManager().getMemoryUsage().getPercentUsage();
+        return brokerService.getSystemUsage().getMemoryUsage().getPercentUsage();
     }
 
     public long getMemoryLimit() {
-        return brokerService.getUsageManager().getMemoryUsage().getLimit();
+        return brokerService.getSystemUsage().getMemoryUsage().getLimit();
     }
 
     public void setMemoryLimit(long limit) {
-        brokerService.getUsageManager().getMemoryUsage().setLimit(limit);
+        brokerService.getSystemUsage().getMemoryUsage().setLimit(limit);
     }
 
     public void resetStatistics() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java
Mon Aug 20 12:30:33 2007
@@ -148,7 +148,7 @@
             } else {
                 flushToDisk();
                 node.decrementReferenceCount();
-                systemUsage.getTempDiskUsage().waitForSpace();
+                systemUsage.getTempUsage().waitForSpace();
                 getDiskList().addLast(node);
             }
         } catch (Exception e) {
@@ -168,7 +168,7 @@
                 memoryList.addFirst(node);
             } else {
                 flushToDisk();
-                systemUsage.getTempDiskUsage().waitForSpace();
+                systemUsage.getTempUsage().waitForSpace();
                 node.decrementReferenceCount();
                 getDiskList().addFirst(node);
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/MemoryUsage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/MemoryUsage.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/MemoryUsage.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/MemoryUsage.java
Mon Aug 20 12:30:33 2007
@@ -16,24 +16,20 @@
  */
 package org.apache.activemq.usage;
 
-
 /**
  * Used to keep track of how much of something is being used so that a
- * productive working set usage can be controlled.
- * 
- * Main use case is manage memory usage.
+ * productive working set usage can be controlled. Main use case is manage
+ * memory usage.
  * 
  * @org.apache.xbean.XBean
- * 
  * @version $Revision: 1.3 $
  */
-public class MemoryUsage extends Usage{
+public class MemoryUsage extends Usage<MemoryUsage> {
 
-    private MemoryUsage parent;
     private long usage;
 
-    public MemoryUsage(){
-        this(null,"default");
+    public MemoryUsage() {
+        this(null, null);
     }
 
     /**
@@ -43,73 +39,72 @@
      * 
      * @param parent
      */
-    public MemoryUsage(MemoryUsage parent){
-        this(parent,"default");
+    public MemoryUsage(MemoryUsage parent) {
+        this(parent, "default");
     }
 
-    public MemoryUsage(String name){
-        this(null,name);
+    public MemoryUsage(String name) {
+        this(null, name);
     }
 
-    public MemoryUsage(MemoryUsage parent,String name){
-        this(parent,name,1.0f);
+    public MemoryUsage(MemoryUsage parent, String name) {
+        this(parent, name, 1.0f);
     }
 
-    public MemoryUsage(MemoryUsage parent,String name,float portion){
-        super(parent,name,portion);
+    public MemoryUsage(MemoryUsage parent, String name, float portion) {
+        super(parent, name, portion);
     }
-    
+
     /**
      * @throws InterruptedException
      */
-    public void waitForSpace() throws InterruptedException{
-        if(parent!=null){
+    public void waitForSpace() throws InterruptedException {
+        if (parent != null) {
             parent.waitForSpace();
         }
-        synchronized(usageMutex){
-            for(int i=0;percentUsage>=100;i++){
+        synchronized (usageMutex) {
+            for (int i = 0; percentUsage >= 100; i++) {
                 usageMutex.wait();
             }
         }
     }
 
     /**
-     * @param timeout 
+     * @param timeout
      * @throws InterruptedException
-     * 
      * @return true if space
      */
-    public boolean waitForSpace(long timeout) throws InterruptedException{
-        if(parent!=null){
-            if(!parent.waitForSpace(timeout)){
+    public boolean waitForSpace(long timeout) throws InterruptedException {
+        if (parent != null) {
+            if (!parent.waitForSpace(timeout)) {
                 return false;
             }
         }
-        synchronized(usageMutex){
-            if(percentUsage>=100){
+        synchronized (usageMutex) {
+            if (percentUsage >= 100) {
                 usageMutex.wait(timeout);
             }
-            return percentUsage<100;
+            return percentUsage < 100;
         }
     }
-    
-    public boolean isFull(){
-        if(parent!=null&&parent.isFull()){
+
+    public boolean isFull() {
+        if (parent != null && parent.isFull()) {
             return true;
         }
-        synchronized(usageMutex){
-            return percentUsage>=100;
+        synchronized (usageMutex) {
+            return percentUsage >= 100;
         }
     }
 
     /**
      * Tries to increase the usage by value amount but blocks if this object is
      * currently full.
-     * @param value 
      * 
+     * @param value
      * @throws InterruptedException
      */
-    public void enqueueUsage(long value) throws InterruptedException{
+    public void enqueueUsage(long value) throws InterruptedException {
         waitForSpace();
         increaseUsage(value);
     }
@@ -119,17 +114,17 @@
      * 
      * @param value
      */
-    public void increaseUsage(long value){
-        if(value==0){
+    public void increaseUsage(long value) {
+        if (value == 0) {
             return;
         }
-        if(parent!=null){
-            parent.increaseUsage(value);
+        if (parent != null) {
+            ((MemoryUsage)parent).increaseUsage(value);
         }
         int percentUsage;
-        synchronized(usageMutex){
-            usage+=value;
-            percentUsage=caclPercentUsage();
+        synchronized (usageMutex) {
+            usage += value;
+            percentUsage = caclPercentUsage();
         }
         setPercentUsage(percentUsage);
     }
@@ -139,22 +134,30 @@
      * 
      * @param value
      */
-    public void decreaseUsage(long value){
-        if(value==0){
+    public void decreaseUsage(long value) {
+        if (value == 0) {
             return;
         }
-        if(parent!=null){
+        if (parent != null) {
             parent.decreaseUsage(value);
         }
         int percentUsage;
-        synchronized(usageMutex){
-            usage-=value;
-            percentUsage=caclPercentUsage();
+        synchronized (usageMutex) {
+            usage -= value;
+            percentUsage = caclPercentUsage();
         }
         setPercentUsage(percentUsage);
     }
 
-    protected long retrieveUsage(){
+    protected long retrieveUsage() {
+        return usage;
+    }
+
+    public long getUsage() {
         return usage;
+    }
+
+    public void setUsage(long usage) {
+        this.usage = usage;
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/StoreUsage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/StoreUsage.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/StoreUsage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/StoreUsage.java Mon
Aug 20 12:30:33 2007
@@ -20,29 +20,42 @@
 
 /**
  * Used to keep track of how much of something is being used so that a
- * productive working set usage can be controlled.
- * 
- * Main use case is manage memory usage.
+ * productive working set usage can be controlled. Main use case is manage
+ * memory usage.
  * 
  * @org.apache.xbean.XBean
- * 
  * @version $Revision: 1.3 $
  */
-public class StoreUsage extends Usage{
+public class StoreUsage extends Usage<StoreUsage> {
 
-    final private PersistenceAdapter store;
+    private PersistenceAdapter store;
 
-    public StoreUsage(String name,PersistenceAdapter store){
-        super(null,name,1.0f);
-        this.store=store;
+    public StoreUsage() {
+        super(null, null, 1.0f);
     }
-    
-    public StoreUsage(StoreUsage parent,String name){
-        super(parent,name,1.0f);
-        this.store=parent.store;
+
+    public StoreUsage(String name, PersistenceAdapter store) {
+        super(null, name, 1.0f);
+        this.store = store;
+    }
+
+    public StoreUsage(StoreUsage parent, String name) {
+        super(parent, name, 1.0f);
+        this.store = parent.store;
     }
 
-    protected long retrieveUsage(){
+    protected long retrieveUsage() {
+        if (store == null)
+            return 0;
         return store.size();
+    }
+
+    public PersistenceAdapter getStore() {
+        return store;
+    }
+
+    public void setStore(PersistenceAdapter store) {
+        this.store = store;
+        onLimitChange();
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/SystemUsage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/SystemUsage.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/SystemUsage.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/SystemUsage.java
Mon Aug 20 12:30:33 2007
@@ -22,102 +22,96 @@
 import org.apache.activemq.kaha.Store;
 import org.apache.activemq.store.PersistenceAdapter;
 
-
 /**
- * Holder for Usage instances for memory, store and temp files
- * 
- * Main use case is manage memory usage.
+ * Holder for Usage instances for memory, store and temp files Main use case is
+ * manage memory usage.
  * 
  * @org.apache.xbean.XBean
- * 
  * @version $Revision: 1.3 $
  */
-public class SystemUsage implements Service{
+public class SystemUsage implements Service {
+
+    private SystemUsage parent;
+    private String name;
+    private MemoryUsage memoryUsage;
+    private StoreUsage storeUsage;
+    private TempUsage tempUsage;
 
-    private final SystemUsage parent;
-    private final String name;
-    private final MemoryUsage memoryUsage;
-    private final StoreUsage storeUsage;
-    private final TempUsage tempDiskUsage;
     /**
      * True if someone called setSendFailIfNoSpace() on this particular usage
      * manager
      */
     private boolean sendFailIfNoSpaceExplicitySet;
     private boolean sendFailIfNoSpace;
-    private List<SystemUsage> children=new CopyOnWriteArrayList<SystemUsage>();
+    private List<SystemUsage> children = new CopyOnWriteArrayList<SystemUsage>();
 
-    public SystemUsage(){
-        this.parent=null;
-        this.name="default";
-        this.memoryUsage=new MemoryUsage(name+":memory");
-        this.storeUsage=null;
-        this.tempDiskUsage=null;
+    public SystemUsage() {
+        this("default", null, null);
     }
 
-    public SystemUsage(String name,PersistenceAdapter adapter,Store tempStore){
-        this.parent=null;
-        this.name=name;
-        this.memoryUsage=new MemoryUsage(name+":memory");
-        this.storeUsage=new StoreUsage(name+":store",adapter);
-        this.tempDiskUsage=new TempUsage(name+":temp",tempStore);
+    public SystemUsage(String name, PersistenceAdapter adapter, Store tempStore) {
+        this.parent = null;
+        this.name = name;
+        this.memoryUsage = new MemoryUsage(name + ":memory");
+        this.storeUsage = new StoreUsage(name + ":store", adapter);
+        this.tempUsage = new TempUsage(name + ":temp", tempStore);
     }
 
-    public SystemUsage(SystemUsage parent,String name){
-        this.parent=parent;
-        this.name=name;
-        this.memoryUsage=new MemoryUsage(parent.memoryUsage,name+":memory");
-        this.storeUsage=new StoreUsage(parent.storeUsage,name+":store");
-        this.tempDiskUsage=new TempUsage(parent!=null?parent.tempDiskUsage:null,name+":temp");
+    public SystemUsage(SystemUsage parent, String name) {
+        this.parent = parent;
+        this.name = name;
+        this.memoryUsage = new MemoryUsage(parent.memoryUsage, name + ":memory");
+        this.storeUsage = new StoreUsage(parent.storeUsage, name + ":store");
+        this.tempUsage = new TempUsage(parent.tempUsage, name + ":temp");
     }
 
-    public String getName(){
+    public String getName() {
         return name;
     }
 
     /**
      * @return the memoryUsage
      */
-    public MemoryUsage getMemoryUsage(){
+    public MemoryUsage getMemoryUsage() {
         return this.memoryUsage;
     }
 
     /**
      * @return the storeUsage
      */
-    public StoreUsage getStoreUsage(){
+    public StoreUsage getStoreUsage() {
         return this.storeUsage;
     }
 
     /**
      * @return the tempDiskUsage
      */
-    public TempUsage getTempDiskUsage(){
-        return this.tempDiskUsage;
+    public TempUsage getTempUsage() {
+        return this.tempUsage;
     }
 
-    public String toString(){
-        return "UsageManager("+getName()+")";
+    public String toString() {
+        return "UsageManager(" + getName() + ")";
     }
 
-    public void start(){
-        if(parent!=null){
+    public void start() {
+        if (parent != null) {
             parent.addChild(this);
         }
         this.memoryUsage.start();
         this.storeUsage.start();
-        this.tempDiskUsage.start();
+        this.tempUsage.start();
     }
 
-    public void stop(){
-        if(parent!=null){
+    public void stop() {
+        if (parent != null) {
             parent.removeChild(this);
         }
         this.memoryUsage.stop();
         this.storeUsage.stop();
-        this.tempDiskUsage.stop();
+        this.tempUsage.stop();
     }
-    
+
     /**
      * Sets whether or not a send() should fail if there is no space free. The
      * default value is false which means to block the send() method until space
@@ -136,11 +130,71 @@
         }
     }
 
-    private void addChild(SystemUsage child){
+    private void addChild(SystemUsage child) {
         children.add(child);
     }
 
-    private void removeChild(SystemUsage child){
+    private void removeChild(SystemUsage child) {
         children.remove(child);
+    }
+
+    public SystemUsage getParent() {
+        return parent;
+    }
+
+    public void setParent(SystemUsage parent) {
+        this.parent = parent;
+    }
+
+    public boolean isSendFailIfNoSpaceExplicitySet() {
+        return sendFailIfNoSpaceExplicitySet;
+    }
+
+    public void setSendFailIfNoSpaceExplicitySet(boolean sendFailIfNoSpaceExplicitySet) {
+        this.sendFailIfNoSpaceExplicitySet = sendFailIfNoSpaceExplicitySet;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+        this.memoryUsage.setName(name + ":memory");
+        this.storeUsage.setName(name + ":store");
+        this.tempUsage.setName(name + ":temp");
+    }
+
+    public void setMemoryUsage(MemoryUsage memoryUsage) {
+        if (memoryUsage.getName() == null) {
+            memoryUsage.setName(this.memoryUsage.getName());
+        }
+        if (parent != null) {
+            memoryUsage.setParent(parent.memoryUsage);
+        }
+        this.memoryUsage = memoryUsage;
+    }
+
+    public void setStoreUsage(StoreUsage storeUsage) {
+        if (storeUsage.getStore() == null) {
+            storeUsage.setStore(this.storeUsage.getStore());
+        }
+        if (storeUsage.getName() == null) {
+            storeUsage.setName(this.storeUsage.getName());
+        }
+        if (parent != null) {
+            storeUsage.setParent(parent.storeUsage);
+        }
+        this.storeUsage = storeUsage;
+
+    }
+
+    public void setTempUsage(TempUsage tempDiskUsage) {
+        if (tempDiskUsage.getStore() == null) {
+            tempDiskUsage.setStore(this.tempUsage.getStore());
+        }
+        if (tempDiskUsage.getName() == null) {
+            tempDiskUsage.setName(this.tempUsage.getName());
+        }
+        if (parent != null) {
+            tempDiskUsage.setParent(parent.tempUsage);
+        }
+        this.tempUsage = tempDiskUsage;
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/TempUsage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/TempUsage.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/TempUsage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/TempUsage.java Mon
Aug 20 12:30:33 2007
@@ -20,30 +20,43 @@
 
 /**
  * Used to keep track of how much of something is being used so that a
- * productive working set usage can be controlled.
- * 
- * Main use case is manage memory usage.
+ * productive working set usage can be controlled. Main use case is manage
+ * memory usage.
  * 
  * @org.apache.xbean.XBean
- * 
  * @version $Revision: 1.3 $
  */
-public class TempUsage extends Usage{
+public class TempUsage extends Usage<TempUsage> {
 
-    final private Store store;
+    private Store store;
 
-        
-    public TempUsage(String name,Store store){
-        super(null,name,1.0f);
-        this.store=store;
+    public TempUsage() {
+        super(null, null, 1.0f);
     }
-    
-    public TempUsage(TempUsage parent,String name){
-        super(parent,name,1.0f);
-        this.store=parent.store;
+
+    public TempUsage(String name, Store store) {
+        super(null, name, 1.0f);
+        this.store = store;
+    }
+
+    public TempUsage(TempUsage parent, String name) {
+        super(parent, name, 1.0f);
+        this.store = parent.store;
     }
 
-    protected long retrieveUsage(){
+    protected long retrieveUsage() {
+        if (store == null) {
+            return 0;
+        }
         return store.size();
     }
-}
\ No newline at end of file
+
+    public Store getStore() {
+        return store;
+    }
+
+    public void setStore(Store store) {
+        this.store = store;
+        onLimitChange();
+    }
+}

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java Mon Aug
20 12:30:33 2007
@@ -28,38 +28,36 @@
 
 /**
  * Used to keep track of how much of something is being used so that a
- * productive working set usage can be controlled.
- * 
- * Main use case is manage memory usage.
+ * productive working set usage can be controlled. Main use case is manage
+ * memory usage.
  * 
  * @org.apache.xbean.XBean
- * 
  * @version $Revision: 1.3 $
  */
-public abstract class Usage implements Service{
+public abstract class Usage<T extends Usage> implements Service {
 
-    private static final Log LOG=LogFactory.getLog(Usage.class);
-    protected final Object usageMutex=new Object();
+    private static final Log LOG = LogFactory.getLog(Usage.class);
+    protected final Object usageMutex = new Object();
     protected int percentUsage;
-    private final Usage parent;
+    protected T parent;
     private UsageCapacity limiter = new DefaultUsageCapacity();
-    private int percentUsageMinDelta=1;
-    private final List<UsageListener> listeners=new CopyOnWriteArrayList<UsageListener>();
-    private final boolean debug=LOG.isDebugEnabled();
-    private String name="";
-    private float usagePortion=1.0f;
-    private List<Usage> children=new CopyOnWriteArrayList<Usage>();
-    private final List<Runnable> callbacks=new LinkedList<Runnable>();
+    private int percentUsageMinDelta = 1;
+    private final List<UsageListener> listeners = new CopyOnWriteArrayList<UsageListener>();
+    private final boolean debug = LOG.isDebugEnabled();
+    private String name;
+    private float usagePortion = 1.0f;
+    private List<T> children = new CopyOnWriteArrayList<T>();
+    private final List<Runnable> callbacks = new LinkedList<Runnable>();
     private int pollingTime = 100;
-   
-    public Usage(Usage parent,String name,float portion){
-        this.parent=parent;
-        this.usagePortion=portion;
-        if(parent!=null){
-            this.limiter.setLimit((long)(parent.getLimit()*portion));
-            this.name=parent.name+":";
+
+    public Usage(T parent, String name, float portion) {
+        this.parent = parent;
+        this.usagePortion = portion;
+        if (parent != null) {
+            this.limiter.setLimit((long)(parent.getLimit() * portion));
+            name = parent.name + ":" + name;
         }
-        this.name+=name;
+        this.name = name;
     }
 
     protected abstract long retrieveUsage();
@@ -67,63 +65,60 @@
     /**
      * @throws InterruptedException
      */
-    public void waitForSpace() throws InterruptedException{
+    public void waitForSpace() throws InterruptedException {
         waitForSpace(0);
     }
 
     /**
-     * @param timeout 
+     * @param timeout
      * @throws InterruptedException
-     * 
      * @return true if space
      */
-    public boolean waitForSpace(long timeout) throws InterruptedException{
-        if(parent!=null){
-            if(!parent.waitForSpace(timeout)){
+    public boolean waitForSpace(long timeout) throws InterruptedException {
+        if (parent != null) {
+            if (!parent.waitForSpace(timeout)) {
                 return false;
             }
         }
-        synchronized(usageMutex){
+        synchronized (usageMutex) {
             caclPercentUsage();
-            if(percentUsage>=100){
-                long deadline=timeout>0?System.currentTimeMillis()+timeout:Long.MAX_VALUE;
-                long timeleft=deadline;
-                while(timeleft>0){
+            if (percentUsage >= 100) {
+                long deadline = timeout > 0 ? System.currentTimeMillis() + timeout : Long.MAX_VALUE;
+                long timeleft = deadline;
+                while (timeleft > 0) {
                     caclPercentUsage();
-                    if(percentUsage>=100){
+                    if (percentUsage >= 100) {
                         usageMutex.wait(pollingTime);
-                        timeleft=deadline-System.currentTimeMillis();
-                    }else{
+                        timeleft = deadline - System.currentTimeMillis();
+                    } else {
                         break;
                     }
                 }
             }
-            return percentUsage<100;
+            return percentUsage < 100;
         }
     }
 
-    
-
-    public boolean isFull(){
-        if(parent!=null&&parent.isFull()){
+    public boolean isFull() {
+        if (parent != null && parent.isFull()) {
             return true;
         }
-        synchronized(usageMutex){
+        synchronized (usageMutex) {
             caclPercentUsage();
-            return percentUsage>=100;
+            return percentUsage >= 100;
         }
     }
 
-    public void addUsageListener(UsageListener listener){
+    public void addUsageListener(UsageListener listener) {
         listeners.add(listener);
     }
 
-    public void removeUsageListener(UsageListener listener){
+    public void removeUsageListener(UsageListener listener) {
         listeners.remove(listener);
     }
 
-    public long getLimit(){
-        synchronized(usageMutex){
+    public long getLimit() {
+        synchronized (usageMutex) {
             return limiter.getLimit();
         }
     }
@@ -131,54 +126,52 @@
     /**
      * Sets the memory limit in bytes. Setting the limit in bytes will set the
      * usagePortion to 0 since the UsageManager is not going to be portion based
-     * off the parent.
-     * 
-     * When set using XBean, you can use values such as: "20 mb", "1024 kb", or
-     * "1 gb"
+     * off the parent. When set using XBean, you can use values such as: "20
+     * mb", "1024 kb", or "1 gb"
      * 
      * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryPropertyEditor"
      */
-    public void setLimit(long limit){
-        if(percentUsageMinDelta<0){
+    public void setLimit(long limit) {
+        if (percentUsageMinDelta < 0) {
             throw new IllegalArgumentException("percentUsageMinDelta must be greater or equal
to 0");
         }
-        synchronized(usageMutex){
+        synchronized (usageMutex) {
             this.limiter.setLimit(limit);
-            this.usagePortion=0;
+            this.usagePortion = 0;
         }
         onLimitChange();
     }
 
-    private void onLimitChange(){
+    protected void onLimitChange() {
         // We may need to calculate the limit
-        if(usagePortion>0&&parent!=null){
-            synchronized(usageMutex){
-                this.limiter.setLimit((long)(parent.getLimit()*usagePortion));
+        if (usagePortion > 0 && parent != null) {
+            synchronized (usageMutex) {
+                this.limiter.setLimit((long)(parent.getLimit() * usagePortion));
             }
         }
         // Reset the percent currently being used.
         int percentUsage;
-        synchronized(usageMutex){
-            percentUsage=caclPercentUsage();
+        synchronized (usageMutex) {
+            percentUsage = caclPercentUsage();
         }
         setPercentUsage(percentUsage);
         // Let the children know that the limit has changed. They may need to
         // set
         // their limits based on ours.
-        for(Usage child:children){
+        for (T child : children) {
             child.onLimitChange();
         }
     }
 
-    public float getUsagePortion(){
-        synchronized(usageMutex){
+    public float getUsagePortion() {
+        synchronized (usageMutex) {
             return usagePortion;
         }
     }
 
-    public void setUsagePortion(float usagePortion){
-        synchronized(usageMutex){
-            this.usagePortion=usagePortion;
+    public void setUsagePortion(float usagePortion) {
+        synchronized (usageMutex) {
+            this.usagePortion = usagePortion;
         }
         onLimitChange();
     }
@@ -187,14 +180,14 @@
      * Sets the minimum number of percentage points the usage has to change
      * before a UsageListener event is fired by the manager.
      */
-    public int getPercentUsage(){
-        synchronized(usageMutex){
+    public int getPercentUsage() {
+        synchronized (usageMutex) {
             return percentUsage;
         }
     }
 
-    public int getPercentUsageMinDelta(){
-        synchronized(usageMutex){
+    public int getPercentUsageMinDelta() {
+        synchronized (usageMutex) {
             return percentUsageMinDelta;
         }
     }
@@ -205,89 +198,90 @@
      * 
      * @param percentUsageMinDelta
      */
-    public void setPercentUsageMinDelta(int percentUsageMinDelta){
-        if(percentUsageMinDelta<1){
+    public void setPercentUsageMinDelta(int percentUsageMinDelta) {
+        if (percentUsageMinDelta < 1) {
             throw new IllegalArgumentException("percentUsageMinDelta must be greater than
0");
         }
         int percentUsage;
-        synchronized(usageMutex){
-            this.percentUsageMinDelta=percentUsageMinDelta;
-            percentUsage=caclPercentUsage();
+        synchronized (usageMutex) {
+            this.percentUsageMinDelta = percentUsageMinDelta;
+            percentUsage = caclPercentUsage();
         }
         setPercentUsage(percentUsage);
     }
 
-    public long getUsage(){
-        synchronized(usageMutex){
+    public long getUsage() {
+        synchronized (usageMutex) {
             return retrieveUsage();
         }
     }
 
-    protected void setPercentUsage(int value){
-        synchronized(usageMutex){
-            int oldValue=percentUsage;
-            percentUsage=value;
-            if(oldValue!=value){
-                fireEvent(oldValue,value);
+    protected void setPercentUsage(int value) {
+        synchronized (usageMutex) {
+            int oldValue = percentUsage;
+            percentUsage = value;
+            if (oldValue != value) {
+                fireEvent(oldValue, value);
             }
         }
     }
 
-    protected int caclPercentUsage(){
-        if(limiter.getLimit()==0){
+    protected int caclPercentUsage() {
+        if (limiter.getLimit() == 0) {
             return 0;
         }
-        return (int)((((retrieveUsage()*100)/limiter.getLimit())/percentUsageMinDelta)*percentUsageMinDelta);
+        return (int)((((retrieveUsage() * 100) / limiter.getLimit()) / percentUsageMinDelta)
* percentUsageMinDelta);
     }
 
-    private void fireEvent(int oldPercentUsage,int newPercentUsage){
-        if(debug){
-            LOG.debug("Memory usage change.  from: "+oldPercentUsage+", to: "+newPercentUsage);
+    private void fireEvent(int oldPercentUsage, int newPercentUsage) {
+        if (debug) {
+            LOG.debug("Memory usage change.  from: " + oldPercentUsage + ", to: " + newPercentUsage);
         }
         // Switching from being full to not being full..
-        if(oldPercentUsage>=100&&newPercentUsage<100){
-            synchronized(usageMutex){
+        if (oldPercentUsage >= 100 && newPercentUsage < 100) {
+            synchronized (usageMutex) {
                 usageMutex.notifyAll();
-                for(Iterator<Runnable> iter=new ArrayList<Runnable>(callbacks).iterator();iter.hasNext();){
-                    Runnable callback=iter.next();
+                for (Iterator<Runnable> iter = new ArrayList<Runnable>(callbacks).iterator();
iter.hasNext();) {
+                    Runnable callback = iter.next();
                     callback.run();
                 }
                 callbacks.clear();
             }
         }
         // Let the listeners know
-        for(Iterator<UsageListener> iter=listeners.iterator();iter.hasNext();){
-            UsageListener l=iter.next();
-            l.onUsageChanged(this,oldPercentUsage,newPercentUsage);
+        for (Iterator<UsageListener> iter = listeners.iterator(); iter.hasNext();)
{
+            UsageListener l = iter.next();
+            l.onUsageChanged(this, oldPercentUsage, newPercentUsage);
         }
     }
 
-    public String getName(){
+    public String getName() {
         return name;
     }
 
-    public String toString(){
-        return "Usage("+getName()+") percentUsage="+percentUsage+"%, usage="+retrieveUsage()+"
limit="+limiter.getLimit()
-                +" percentUsageMinDelta="+percentUsageMinDelta+"%";
+    public String toString() {
+        return "Usage(" + getName() + ") percentUsage=" + percentUsage + "%, usage=" + retrieveUsage()
+ " limit=" + limiter.getLimit() + " percentUsageMinDelta=" + percentUsageMinDelta + "%";
     }
 
-    public void start(){
-        if(parent!=null){
+    @SuppressWarnings("unchecked")
+    public void start() {
+        if (parent != null) {
             parent.addChild(this);
         }
     }
 
-    public void stop(){
-        if(parent!=null){
+    @SuppressWarnings("unchecked")
+    public void stop() {
+        if (parent != null) {
             parent.removeChild(this);
         }
     }
 
-    private void addChild(Usage child){
+    private void addChild(T child) {
         children.add(child);
     }
 
-    private void removeChild(Usage child){
+    private void removeChild(T child) {
         children.remove(child);
     }
 
@@ -296,63 +290,71 @@
      * @return true if the UsageManager was full. The callback will only be
      *         called if this method returns true.
      */
-    public boolean notifyCallbackWhenNotFull(final Runnable callback){
-        if(parent!=null){
-            Runnable r=new Runnable(){
-
-                public void run(){
-                    synchronized(usageMutex){
-                        if(percentUsage>=100){
+    public boolean notifyCallbackWhenNotFull(final Runnable callback) {
+        if (parent != null) {
+            Runnable r = new Runnable() {
+
+                public void run() {
+                    synchronized (usageMutex) {
+                        if (percentUsage >= 100) {
                             callbacks.add(callback);
-                        }else{
+                        } else {
                             callback.run();
                         }
                     }
                 }
             };
-            if(parent.notifyCallbackWhenNotFull(r)){
+            if (parent.notifyCallbackWhenNotFull(r)) {
                 return true;
             }
         }
-        synchronized(usageMutex){
-            if(percentUsage>=100){
+        synchronized (usageMutex) {
+            if (percentUsage >= 100) {
                 callbacks.add(callback);
                 return true;
-            }else{
+            } else {
                 return false;
             }
         }
     }
 
-    
     /**
      * @return the limiter
      */
-    public UsageCapacity getLimiter(){
+    public UsageCapacity getLimiter() {
         return this.limiter;
     }
 
-    
     /**
      * @param limiter the limiter to set
      */
-    public void setLimiter(UsageCapacity limiter){
-        this.limiter=limiter;
+    public void setLimiter(UsageCapacity limiter) {
+        this.limiter = limiter;
     }
 
-    
     /**
      * @return the pollingTime
      */
-    public int getPollingTime(){
+    public int getPollingTime() {
         return this.pollingTime;
     }
 
-    
     /**
      * @param pollingTime the pollingTime to set
      */
-    public void setPollingTime(int pollingTime){
-        this.pollingTime=pollingTime;
+    public void setPollingTime(int pollingTime) {
+        this.pollingTime = pollingTime;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public T getParent() {
+        return parent;
+    }
+
+    public void setParent(T parent) {
+        this.parent = parent;
     }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/AMQDeadlockTest3.java Mon
Aug 20 12:30:33 2007
@@ -240,7 +240,7 @@
 
         final SystemUsage memoryManager = new SystemUsage();
         memoryManager.getMemoryUsage().setLimit(5000000);
-        brokerService.setUsageManager(memoryManager);
+        brokerService.setSystemUsage(memoryManager);
 
         final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
 

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/MessageExpirationTest.java
Mon Aug 20 12:30:33 2007
@@ -91,7 +91,7 @@
 
         // Reduce the limit so that only 1 message can flow through the broker
         // at a time.
-        broker.getUsageManager().getMemoryUsage().setLimit(1);
+        broker.getSystemUsage().getMemoryUsage().setLimit(1);
 
         final Message m1 = createMessage(producerInfo, destination, deliveryMode);
         final Message m2 = createMessage(producerInfo, destination, deliveryMode, 1000);

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigTest.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigTest.java
Mon Aug 20 12:30:33 2007
@@ -233,13 +233,16 @@
 
             // Check usage manager
             // System.out.print("Checking memory manager configurations... ");
-            SystemUsage memMgr = broker.getUsageManager();
-            assertTrue("Should have a memory manager", memMgr != null);
-            assertEquals("UsageManager Config Error (limit)", 200000, memMgr.getMemoryUsage().getLimit());
-            assertEquals("UsageManager Config Error (percentUsageMinDelta)", 20, memMgr.getMemoryUsage().getPercentUsageMinDelta());
+            SystemUsage systemUsage = broker.getSystemUsage();
+            assertTrue("Should have a SystemUsage", systemUsage != null);
+            assertEquals("SystemUsage Config Error (MemoryUsage.limit)", 1024 * 1024 * 10,
systemUsage.getMemoryUsage().getLimit());
+            assertEquals("SystemUsage Config Error (MemoryUsage.percentUsageMinDelta)", 20,
systemUsage.getMemoryUsage().getPercentUsageMinDelta());
+            assertEquals("SystemUsage Config Error (TempUsage.limit)", 1024 * 1024 * 100,
systemUsage.getTempUsage().getLimit());
+            assertEquals("SystemUsage Config Error (StoreUsage.limit)", 1024 * 1024 * 1024,
systemUsage.getStoreUsage().getLimit());
+            assertEquals("SystemUsage Config Error (StoreUsage.name)", "foo", systemUsage.getStoreUsage().getName());
+                        
             LOG.info("Success");
 
-            LOG.info("Success");
         } finally {
             if (broker != null) {
                 broker.stop();

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQDeadlockTestW4Brokers.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQDeadlockTestW4Brokers.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQDeadlockTestW4Brokers.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQDeadlockTestW4Brokers.java
Mon Aug 20 12:30:33 2007
@@ -175,7 +175,7 @@
 
         final SystemUsage memoryManager = new SystemUsage();
         memoryManager.getMemoryUsage().setLimit(100000000);
-        brokerService.setUsageManager(memoryManager);
+        brokerService.setSystemUsage(memoryManager);
 
         final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
 

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQFailoverIssue.java
Mon Aug 20 12:30:33 2007
@@ -108,7 +108,7 @@
         brokerService.setUseJmx(true);
         final SystemUsage memoryManager = new SystemUsage();
         memoryManager.getMemoryUsage().setLimit(5000000);
-        brokerService.setUsageManager(memoryManager);
+        brokerService.setSystemUsage(memoryManager);
         final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
         final PolicyEntry entry = new PolicyEntry();
         entry.setQueue(">");

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/AMQStackOverFlowTest.java
Mon Aug 20 12:30:33 2007
@@ -119,7 +119,7 @@
 
         final SystemUsage memoryManager = new SystemUsage();
         memoryManager.getMemoryUsage().setLimit(10);
-        brokerService.setUsageManager(memoryManager);
+        brokerService.setSystemUsage(memoryManager);
 
         final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
 

Modified: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/example.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/example.xml?rev=567796&r1=567795&r2=567796&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/example.xml
(original)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/example.xml
Mon Aug 20 12:30:33 2007
@@ -76,9 +76,19 @@
             </amq:policyMap>
         </amq:destinationPolicy>
 
-        <amq:memoryManager>
-            <amq:usageManager limit="200000" percentUsageMinDelta="20"/>
-        </amq:memoryManager>
+        <amq:systemUsage>
+            <amq:systemUsage>
+	            <amq:memoryUsage>
+    	            <amq:memoryUsage limit="10 mb" percentUsageMinDelta="20"/>
+	            </amq:memoryUsage>
+	            <amq:tempUsage>
+    	            <amq:tempUsage limit="100 mb"/>
+	            </amq:tempUsage>
+	            <amq:storeUsage>
+    	            <amq:storeUsage limit="1 gb" name="foo"/>
+	            </amq:storeUsage>
+            </amq:systemUsage>
+        </amq:systemUsage>
 
         <amq:persistenceAdapter>
             <amq:memoryPersistenceAdapter init-method="createTransactionStore"/>



Mime
View raw message