|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--uk.org.ogsadai.common.MemoryUtilities
Utilities for managing, checking and logging memory usage.
| Field Summary | |
private static java.lang.String |
COPYRIGHT_NOTICE
|
private static DAILogger |
LOG
|
private static long |
MAX_MEMORY
|
private static java.lang.Runtime |
RUNTIME
|
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(byte[] bytes,
DAILogger log)
Check that the copying of a byte array within the JVM will not go over the threshold memory ratio set for this system. |
static void |
checkMemory(java.io.ByteArrayOutputStream stream,
DAILogger log)
Check that the convertion of a ByteArrayOutputStream to a byte array within the
JVM will not go over the threshold memory ratio set for this
system. |
static void |
checkMemory(int numberOfBytesToAdd,
DAILogger log)
Check 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.StringBuffer buffer,
DAILogger log)
Check that the conversion of a StringBuffer to a
String within the JVM will not
go over the threshold memory ratio set for this system. |
static void |
checkMemory(java.lang.String stringToCopy,
DAILogger log)
Check that the copying of a String within the JVM
will not go over the threshold memory ratio set for this system. |
private static long |
getCurrentlyUsedMemory()
Get current memory in use. |
private static double |
getCurrentRatio(int numberOfBytesToAdd)
Get ratio of current memory in use + number of requested bytes to total memory. |
static void |
logMemoryUsage(DAILogger log)
Logs the current state of the JVM memory at DEBUG level to this object's own log and in the logger provided. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final java.lang.String COPYRIGHT_NOTICE
private static final DAILogger LOG
private static final java.lang.Runtime RUNTIME
private static final long MAX_MEMORY
public static final double THRESHOLD
java.lang.OutOfMemoryError).
| Constructor Detail |
public MemoryUtilities()
| Method Detail |
public static void checkMemory(java.lang.String stringToCopy,
DAILogger log)
throws OutOfMemoryException
String within the JVM
will not go over the threshold memory ratio set for this system.
stringToCopy - The string to be copied.log - Destination of memory usage info.
OutOfMemoryException - if the ratio
of used memory would be exceeded by allocating the number of
bytes specified.
public static void checkMemory(byte[] bytes,
DAILogger log)
throws OutOfMemoryException
bytes - The byte array to be copied.log - Destination of memory usage info.
OutOfMemoryException - if the ratio
of used memory would be exceeded by allocating the number of
bytes specified.
public static void checkMemory(java.lang.StringBuffer buffer,
DAILogger log)
throws OutOfMemoryException
StringBuffer to a
String within the JVM will not
go over the threshold memory ratio set for this system.
buffer - The java.lang.StringBuffer to be converted.log - Destination of memory usage info.
OutOfMemoryException - if the ratio
of used memory would be exceeded by allocating the number of
bytes specified.
public static void checkMemory(java.io.ByteArrayOutputStream stream,
DAILogger log)
throws OutOfMemoryException
ByteArrayOutputStream to a byte array within the
JVM will not go over the threshold memory ratio set for this
system.
stream - The java.io.ByteArrayOutputStream to be converted.log - Destination of memory usage info.
OutOfMemoryException - if the ratio
of used memory would be exceeded by allocating the number of
bytes specified.
public static void checkMemory(int numberOfBytesToAdd,
DAILogger log)
throws OutOfMemoryException
numberOfBytesToAdd - Number of bytes of memory to be tested prior to allocationlog - Destination of memory usage info.
OutOfMemoryException - if the ratio
of used memory would be exceeded by allocating the number of
bytes specified.private static double getCurrentRatio(int numberOfBytesToAdd)
numberOfBytesToAdd - Requested number of bytes.
private static long getCurrentlyUsedMemory()
public static void logMemoryUsage(DAILogger log)
For analysis purposes, the format of the log message is as
follows:
[NUMBER] of [NUMBER] bytes in use. [NUMBER]%
log - Destination for log messages.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||