uk.ac.leeds.ccg.andyt.generic.memory
Class Generic_OutOfMemoryErrorHandler

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.generic.memory.Generic_OutOfMemoryErrorHandler
All Implemented Interfaces:
java.io.Serializable

public abstract class Generic_OutOfMemoryErrorHandler
extends java.lang.Object
implements java.io.Serializable

A class to be extended so as to handle OutOfMemoryErrors.

See Also:
Serialized Form

Field Summary
 Generic_TestMemory _Generic_TestMemory
           
 boolean _HandleOutOfMemoryError_boolean
           
protected  int[] _MemoryReserve
          Reserve memory that can be set to null and garbage collected so as to handle OutOfMemoryErrors.
static int Default_Memory_Threshold
           
static boolean HandleOutOfMemoryErrorFalse
          For ease of search and replace coding.
static boolean HandleOutOfMemoryErrorTrue
          For ease of search and replace coding.
 
Constructor Summary
Generic_OutOfMemoryErrorHandler()
           
 
Method Summary
 void clear_MemoryReserve()
          Clears _MemoryReserve by setting it to null and calling the garbage collector.
protected  Generic_TestMemory get_Generic_TestMemory()
          For initialising and returning _Generic_TestMemory.
 int[] get_MemoryReserve()
           
 java.lang.Runtime getRuntime()
          May initialise _Generic_TestMemory and _Generic_TestMemory._Runtime.
protected  long getTotalFreeMemory()
           return get_Generic_TestMemory().getTotalFreeMemory();
 long getTotalFreeMemory(boolean handleOutOfMemoryError)
          For returning the total free memory available to the JVM.
protected  void init_MemoryReserve()
          Initialises _MemoryReserve as an int[] of size Default_Memory_Threshold.
 void init_MemoryReserve(boolean handleOutOfMemoryError)
          Initialises _MemoryReserve.
protected  void init_MemoryReserve(int size)
          Initialises _MemoryReserve as an array of size given by size.
 java.io.File initFile(java.io.File a_File, java.lang.String a_String, boolean handleOutOfMemoryError)
          For initialising a File from File _File and String _String.
 java.io.File initFile(java.lang.String a_String, boolean handleOutOfMemoryError)
          For initialising a File from String _String.
 java.io.File initFileDirectory(java.io.File _ParentFile, java.lang.String _String, boolean handleOutOfMemoryError)
          For initialising a File Directory from File _ParentFile and String _String.
 java.lang.String initString(int length, boolean handleOutOfMemoryError)
          For initialising a String of length length.
 java.lang.String initString(java.lang.String a_String, java.lang.String b_String, boolean handleOutOfMemoryError)
           
 java.lang.String println(java.lang.String a_String, java.lang.String a_StringToDuplicateAndReturn, boolean handleOutOfMemoryError)
           
 void set_MemoryReserve(int[] a_MemoryReserve)
          this._MemoryReserve = a_MemoryReserve;
 double sin(double value, boolean handleOutOfMemoryError)
           
abstract  boolean swapToFile_DataAny()
           
abstract  boolean swapToFile_DataAny(boolean handleOutOfMemoryError)
           
 java.lang.String toString(double a_double, boolean handleOutOfMemoryError)
           
protected abstract  boolean tryToEnsureThereIsEnoughMemoryToContinue()
          For ensuring robustness in handling OutOfMemoryError and to try to prevent them being thrown.
abstract  boolean tryToEnsureThereIsEnoughMemoryToContinue(boolean handleOutOfMemoryError)
          A method to ensure there is enough memory to continue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_Generic_TestMemory

public transient Generic_TestMemory _Generic_TestMemory

_HandleOutOfMemoryError_boolean

public boolean _HandleOutOfMemoryError_boolean

Default_Memory_Threshold

public static final int Default_Memory_Threshold
See Also:
Constant Field Values

HandleOutOfMemoryErrorFalse

public static final boolean HandleOutOfMemoryErrorFalse
For ease of search and replace coding.

See Also:
Constant Field Values

HandleOutOfMemoryErrorTrue

public static final boolean HandleOutOfMemoryErrorTrue
For ease of search and replace coding.

See Also:
Constant Field Values

_MemoryReserve

protected transient int[] _MemoryReserve
Reserve memory that can be set to null and garbage collected so as to handle OutOfMemoryErrors.

Constructor Detail

Generic_OutOfMemoryErrorHandler

public Generic_OutOfMemoryErrorHandler()
Method Detail

