aicas logoJamaica 6.1 release 1

com.aicas.jamaica.lang
Class MemoryBudget

java.lang.Object
  extended by com.aicas.jamaica.lang.AllocationHandler
      extended by com.aicas.jamaica.lang.MemoryBudget

public abstract class MemoryBudget
extends AllocationHandler

MemoryBudget is a class that provides to equip a thread with a certain memory allocation budget. After the budget is exceeded, the thread will no longer succeed in any allocations that it does.


Constructor Summary
MemoryBudget(Thread t, long budget)
          Add a budget for a given thread
 
Method Summary
 boolean allocationPermitted()
          Is allocation within thread() still permitted?
 void allowAllocation()
          Permit allocation for this thread.
 long budget()
          Get the budget of a given thread
abstract  void budgetEmpty()
          Handler routine that is called when the budget of a certain thread is exhausted.
 void destroy()
          Remove this memory budget from thread().
 void forbidAllocation()
          Forbid allocation for this thread.
 Object handle(Object o)
          Routine that will be called when a thread allocated an object.
 Thread thread()
          The thread this budget is assigned to
 long usedBudget()
          Get the used budget of a given thread
 
Methods inherited from class com.aicas.jamaica.lang.AllocationHandler
removeAllocationHandler, setAllocationHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryBudget

public MemoryBudget(Thread t,
                    long budget)
Add a budget for a given thread

Parameters:
t - the thread
budget - the budget in bytes
Method Detail

budget

public long budget()
Get the budget of a given thread

Returns:
the budget in bytes

usedBudget

public long usedBudget()
Get the used budget of a given thread

Returns:
the used budget in bytes

thread

public Thread thread()
The thread this budget is assigned to

Returns:
the thread, never null

allocationPermitted

public boolean allocationPermitted()
Is allocation within thread() still permitted?

Returns:
true if allocation is still permitted, i.e., there was no budget overrun yet.

handle

public final Object handle(Object o)
Routine that will be called when a thread allocated an object.

Specified by:
handle in class AllocationHandler
Parameters:
o - the allocated object
Returns:
the allocated object o or null if the allocation should fail.

forbidAllocation

public void forbidAllocation()
Forbid allocation for this thread. This can be used during a call to budgetEmpty to disallow allocation for thread().


allowAllocation

public void allowAllocation()
Permit allocation for this thread. This undoes the call to forbidAllocation().


budgetEmpty

public abstract void budgetEmpty()
Handler routine that is called when the budget of a certain thread is exhausted.


destroy

public void destroy()
Remove this memory budget from thread(). All MemoryBudget instances must to be destroyed to ensure that the associated resources will be reclaimed.


aicas logoJamaica 6.1 release 1

aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2012 aicas GmbH. All Rights Reserved.