org.apache.activemq.memory
Class UsageManager

java.lang.Object
  extended by org.apache.activemq.memory.UsageManager

public class UsageManager
extends java.lang.Object

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.

Version:
$Revision: 1.3 $

Constructor Summary
UsageManager()
           
UsageManager(UsageManager parent)
          Create the memory manager linked to a parent.
 
Method Summary
 void addUsageListener(UsageListener listener)
           
 void decreaseUsage(long value)
          Decreases the usage by the value amount.
 void enqueueUsage(long value)
          Tries to increase the usage by value amount but blocks if this object is currently full.
 long getLimit()
           
 int getPercentUsage()
           
 int getPercentUsageMinDelta()
           
 long getUsage()
           
 void increaseUsage(long value)
          Increases the usage by the value amount.
 boolean isFull()
           
 boolean isSendFailIfNoSpace()
           
 boolean notifyCallbackWhenNotFull(java.lang.Runnable callback)
           
 void removeUsageListener(UsageListener listener)
           
 void setLimit(long limit)
          Sets the memory limit in bytes.
 void setPercentUsageMinDelta(int percentUsageMinDelta)
          Sets the minimum number of percentage points the usage has to change before a UsageListener event is fired by the manager.
 void setSendFailIfNoSpace(boolean failProducerIfNoSpace)
          Sets whether or not a send() should fail if there is no space free.
 java.lang.String toString()
           
 void waitForSpace()
           
 boolean waitForSpace(long timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UsageManager

public UsageManager()

UsageManager

public UsageManager(UsageManager parent)
Create the memory manager linked to a parent. When the memory manager is linked to a parent then when usage increased or decreased, the parent's usage is also increased or decreased.

Parameters:
parent -
Method Detail

enqueueUsage

public void enqueueUsage(long value)
                  throws java.lang.InterruptedException
Tries to increase the usage by value amount but blocks if this object is currently full.

Throws:
java.lang.InterruptedException

waitForSpace

public void waitForSpace()
                  throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitForSpace

public boolean waitForSpace(long timeout)
                     throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

notifyCallbackWhenNotFull

public boolean notifyCallbackWhenNotFull(java.lang.Runnable callback)
Parameters:
callback -
Returns:
true if the UsageManager was full. The callback will only be called if this method returns true.

increaseUsage

public void increaseUsage(long value)
Increases the usage by the value amount.

Parameters:
value -

decreaseUsage

public void decreaseUsage(long value)
Decreases the usage by the value amount.

Parameters:
value -

isFull

public boolean isFull()

addUsageListener

public void addUsageListener(UsageListener listener)

removeUsageListener

public void removeUsageListener(UsageListener listener)

getLimit

public long getLimit()

setLimit

public void setLimit(long limit)
Sets the memory limit in bytes. When set using XBean, you can use values such as: "20 mb", "1024 kb", or "1 gb"


getPercentUsage

public int getPercentUsage()

getPercentUsageMinDelta

public int getPercentUsageMinDelta()

setPercentUsageMinDelta

public void setPercentUsageMinDelta(int percentUsageMinDelta)
Sets the minimum number of percentage points the usage has to change before a UsageListener event is fired by the manager.

Parameters:
percentUsageMinDelta -

getUsage

public long getUsage()

setSendFailIfNoSpace

public void setSendFailIfNoSpace(boolean failProducerIfNoSpace)
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 becomes available


isSendFailIfNoSpace

public boolean isSendFailIfNoSpace()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009 Apache Software Foundation. All Rights Reserved.