swapToFile_DataAny

public abstract boolean swapToFile_DataAny()

swapToFile_DataAny

public abstract boolean swapToFile_DataAny(boolean handleOutOfMemoryError)

getRuntime

public java.lang.Runtime getRuntime()
May initialise _Generic_TestMemory and _Generic_TestMemory._Runtime.

Returns:
_Generic_TestMemory._Runtime

init_MemoryReserve

protected final void init_MemoryReserve(int size)
Initialises _MemoryReserve as an array of size given by size.

Parameters:
size - Size that _MemoryReserve is initialised to.

get_MemoryReserve

public int[] get_MemoryReserve()
Returns:
this._MemoryReserve.

set_MemoryReserve

public void set_MemoryReserve(int[] a_MemoryReserve)
this._MemoryReserve = a_MemoryReserve;


init_MemoryReserve

public void init_MemoryReserve(boolean handleOutOfMemoryError)
Initialises _MemoryReserve.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught, swap operations are initiated, then the method is re-called. If false then OutOfMemoryErrors are caught and thrown.

init_MemoryReserve

protected void init_MemoryReserve()
Initialises _MemoryReserve as an int[] of size Default_Memory_Threshold. _MemoryReserve is for use when an OutOfMemoryError is handled. This involves clear_MemoryReserve() which sets _MemoryReserve to null providing memory for swapping operations that move data from one location (memory/RAM) to another location (disk). The swapping may involve accounting the amount and details of the data swapped and the locations and returning this information.


clear_MemoryReserve

public final void clear_MemoryReserve()
Clears _MemoryReserve by setting it to null and calling the garbage collector. After this method is executed then no further method calls will handle OutOfMemoryError until _MemoryReserve is initialised again. Generally, the assumption is that _MemoryReserve is not null before this is called.


tryToEnsureThereIsEnoughMemoryToContinue

protected abstract boolean tryToEnsureThereIsEnoughMemoryToContinue()
For ensuring robustness in handling OutOfMemoryError and to try to prevent them being thrown. If this method returns false then it may be best to write all data to persistent memory and restart the JVM with a increased heap size before attempting to continue.

Returns:
true if there is enough memory to continue and false otherwise.

get_Generic_TestMemory

protected Generic_TestMemory get_Generic_TestMemory()
For initialising and returning _Generic_TestMemory.

Returns:
_Generic_TestMemory (after default construction if null)

tryToEnsureThereIsEnoughMemoryToContinue

public abstract boolean tryToEnsureThereIsEnoughMemoryToContinue(boolean handleOutOfMemoryError)
A method to ensure there is enough memory to continue.

Parameters:
handleOutOfMemoryError -
Returns:
true if ensured there is enough memory to continue

getTotalFreeMemory

protected long getTotalFreeMemory()
return get_Generic_TestMemory().getTotalFreeMemory();


getTotalFreeMemory

public long getTotalFreeMemory(boolean handleOutOfMemoryError)
For returning the total free memory available to the JVM. This method will try to swap data if handleOutOfMemory is true, but if it finds no data to swap will throw an OutOfMemoryError.


initString

public java.lang.String initString(int length,
                                   boolean handleOutOfMemoryError)
For initialising a String of length length.


initString

public java.lang.String initString(java.lang.String a_String,
                                   java.lang.String b_String,
                                   boolean handleOutOfMemoryError)
Returns:
String which is a_String appended to the end of b_String

initFile

public java.io.File initFile(java.lang.String a_String,
                             boolean handleOutOfMemoryError)
                      throws java.io.IOException
For initialising a File from String _String.

Throws:
java.io.IOException

initFile

public java.io.File initFile(java.io.File a_File,
                             java.lang.String a_String,
                             boolean handleOutOfMemoryError)
                      throws java.io.IOException
For initialising a File from File _File and String _String.

Throws:
java.io.IOException

initFileDirectory

public java.io.File initFileDirectory(java.io.File _ParentFile,
                                      java.lang.String _String,
                                      boolean handleOutOfMemoryError)
                               throws java.io.IOException
For initialising a File Directory from File _ParentFile and String _String.

Throws:
java.io.IOException

println

public java.lang.String println(java.lang.String a_String,
                                java.lang.String a_StringToDuplicateAndReturn,
                                boolean handleOutOfMemoryError)

sin

public double sin(double value,
                  boolean handleOutOfMemoryError)

toString

public java.lang.String toString(double a_double,
                                 boolean handleOutOfMemoryError)