Class StoragePolicy
- Direct Known Subclasses:
ByteStoreStoragePolicy
,MonitorStoragePolicy
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").
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.
The default, if not otherwise set, corresponds to "adaptive
".
Code which wants to store data in a particular way may use one of
the predefined policies ADAPTIVE
, PREFER_MEMORY
,
PREFER_DISK
SIDEWAYS
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.
- Author:
- Mark Taylor (Starlink)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StoragePolicy
Storage policy which will store small amounts of data in an array in memory, and larger amounts in a scratch disk file.static final StoragePolicy
Storage policy which just throws away the rows it is given.static final String
Name of the system property which can be set to indicate the initial setting of the default storage policy ("startable.storage").static final StoragePolicy
Storage policy which will normally store table data in a scratch disk file.static final StoragePolicy
Storage policy which will always store table data in memory.static final StoragePolicy
Storage policy which will normally store table data in scratch disk files in such a way that cells from the same column are contiguous on disk. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a random-access deep copy of the given table.static StoragePolicy
Returns the default storage policy for this JVM.abstract ByteStore
Returns a new ByteStore object which can be used to provide a destination for general purpose data storage.abstract RowStore
Creates a new RowStore and primes it by callingTableSink.acceptMetadata(uk.ac.starlink.table.StarTable)
on it.abstract RowStore
Returns a newRowStore
object which can be used to provide a destination for random-access table storage.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.
-
Field Details
-
PREF_PROPERTY
Name of the system property which can be set to indicate the initial setting of the default storage policy ("startable.storage"). Currently recognised values are "adaptive", "memory", "disk", "sideways", and "discard". Alternatively, the classname of a StoragePolicy implementation with a no-arg constructor may be supplied.- See Also:
-
PREFER_MEMORY
Storage policy which will always store table data in memory. Table cells are stored as objects, which will be fast to write, and can cope with any object type, but may be expensive on memory. -
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 thejava.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. -
SIDEWAYS
Storage policy which will normally store table data in scratch disk files in such a way that cells from the same column are contiguous on disk. This may be more efficient for certain access patterns for tables which are very large and, in particular, very wide. It's generally more expensive on system resources thanPREFER_DISK
however, so it is only the best choice in rather specialised circumstances. If it's impossible for some reason to store the data in this way, or if the number of cells requested is small, it will fall back to using memory storage. Temporary disk files (at least one per column) are written in the default temporary directory, which is the value of thejava.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
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. -
ADAPTIVE
Storage policy which will store small amounts of data in an array in memory, and larger amounts in a scratch disk file. Temporary disk files are written in the default temporary directory, which is the value of thejava.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.
-
-
Constructor Details
-
StoragePolicy
public StoragePolicy()
-
-
Method Details
-
getDefaultPolicy
Returns the default storage policy for this JVM.- Returns:
- default storage policy
-
setDefaultPolicy
Sets the default storage policy used for this JVM.- Parameters:
policy
- new default storage policy
-
makeByteStore
Returns a new ByteStore object which can be used to provide a destination for general purpose data storage.- Returns:
- new byte store
-
makeRowStore
Returns a newRowStore
object which can be used to provide a destination for random-access table storage.- Returns:
- a RowStore object
-
makeConfiguredRowStore
Creates a new RowStore and primes it by callingTableSink.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
Returns a table based on a given table and guaranteed to have random access. If the original tabletable
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 withisRandom()==true
- Throws:
IOException
-
copyTable
Returns a random-access deep copy of the given table. This utility method is likerandomTable(uk.ac.starlink.table.StarTable)
except that a copy is made even if the original is already random access. It can be useful if you want a copy of the table known to have the resource usage or performance characteristics defined by this policy.- Parameters:
table
- input table- Returns:
- deep copy of
table
- Throws:
IOException
-