|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.datasource.ExhibitDataSimpleCache.CachedFile
private static final class ExhibitDataSimpleCache.CachedFile
Object representing one (partially) cached file on disc. This is immutable, serialisable, and totally ordered.
The natural sort order is LRU (Least-Recently Used) first, with ties (which should be very rare) broken by increasing cached length (ignoring thumbnails, etc) (to represent the cost expended getting the data to cache), and then exhibit name.
This carries the minimum that need be known about each file on disc.
The item is immutable to avoid causing difficulties when already inserted in a sorted collection.
We store the timestamp of the original source exhibit file; if it doesn't match the current exhibit timestamp then this cache entry and its cached data has to be regarded as invalidated and discarded.
| Field Summary | |
|---|---|
private static boolean |
_TE_USE_CLONE
If true, touchedEntry() used clone() rather than a constructor. |
(package private) long |
cachedLength
The initial portion cached on disc (bytes); never negative. |
(package private) long |
lastAccessed
The time last written or read; non-negative. |
(package private) static int |
MAX_EMPTY_ENTRY_BYTES_ON_DISC
Rough estimate of maximum space required for new empty cache entry. |
(package private) Name.ExhibitFull |
name
The official name of the exhibit; never null and always a valid exhibit name. |
private static long |
serialVersionUID
My serialisation version number. |
(package private) long |
timestamp
The master-exhibit timestamp; strictly positive. |
(package private) int |
tnBytes
The size of the serialised thumbnail object, zero if none; never negative. |
| Constructor Summary | |
|---|---|
private |
ExhibitDataSimpleCache.CachedFile(Name.ExhibitFull _name,
long _ts,
long _len,
long _lastA,
int _tnBytes)
Creates a raw entry given all the data about the entry. |
| Method Summary | |
|---|---|
(package private) long |
calcDiscSpace()
Calculate the disc space taken up by this exhibit cache entry all told. |
private ExhibitDataSimpleCache.CachedFile |
cloneMe()
Clone the object; does not throw CloneNotSupportedException. |
int |
compareTo(ExhibitDataSimpleCache.CachedFile other)
Total ordering: oldest first, then smallest first, then by name. |
boolean |
equals(java.lang.Object o)
Equality relies on comparison, ie on last-access time, cached length and name. |
(package private) ExhibitDataSimpleCache.CachedFile |
extendCacheFile(java.io.File cacheDir,
long dataStart,
java.nio.ByteBuffer data)
Extend given cache file on disc and return new CachedFile. |
(package private) ExhibitDataSimpleCache.CachedFile |
fixup(ExhibitDataSimpleCache.CachedFile rec,
SimpleLoggerIF logger)
Fixes-up in-memory cached meta-data for exhibit with that from disc. |
(package private) ExhibitDataSimpleCache.CachedFile |
getCachedData(java.io.File cacheDir,
int start,
java.nio.ByteBuffer buf,
boolean quick)
Return data chunk from cached file in the result argument. |
(package private) static long |
getCachedDataLength(java.io.File cacheDir,
Name.ExhibitFull exhibitName)
Recovers the actual on-disc cached exhibit prefix length, or 0 if not present. |
long |
getLastAccessed()
The time last written or read; non-negative. |
(package private) ExhibitThumbnails |
getThumbnails(java.io.File cacheDir)
Returns thumbnails; never null. |
int |
hashCode()
The hash depends on the timestamp. |
(package private) boolean |
hasThumbnails()
Do we have thumbnails? True if the thumbnails file is non-zero length. |
(package private) boolean |
isEquivalent(ExhibitDataSimpleCache.CachedFile other)
Returns true if this exhibit's metadata is essentially equivalent to another one. |
(package private) static ExhibitDataSimpleCache.CachedFile |
makeNewDiscCacheFile(java.io.File cacheDir,
Name.ExhibitFull name,
long exhibitStamp)
Make a new file on disc and return its CachedFile. |
private void |
readObject(java.io.ObjectInputStream in)
Deserialise. |
(package private) static ExhibitDataSimpleCache.CachedFile |
recoverExtantCachedFileDetails(java.io.File cacheDir,
Name.ExhibitFull exhibitName)
Recovers an approximate entry for an extant cached file; never null. |
(package private) ExhibitDataSimpleCache.CachedFile |
saveThumbnails(java.io.File cacheDir,
ExhibitThumbnails tns)
Add a thumbnail file and return a new in-memory cache entry. |
java.lang.String |
toString()
Generate human-readable summary of state. |
(package private) ExhibitDataSimpleCache.CachedFile |
touchedEntry()
Make touched cache file entry. |
(package private) ExhibitDataSimpleCache.CachedFile |
touchedEntry(long newLastAccessedTimestamp)
Make touched cache file entry. |
void |
validateObject()
Validate fields/state. |
(package private) ExhibitDataSimpleCache.CachedFile |
zapData(java.io.File cacheDir)
Remove any exhibit data and return a new in-memory cache entry. |
(package private) void |
zapMe(java.io.File cacheDir)
Used to zap my disc files, including all auxiliary files for this exhibit. |
(package private) ExhibitDataSimpleCache.CachedFile |
zapThumbnails(java.io.File cacheDir)
Remove any thumbnail file and return a new in-memory cache entry. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
final Name.ExhibitFull name
final long timestamp
final long cachedLength
long lastAccessed
We only do the setLastModified() when writing to the filesystem anyway, or in the special case of reading the first byte of an exhibit. We do this to save (synchronous) disc traffic updating timestamps when in fact this should all be in the metadata and is only needed if that is lost for some reason.
Logically final, but made mutable for touchedEntry() to be able to overwrite in a cloned copy.
May be zero if only metadata but no exhibit data is present.
final int tnBytes
private static final boolean _TE_USE_CLONE
static final int MAX_EMPTY_ENTRY_BYTES_ON_DISC
This should approximately match what calcDiscSpace() should produce for such an exhibit, but the values may not be exactly the same.
private static final long serialVersionUID
| Constructor Detail |
|---|
private ExhibitDataSimpleCache.CachedFile(Name.ExhibitFull _name,
long _ts,
long _len,
long _lastA,
int _tnBytes)
throws java.lang.IllegalArgumentException
Should not be called directly from outside the class.
java.lang.IllegalArgumentException| Method Detail |
|---|
public long getLastAccessed()
boolean isEquivalent(ExhibitDataSimpleCache.CachedFile other)
The result is false if the argument is null.
boolean hasThumbnails()
final ExhibitThumbnails getThumbnails(java.io.File cacheDir)
throws java.io.IOException
We're fairly dumb about this, assuming that all aurgument have been validated.
java.io.IOException
ExhibitDataSimpleCache.CachedFile getCachedData(java.io.File cacheDir,
int start,
java.nio.ByteBuffer buf,
boolean quick)
throws java.io.IOException
We touch the file (set its stamp to `now') to show that it has been used iff we retrieve the first byte otherwise we rely on the in-memory metadata to hold the last access time; this is a belt-and-braces measure in case we have to reconstruct the metadata from the disc cache for some reason.
This will throw an IOException or IllegalArgumentException if it cannot find the file or there is some other problem.
We're fairly dumb about this, assuming that everything has been checked elsewhere.
If the read length is zero the buffer may be null.
quick - be as fast as possible, eg don't update timestamps
java.io.IOException
static long getCachedDataLength(java.io.File cacheDir,
Name.ExhibitFull exhibitName)
All arguments must be validated and safe before calling this routine; for speed it does no further validation.
cacheDir - non-null directory containing cacheexhibitName - name of exhibit; syntactically valid, non-null
ExhibitDataSimpleCache.CachedFile fixup(ExhibitDataSimpleCache.CachedFile rec,
SimpleLoggerIF logger)
In particular this returns a new item if:
This instance is not altered, nor is the disc-based data.
TODO: Possibly discard all cached data for an exhibit with a changed timestamp.
rec - the meta-data as reconstructed from disc; never null
static ExhibitDataSimpleCache.CachedFile recoverExtantCachedFileDetails(java.io.File cacheDir,
Name.ExhibitFull exhibitName)
throws java.io.IOException
This will throw an IOException or IllegalArgumentException if it cannot find the file or other data that it needs.
This does not adjust the in-memory records, nor alter anything on disc.
java.io.IOExceptionExhibitDataSimpleCache.CachedFile touchedEntry()
This does not alter anything on disc.
ExhibitDataSimpleCache.CachedFile touchedEntry(long newLastAccessedTimestamp)
This does not alter anything on disc.
This could construct a new object, but to save time and avoid the heavy lifting in the constructor, this uses clone().
newLastAccessedTimestamp - time to make touched version of descriptor with,
strictly positiveprivate ExhibitDataSimpleCache.CachedFile cloneMe()
static ExhibitDataSimpleCache.CachedFile makeNewDiscCacheFile(java.io.File cacheDir,
Name.ExhibitFull name,
long exhibitStamp)
throws java.io.IOException
No zero-length cache entry is created.
No thumbnail is created; any extant one is expunged.
This does not adjust the in-memory records.
java.io.IOException
ExhibitDataSimpleCache.CachedFile extendCacheFile(java.io.File cacheDir,
long dataStart,
java.nio.ByteBuffer data)
throws java.io.IOException
Note that though the new data should normally be exactly at the end of the existing data, it is not an error, though probably inefficient, to start writing before the end of the existing data, since that indicates wasted effort re-cacheing data we already have.
It is an error to start writing at a point beyond the end of the existing cached data since we don't support "sparse" data and on some operating systems (eg UNIX) the gaps would be filled with zeros which we probably don't want.
If there is an overlap with the existing data, the old (overlapped) data is overwritten silently with the new. This may allow us to update parts in-situ to fix errors, and to silently handle partly-overlapping concurrent updates.
The cache file is extended with (the non-overlapping part of) the given data.
This does not adjust the in-memory records.
This must only be called when other cache write activity (such as removing entries) is locked out to avoid possible file corruption.
java.io.IOExceptionExhibitDataSimpleCache.CachedFile zapThumbnails(java.io.File cacheDir)
This does not mark the entry as updated on disc nor in the new record.
This does not adjust the in-memory records itself.
ExhibitDataSimpleCache.CachedFile zapData(java.io.File cacheDir)
This attempts to force a deletion even if the file is not obviously present, just to make best efforts to purge it, and we whinge (on System.err) if we cannot make it go away.
This does not mark the entry as updated on disc nor in the new record.
This does not adjust the in-memory records itself.
ExhibitDataSimpleCache.CachedFile saveThumbnails(java.io.File cacheDir,
ExhibitThumbnails tns)
throws java.io.IOException
The thumbnail argument must be non-null.
This does not mark the entry as updated on disc or in the new record.
This does not adjust the in-memory records itself.
java.io.IOExceptionpublic final boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.Objectpublic final int compareTo(ExhibitDataSimpleCache.CachedFile other)
compareTo in interface java.lang.Comparable<ExhibitDataSimpleCache.CachedFile>final long calcDiscSpace()
This assumes a roughly UFS-like (UNIX File System) pattern of disc usage.
final void zapMe(java.io.File cacheDir)
This does not adjust the in-memory records.
public java.lang.String toString()
toString in class java.lang.Object
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public void validateObject()
throws java.io.InvalidObjectException
Barf if something bad is found. (Maybe allow some extra info in debug version.)
validateObject in interface java.io.ObjectInputValidationjava.io.InvalidObjectException
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||