uk.ac.starlink.table
Class StoragePolicy

java.lang.Object
  |
  +--uk.ac.starlink.table.StoragePolicy

public abstract class StoragePolicy
extends Object

Defines storage methods for bulk data. If the table handling system needs to cache bulk data somewhere, for instance because it is reading a table from a stream but needs to make it available for random access, it will use a StoragePolicy object to work out how to do it.

Code which has no preferences about how to store data can obtain an instance of this class using the getDefaultPolicy() method. The initial value of this may be selected by setting the system property named by the string PREF_PROPERTY ("startable.storage"); currently recognised values are the strings "disk", "memory" and "discard". You may also use the name of a class which extends StoragePolicy and has a no-arg constructor, in which case one of these will be instantiated and used.

Code which wants to store data in a particular way may use one of the predefined policies PREFER_MEMORY, PREFER_DISK or DISCARD, or may implement their own policy by extending this class. If you want more control, you can always create instances of the public RowStore implementations directly.


Field Summary
static StoragePolicy DISCARD
          Storage policy which just throws away the rows it is given.
static String PREF_PROPERTY
          Name of the system property which can be set to indicate the initial setting of the default storage policy.
static StoragePolicy PREFER_DISK
          Storage policy which will normally store table data in a scratch disk file.
static StoragePolicy PREFER_MEMORY
          Storage policy which will always store table data in memory.
 
Constructor Summary
StoragePolicy()
           
 
Method Summary
static StoragePolicy getDefaultPolicy()
          Returns the default storage policy for this JVM.
abstract  RowStore makeConfiguredRowStore(StarTable meta)
          Creates a new RowStore and primes it by calling TableSink.acceptMetadata(uk.ac.starlink.table.StarTable) on it.
abstract  RowStore makeRowStore()
          Returns a new RowStore object which can be used to provide a destination for random-access table storage.
 StarTable randomTable(StarTable table)
          Returns a table based on a given table and guaranteed to have random access.
static void setDefaultPolicy(StoragePolicy policy)
          Sets the default storage policy used for this JVM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREF_PROPERTY

public static final String PREF_PROPERTY
Name of the system property which can be set to indicate the initial setting of the default storage policy. Currently recognised values are "disk", "memory" and "discard";

See Also:
Constant Field Values

PREFER_MEMORY

public static final StoragePolicy PREFER_MEMORY
Storage policy which will always store table data in memory.


PREFER_DISK

public static final StoragePolicy PREFER_DISK
Storage policy which will normally store table data in a scratch disk file. If it's impossible for some reason (I/O error, security restrictions) then it will fall back to using memory. It might also use memory if it thinks it's got a small table to deal with. Temporary disk files are written in the default temporary directory, which is the value of the java.io.tmpdir system property. These files will be deleted when the JVM exits, if not before. They will probably be deleted around the time they are no longer needed (when the RowStore in question is garbage collected), though this cannot be guaranteed since it depends on the details of the JVM's GC implementation.


DISCARD

public static final StoragePolicy DISCARD
Storage policy which just throws away the rows it is given. Tables obtained from its row stores will have no rows. Obviously, this has rather limited application.

Constructor Detail

StoragePolicy

public StoragePolicy()
Method Detail

getDefaultPolicy

public static StoragePolicy getDefaultPolicy()
Returns the default storage policy for this JVM.

Returns:
default storage policy

setDefaultPolicy

public static void setDefaultPolicy(StoragePolicy policy)
Sets the default storage policy used for this JVM.

Parameters:
policy - new default storage policy

makeRowStore

public abstract RowStore makeRowStore()
Returns a new RowStore object which can be used to provide a destination for random-access table storage.

Returns:
a RowStore object

makeConfiguredRowStore

public abstract RowStore makeConfiguredRowStore(StarTable meta)
Creates a new RowStore and primes it by calling TableSink.acceptMetadata(uk.ac.starlink.table.StarTable) on it.

Parameters:
meta - template giving the metadata which describes the rows that will have to be stored
Returns:
a RowStore on which acceptMetadata(meta) has been called

randomTable

public StarTable randomTable(StarTable table)
                      throws IOException
Returns a table based on a given table and guaranteed to have random access. If the original table table has random access then it is returned, otherwise a new random access table is built using its data.

Parameters:
table - original table
Returns:
a table with the same data as table and with isRandom()==true
IOException

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.