appia.memoryManager
Class MemoryManager

java.lang.Object
  |
  +--appia.memoryManager.MemoryManager

public class MemoryManager
extends java.lang.Object

This class is used by the events and a Channel to stabilish a maximum number of bytes used by messages that a channel can hold.

See Also:
Channel, Message

Constructor Summary
MemoryManager(java.lang.String id, int size, int threshold)
          Constructor of the class.
 
Method Summary
 boolean aboveThreshold()
          Verifies if the channel is above the water mark specified by the user in the contructor.
 void free(int nBytes)
          Free an amount of memory in the memory manager.
 int getMaxSize()
          Gets the actual size of the memory (in bytes)
 java.lang.String getMemoryManagerID()
          Gets Memory Manager ID.
 int getThreshold()
          Gets the value of the specified threshold.
 boolean malloc(int nBytes)
          Reserve an amount of memory.
 void setMaxSize(int newSize)
          Sets the Maximun size of memory that the channel of this memory manager can hold.
 void setThreshold(int newThreshold)
          Sets the threshold for this memory manager.
 int used()
          Gets the amount of memory (in bytes) occupied in the memory manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryManager

public MemoryManager(java.lang.String id,
                     int size,
                     int threshold)
Constructor of the class.

Parameters:
id - Identifier of the memory manager.
size - Max number of bytes. It must be a positive integer.
threshold - Tolerance margin of the Memory Manager (in bytes).
Method Detail

aboveThreshold

public boolean aboveThreshold()
Verifies if the channel is above the water mark specified by the user in the contructor.

Returns:
true if the amount of memory reached the threshold.

getThreshold

public int getThreshold()
Gets the value of the specified threshold.

Returns:
the value of the specified threshold.

setThreshold

public void setThreshold(int newThreshold)
Sets the threshold for this memory manager. newThreshold must be between 0 and getMaxSize()

Parameters:
newThreshold - the new threshold.

getMemoryManagerID

public java.lang.String getMemoryManagerID()
Gets Memory Manager ID.

Returns:
the Memory Manager ID.

setMaxSize

public void setMaxSize(int newSize)
                throws AppiaWrongSizeException
Sets the Maximun size of memory that the channel of this memory manager can hold. If the new specified value is lower than 0 or lower than the current used size, throws a AppiaWrongSizeException.

Parameters:
newSize - the new size of the memory (in bytes).
AppiaWrongSizeException

getMaxSize

public int getMaxSize()
Gets the actual size of the memory (in bytes)


used

public int used()
Gets the amount of memory (in bytes) occupied in the memory manager.


malloc

public boolean malloc(int nBytes)
Reserve an amount of memory.

Returns:
True on sucess, False if the memory manager do not have this amount of memory.

free

public void free(int nBytes)
Free an amount of memory in the memory manager.