uk.org.ogsadai.common
Class MemoryUtilities

java.lang.Object
  |
  +--uk.org.ogsadai.common.MemoryUtilities

public class MemoryUtilities
extends java.lang.Object

OGSA-DAI class/interface uk.org.dai.common.MemoryUtilities Provides utilities for managing, checking and logging memory usage.


Field Summary
static double THRESHOLD
          Threshold ratio for how full the JVM memory must be before an exception is thrown (to avoid a java.lang.OutOfMemoryError).
 
Constructor Summary
MemoryUtilities()
           
 
Method Summary
static void checkMemory(int numberOfBytesToAdd, int messageNumber, org.apache.log4j.Logger logger)
          Checks that the allocation of an extra number of bytes within the JVM will not go over the threshold ratio set for this system.
static void checkMemory(int numberOfBytesToAdd, org.apache.log4j.Logger logger)
          Checks that the allocation of an extra number of bytes within the JVM will not go over the threshold ratio set for this system.
static void checkMemory(java.lang.String stringToCopy, int messageNumber, org.apache.log4j.Logger logger)
          Checks that the copying of a String within the JVM will not go over the threshold memory ratio set for this system.
static void checkMemory(java.lang.String stringToCopy, org.apache.log4j.Logger logger)
          Checks that the copying of a String within the JVM will not go over the threshold memory ratio set for this system.
static void logMemoryUsage(org.apache.log4j.Logger log)
          Logs the current state of the JVM memory at DEBUG level to the MemoryUtilities Logger and the Logger provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THRESHOLD

public static final double THRESHOLD
Threshold ratio for how full the JVM memory must be before an exception is thrown (to avoid a java.lang.OutOfMemoryError).

See Also:
Constant Field Values
Constructor Detail

MemoryUtilities

public MemoryUtilities()
Method Detail

checkMemory

public static void checkMemory(int numberOfBytesToAdd,
                               org.apache.log4j.Logger logger)
                        throws CommonSystemException
Checks that the allocation of an extra number of bytes within the JVM will not go over the threshold ratio set for this system. If the threshold ratio would be exceeded by the allocation of this amount of memory, a CommonSystemException is thrown. The Exception will contain the default message.

Parameters:
numberOfBytesToAdd - The number of bytes of memory to be tested prior to allocation
Throws:
CommonSystemException - if the ratio of used memory would be exceeded by allocating the number of bytes specified

checkMemory

public static void checkMemory(java.lang.String stringToCopy,
                               org.apache.log4j.Logger logger)
                        throws CommonSystemException
Checks that the copying of a String within the JVM will not go over the threshold memory ratio set for this system. If the threshold ratio would be exceeded by the allocation of this amount of memory, a CommonSystemException is thrown. The Exception will contain the default message.

Parameters:
stringToCopy - The string to be copied
Throws:
CommonSystemException - if the ratio of used memory would be exceeded by allocating the number of bytes specified

checkMemory

public static void checkMemory(java.lang.String stringToCopy,
                               int messageNumber,
                               org.apache.log4j.Logger logger)
                        throws CommonSystemException
Checks that the copying of a String within the JVM will not go over the threshold memory ratio set for this system. If the threshold ratio would be exceeded by the allocation of this amount of memory, a CommonSystemException is thrown. The Exception will contain the message specified by the messageNumber parameter.

Parameters:
stringToCopy - The string to be copied
messageNumber - The message identifier to be used if an Exception is thrown
Throws:
CommonSystemException - if the ratio of used memory would be exceeded by allocating the number of bytes specified

checkMemory

public static void checkMemory(int numberOfBytesToAdd,
                               int messageNumber,
                               org.apache.log4j.Logger logger)
                        throws CommonSystemException
Checks that the allocation of an extra number of bytes within the JVM will not go over the threshold ratio set for this system. If the threshold ratio would be exceeded by the allocation of this amount of memory, a CommonSystemException is thrown. The Exception will contain the message specified by the messageNumber parameter.

Parameters:
numberOfBytesToAdd - The number of bytes of memory to be tested prior to allocation
messageNumber - The message identifier to be used if an Exception is thrown
Throws:
CommonSystemException - if the ratio of used memory would be exceeded by allocating the number of bytes specified

logMemoryUsage

public static void logMemoryUsage(org.apache.log4j.Logger log)
Logs the current state of the JVM memory at DEBUG level to the MemoryUtilities Logger and the Logger provided. For analysis purposes, the format of the log message is as follows:
[NUMBER] of [NUMBER] bytes in use. [NUMBER]%

Parameters:
log - Logger to log to (to track where we are in the process).