uk.ac.leeds.ccg.andyt.projects.genesis.utilities
Class ErrorHandler

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.projects.genesis.utilities.ErrorHandler
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
GenerateSociety

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

An abstract class to be extended by classes that are required to handle runtime errors such as java.lang.OutOfMemroyError.

See Also:
Serialized Form

Constructor Summary
ErrorHandler()
           
 
Method Summary
 void clearMemoryReserve()
          Clears memoryReserve by setting it to null and calling the garbage collector.
 java.io.File getDirectory()
           
protected  int[] getMemoryReserve()
           
protected  java.util.HashMap getNumberOfCachesSwappedAsFilesHashMap()
           
 void initMemoryReserve()
          Initialises memoryReserve as an array of size 3000000.
 void initMemoryReserve(int size)
          Initialises this.memoryReserve as an int[] of length size.
protected  java.lang.Object loadObject(java.io.File aFile)
          Loads an Object from aFile File.
protected  java.lang.Object loadObject(java.io.ObjectInputStream aObjectInputStream)
          Loads an Object from aObjectInputStream ObjectInputStream.
protected  void setDirectory(java.io.File directory)
          Sets this.directory to directory.
protected  void setMemoryReserve(int[] memoryReserve)
          Sets this.memoryReserve to memoryReserve.
protected  void setNumberOfCachesSwappedAsFilesHashMap(java.util.HashMap numberOfCachesSwappedAsFilesHashMap)
          Sets this.numberOfCachesSwappedAsFilesHashMap to numberOfCachesSwappedAsFilesHashMap.
protected  java.io.File swapToFile(java.util.HashMap aHashMap)
          If aHashMap.isEmpty() this does nothing and returns null.
protected  java.io.File swapToFile(java.util.HashSet _HashSet)
          If aHashSetSerializable.isEmpty() this does nothing and returns null.
protected  java.io.File writeToFile()
          A method to write this instance to a File located in the directory returned by getDirectory().
 java.io.File writeToFile(boolean handleOutOfMemoryError)
          A method to write this instance to Files located in this.directory.
protected  void writeToFile(java.lang.Object objectToWrite, java.io.File aFileToWriteTo)
          A method to write this instance to a File located in the directory returned by getDirectory().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ErrorHandler

public ErrorHandler()
Method Detail

initMemoryReserve

public final void initMemoryReserve(int size)
Initialises this.memoryReserve as an int[] of length size.

Parameters:
size - The length that this.memoryReserve is initialised as.

initMemoryReserve

public final void initMemoryReserve()
Initialises memoryReserve as an array of size 3000000. Enough memory is needed for swapping data to this.directory


clearMemoryReserve

public final void clearMemoryReserve()
Clears memoryReserve by setting it to null and calling the garbage collector.


swapToFile

protected java.io.File swapToFile(java.util.HashSet _HashSet)
If aHashSetSerializable.isEmpty() this does nothing and returns null. Otherwise aHashSetSerializable is swapped to a File which is returned.


swapToFile

protected java.io.File swapToFile(java.util.HashMap aHashMap)
If aHashMap.isEmpty() this does nothing and returns null. Otherwise aHashMap is swapped to a File which is returned.


writeToFile

public final java.io.File writeToFile(boolean handleOutOfMemoryError)
                               throws java.io.IOException
A method to write this instance to Files located in this.directory.

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.
Throws:
java.io.IOException

writeToFile

protected java.io.File writeToFile()
                            throws java.io.IOException
A method to write this instance to a File located in the directory returned by getDirectory().

Throws:
java.io.IOException

writeToFile

protected void writeToFile(java.lang.Object objectToWrite,
                           java.io.File aFileToWriteTo)
                    throws java.io.IOException
A method to write this instance to a File located in the directory returned by getDirectory().

Parameters:
objectToWrite - The object to be written
Throws:
java.io.IOException

loadObject

protected final java.lang.Object loadObject(java.io.File aFile)
Loads an Object from aFile File.

Parameters:
aFile - The File from which the ObjectReturns:
The loaded Objectnull

loadObject

protected final java.lang.Object loadObject(java.io.ObjectInputStream aObjectInputStream)
Loads an Object from aObjectInputStream ObjectInputStream.

Parameters:
aObjectInputStream - The ObjectInputStream from which the ObjectReturns:
The loaded Objectnull

getDirectory

public final java.io.File getDirectory()
Returns:
this.directory

setDirectory

protected final void setDirectory(java.io.File directory)
Sets this.directory to directory. N.B. No checks are done on directory to ensure it is viable for use.


getMemoryReserve

protected final int[] getMemoryReserve()
Returns:
this.memoryReserve

setMemoryReserve

protected final void setMemoryReserve(int[] memoryReserve)
Sets this.memoryReserve to memoryReserve.


getNumberOfCachesSwappedAsFilesHashMap

protected final java.util.HashMap getNumberOfCachesSwappedAsFilesHashMap()
Returns:
this.numberOfCachesSwappedAsFilesHashMap

setNumberOfCachesSwappedAsFilesHashMap

protected final void setNumberOfCachesSwappedAsFilesHashMap(java.util.HashMap numberOfCachesSwappedAsFilesHashMap)
Sets this.numberOfCachesSwappedAsFilesHashMap to numberOfCachesSwappedAsFilesHashMap.