org.apache.activemq.usage
Class Usage<T extends Usage>

java.lang.Object
  extended by org.apache.activemq.usage.Usage<T>
All Implemented Interfaces:
Service
Direct Known Subclasses:
JobSchedulerUsage, MemoryUsage, StoreUsage, TempUsage

public abstract class Usage<T extends Usage>
extends Object
implements Service

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.


Field Summary
protected  String name
           
protected  T parent
           
protected  int percentUsage
           
protected  ReentrantReadWriteLock usageLock
           
protected  Condition waitForSpaceCondition
           
 
Constructor Summary
Usage(T parent, String name, float portion)
           
 
Method Summary
protected  void addChild(T child)
           
 void addUsageListener(UsageListener listener)
           
protected  int caclPercentUsage()
           
 ThreadPoolExecutor getExecutor()
           
 long getLimit()
           
 UsageCapacity getLimiter()
           
 String getName()
           
 T getParent()
           
 int getPercentUsage()
           
 int getPercentUsageMinDelta()
           
 int getPollingTime()
           
 long getUsage()
           
 float getUsagePortion()
           
 boolean isFull()
           
 boolean isFull(int highWaterMark)
           
 boolean isStarted()
           
 boolean notifyCallbackWhenNotFull(Runnable callback)
           
protected  void onLimitChange()
           
protected  void removeChild(T child)
           
 void removeUsageListener(UsageListener listener)
           
protected abstract  long retrieveUsage()
           
 void setExecutor(ThreadPoolExecutor executor)
           
 void setLimit(long limit)
          Sets the memory limit in bytes.
 void setLimiter(UsageCapacity limiter)
           
 void setName(String name)
           
 void setParent(T parent)
           
protected  void setPercentUsage(int value)
           
 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 setPollingTime(int pollingTime)
           
 void setUsagePortion(float usagePortion)
           
 void start()
           
 void stop()
           
 String toString()
           
 void waitForSpace()
           
 boolean waitForSpace(long timeout)
           
 boolean waitForSpace(long timeout, int highWaterMark)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

usageLock

protected final ReentrantReadWriteLock usageLock

waitForSpaceCondition

protected final Condition waitForSpaceCondition

percentUsage

protected int percentUsage

parent

protected T extends Usage parent

name

protected String name
Constructor Detail

Usage

public Usage(T parent,
             String name,
             float portion)
Method Detail

retrieveUsage

protected abstract long retrieveUsage()

waitForSpace

public void waitForSpace()
                  throws InterruptedException
Throws:
InterruptedException

waitForSpace

public boolean waitForSpace(long timeout)
                     throws InterruptedException
Throws:
InterruptedException

waitForSpace

public boolean waitForSpace(long timeout,
                            int highWaterMark)
                     throws InterruptedException
Parameters:
timeout -
Returns:
true if space
Throws:
InterruptedException

isFull

public boolean isFull()

isFull

public boolean isFull(int highWaterMark)

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. 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, values of the form "20 Mb", "1024kb", and "1g" can be used


onLimitChange

protected void onLimitChange()

getUsagePortion

public float getUsagePortion()

setUsagePortion

public void setUsagePortion(float usagePortion)

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()

setPercentUsage

protected void setPercentUsage(int value)

caclPercentUsage

protected int caclPercentUsage()

getName

public String getName()

toString

public String toString()
Overrides:
toString in class Object

start

public void start()
Specified by:
start in interface Service

stop

public void stop()
Specified by:
stop in interface Service

addChild

protected void addChild(T child)

removeChild

protected void removeChild(T child)

notifyCallbackWhenNotFull

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

getLimiter

public UsageCapacity getLimiter()
Returns:
the limiter

setLimiter

public void setLimiter(UsageCapacity limiter)
Parameters:
limiter - the limiter to set

getPollingTime

public int getPollingTime()
Returns:
the pollingTime

setPollingTime

public void setPollingTime(int pollingTime)
Parameters:
pollingTime - the pollingTime to set

setName

public void setName(String name)

getParent

public T getParent()

setParent

public void setParent(T parent)

setExecutor

public void setExecutor(ThreadPoolExecutor executor)

getExecutor

public ThreadPoolExecutor getExecutor()

isStarted

public boolean isStarted()


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.