Package com.aoindustries.aoserv.client
Class FilesystemCachedTable<K,V extends FilesystemCachedObject<K,V>>
- java.lang.Object
-
- com.aoindustries.aoserv.client.AOServTable<K,V>
-
- com.aoindustries.aoserv.client.FilesystemCachedTable<K,V>
-
- All Implemented Interfaces:
FileListObjectFactory<V>,Table<V>,Iterable<V>
- Direct Known Subclasses:
DistroFileTable
public abstract class FilesystemCachedTable<K,V extends FilesystemCachedObject<K,V>> extends AOServTable<K,V> implements FileListObjectFactory<V>
AFilesystemCachedTablestores all of the availableFilesystemCachedObjects in a temporary file and performs all subsequent data access locally. The server notifies the client when a table is updated, and the caches are then invalidated. Once invalidated, the data is reloaded upon next use.The file format is a simple fixed record length format. TODO: It is possible to use the same column sorting technique to implement the getIndexedRows method from AOServTable.
- Author:
- AO Industries, Inc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.aoindustries.aoserv.client.AOServTable
AOServTable.OrderBy
-
-
Field Summary
-
Fields inherited from class com.aoindustries.aoserv.client.AOServTable
ASCENDING, connector, DESCENDING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFilesystemCachedTable(AOServConnector connector, Class<V> clazz)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclearCache()Clears the cache, freeing up memory.VcreateInstance()protected abstract intgetRecordLength()List<V>getRows()Gets the complete list of objects in the table.List<V>getRowsCopy()Gets a modifiable copy of the rows, which may then be manipulated, such as for sorting.protected ComparisonSortAlgorithm<Object>getSortAlgorithm()FastQSort accesses the disk file less than other algorithms, and does not load all the objects into memory at once like the default Java merge sort.protected VgetUniqueRowImpl(int col, Object value)Gets a row given a unique column value.booleanisLoaded()Checks if the table is loaded.-
Methods inherited from class com.aoindustries.aoserv.client.AOServTable
addProgressListener, addTableListener, addTableListener, addTableLoadListener, get, getCachedRowCount, getConnector, getDefaultOrderBy, getDefaultOrderBySQLExpressions, getIndexedRows, getIndexedRows, getMap, getNewObject, getObject, getObjects, getObjects, getObjects, getObjectsNoProgress, getObjectsNoProgress, getSize, getTableID, getTableName, getTableSchema, getUniqueRow, getUniqueRow, getUniqueRow, getUniqueRow, handleCommand, hasAnyTableListener, hasTableListener, isEmpty, iterator, printTable, removeProgressListener, removeTableListener, removeTableLoadListener, size, sortIfNeeded, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
FilesystemCachedTable
protected FilesystemCachedTable(AOServConnector connector, Class<V> clazz)
-
-
Method Detail
-
getRecordLength
protected abstract int getRecordLength()
-
clearCache
public void clearCache()
Clears the cache, freeing up memory. The data will be reloaded upon next use.- Overrides:
clearCachein classAOServTable<K,V extends FilesystemCachedObject<K,V>>
-
getRows
public final List<V> getRows() throws IOException, SQLException
Gets the complete list of objects in the table. This list is unmodifiable and will not ever be changed. Newer data will be contained in new lists so that any calling code sees a snapshot of the code and may safely assume the data is constant as long as the code uses the same reference to List returned here.- Specified by:
getRowsin interfaceTable<K>- Overrides:
getRowsin classAOServTable<K,V extends FilesystemCachedObject<K,V>>- Returns:
- a
Listcontaining all of the rows - Throws:
IOException- if unable to access the serverSQLException- if unable to access the database- See Also:
AOServTable.getRowsCopy()
-
getRowsCopy
public List<V> getRowsCopy() throws IOException, SQLException
Description copied from class:AOServTableGets a modifiable copy of the rows, which may then be manipulated, such as for sorting.This gives the table implementation a way to create a defensive copy most efficient to its underlying storage mechanism.
Note: It is best to use
AOServTable.getSortAlgorithm()when sorting rows, as the choice of sorting can be very important when objects are pulled from non-heap source like filesystem-based objects. It is very easy for the sort itself to end up pulling all objects into heap.- Specified by:
getRowsCopyin classAOServTable<K,V extends FilesystemCachedObject<K,V>>- Throws:
IOExceptionSQLException- See Also:
AOServTable.getRows(),AOServTable.getSortAlgorithm()
-
getSortAlgorithm
protected ComparisonSortAlgorithm<Object> getSortAlgorithm()
FastQSort accesses the disk file less than other algorithms, and does not load all the objects into memory at once like the default Java merge sort.- Overrides:
getSortAlgorithmin classAOServTable<K,V extends FilesystemCachedObject<K,V>>
-
getUniqueRowImpl
protected final V getUniqueRowImpl(int col, Object value) throws IOException, SQLException
Description copied from class:AOServTableGets a row given a unique column value.- Specified by:
getUniqueRowImplin classAOServTable<K,V extends FilesystemCachedObject<K,V>>- Parameters:
col- the column index to searchvalue- whennull, no row is matched, even if there is a single row with a uniquelynullvalue- Throws:
IOExceptionSQLException
-
isLoaded
public final boolean isLoaded()
Description copied from class:AOServTableChecks if the table is loaded. A table is considered loaded when accessing any part of it will be done entirely locally, avoiding any network traffic.- Overrides:
isLoadedin classAOServTable<K,V extends FilesystemCachedObject<K,V>>
-
createInstance
public V createInstance() throws IOException
- Specified by:
createInstancein interfaceFileListObjectFactory<K>- Throws:
IOException
-
-