org.peace_tools.data
Class DataStore

java.lang.Object
  extended by org.peace_tools.data.DataStore

public class DataStore
extends java.lang.Object

A helper class to load and maintain data files. This class is a helper class that is used to load and maintain information about ESTs, MSTs, and Cluster data files. This class maintains references to currently loaded entries so that various data files can be shared and reused. The information is maintained in a weak hash map. Therefore, if an entry is not used (at least for some time) then it will be automatically garbage collected and needs to be reloaded.

Note: This class is not meant to be directly instantiated to preserve singleton property. Use the static get() method to obtain a reference to the globally unique instance of this class.


Field Summary
private  java.util.WeakHashMap<java.lang.String,java.lang.Object> cache
          A weak hash map that serves as a cache to hold MST, EST, and cluster data file entries in it.
private static DataStore dataStore
          The globally unique singleton instance of this class that is shared by all the other classes that require data files to be loaded.
private static java.lang.String LOW_MEMORY_MSG
          Message to be displayed to the user to indicate that there is a low memory situation when loading a file.
private static java.lang.String MEM_USAGE
          Memory statistics to be displayed to the user after formatting (to fill in the necessary information).
private static java.lang.String MEM_USAGE_LOG
          A simple log message that is cut just before the memory checks are performed by the memoryCheck() method in this class.
 
Constructor Summary
private DataStore()
          The constructor.
 
Method Summary
static DataStore get()
          Obtain reference to the globally unique singleton instance.
 ClusterFile getClusterData(java.lang.String fileName, java.awt.Component parent)
          Method to load/get a given cluster file.
 ESTList getFASTA(java.lang.String fileName, java.awt.Component parent)
          Method to load/get a given FASTA file.
 MST getMSTData(java.lang.String fileName, java.awt.Component parent)
          Method to load/get a given cluster file.
 void memoryCheck(java.io.File fileToBeLoaded, java.awt.Component parent)
          Helper method to ensure there is sufficient memory to load data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private final java.util.WeakHashMap<java.lang.String,java.lang.Object> cache
A weak hash map that serves as a cache to hold MST, EST, and cluster data file entries in it. Entries are added to this cache on demand, whenever new files need to be loaded.


LOW_MEMORY_MSG

private static final java.lang.String LOW_MEMORY_MSG
Message to be displayed to the user to indicate that there is a low memory situation when loading a file. This message is formatted (to fill in missing information) by the memoryCheck() method.

See Also:
Constant Field Values

MEM_USAGE

private static final java.lang.String MEM_USAGE
Memory statistics to be displayed to the user after formatting (to fill in the necessary information). This string is used in the memoryCheck() method.

See Also:
Constant Field Values

MEM_USAGE_LOG

private static final java.lang.String MEM_USAGE_LOG
A simple log message that is cut just before the memory checks are performed by the memoryCheck() method in this class. This string is filled-in and logged in the programmer log.

See Also:
Constant Field Values

dataStore

private static final DataStore dataStore
The globally unique singleton instance of this class that is shared by all the other classes that require data files to be loaded.

Constructor Detail

DataStore

private DataStore()
The constructor. This class is not meant to be instantiated. Therefore the constructor is private. Use the get() method to obtain a reference to the global instance of this class.

Method Detail

get

public static DataStore get()
Obtain reference to the globally unique singleton instance.

Returns:
The globally unique singleton instance of the data store.

memoryCheck

public void memoryCheck(java.io.File fileToBeLoaded,
                        java.awt.Component parent)
                 throws LowMemoryException
Helper method to ensure there is sufficient memory to load data. This is a helper method that is called just before data files are loaded to ensure that sufficient memory is available to load large files. If not, an warning message is displayed to the user along with information on how to increase memory.

Parameters:
fileToBeLoaded - The file that is going to be loaded into memory.
parent - The parent component based on which any warning dialog boxes are to be displayed.
Throws:
This - method throws a LowMemoryException if the memory is low and the user chooses to cancel a file loading operation.
LowMemoryException

getFASTA

public ESTList getFASTA(java.lang.String fileName,
                        java.awt.Component parent)
                 throws java.lang.Exception
Method to load/get a given FASTA file. This method can be used to obtain the ESTs loaded from a given FASTA file. The full path to the FASTA file must be supplied as the parameter to this method. If the specified file is not found in cache, then this method loads the file from disk, places the entry in cache, and returns a reference to the ESTList.

Parameters:
fileName - The FASTA file containing ESTs to be loaded.
parent - If this parameter is not null then this method displays a progress monitor.
Returns:
This method returns the list of ESTs from the given file.
Throws:
java.lang.Exception - This method throws exceptions if the specified file could not be loaded due to various reasons.

getClusterData

public ClusterFile getClusterData(java.lang.String fileName,
                                  java.awt.Component parent)
                           throws java.lang.Exception
Method to load/get a given cluster file. This method can be used to obtain the cluster data loaded from a given cluster file. The full path to the data file must be supplied as the parameter to this method. If the specified file is not found in cache, then this method loads the file from disk, places the entry in cache, and returns a reference to the cluster information.

Parameters:
fileName - The cluster file containing the data to be loaded.
parent - If this parameter is not null then this method displays a progress monitor.
Returns:
This method returns the cluster data from the given file.
Throws:
java.lang.Exception - This method throws exceptions if the specified file could not be loaded due to various reasons.

getMSTData

public MST getMSTData(java.lang.String fileName,
                      java.awt.Component parent)
               throws java.lang.Exception
Method to load/get a given cluster file. This method can be used to obtain the cluster data loaded from a given cluster file. The full path to the data file must be supplied as the parameter to this method. If the specified file is not found in cache, then this method loads the file from disk, places the entry in cache, and returns a reference to the cluster information.

Parameters:
fileName - The cluster file containing the data to be loaded.
parent - If this parameter is not null then this method displays a progress monitor.
Returns:
This method returns the cluster data from the given file.
Throws:
java.lang.Exception - This method throws exceptions if the specified file could not be loaded due to various reasons.