|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.ExhibitPropsComputable
public final class ExhibitPropsComputable
Immutable (and serialisable) store of all immutable computable auxiliary properties of a single exhibit. These are properties that can be computed from the basic exhibit binary data and that generally do not need to be recomputed (unless that exhibit changes, or if we upgrade the code and can get "better" values).
Some of the attributes contained in this object may be expensive to compute (and may require reading the entire exhibit) and thus this object is precomputed on the master server (or offline) where the exhibit is available from fast local storage in its entirety.
This is designed to be efficient on the wire and in memory, since these details will be held for each and every exhibit.
Some data in this object is transient and recomputable from other fields and is recomputed if this object is serialised and deserialised or is kicked out of memory due a shortage.
The equals() and hashCode() of this class can be very expensive, so intern()ing it can be too. However, we do intern() some of its elements.
The construction of this item is brittle, so that if we cannot construct it all, correctly, then we veto construction entirely, so as to avoid results from transient failures persisting indefinitely.
TODO: use a raw UTF form for the description text (not a String or Name) on the wire so that when serialising we don't create and hold onto another Object reference when we could instead have some compressed bytes in a stream somewhere
| Field Summary | |
|---|---|
private int |
_hash
Private cache of the hash value; initially zero, and zero for an EMPTY instance. |
private static boolean |
ATTEMPT_C7BS_COMPRESSION
If true then attempt in-memory compression of metadata to save space with Compact7BitString. |
private static boolean |
DEFER_COMPACTION
If true then defer compaction of metadata. |
static ExhibitPropsComputable |
EMPTY
Shared empty instance. |
private static java.lang.String |
MDPREFIX
Common "assumed" prefix on XML metadata. |
private static int |
MDPREFIX_LENGTH
|
private static java.lang.String |
MDSUFFIX
Common "assumed" suffix on XML metadata. |
private static int |
MDSUFFIX_LENGTH
|
private java.lang.Object |
metadata
Trimmed metadata for the exhibit (without the constant prefix/suffix); null if none available. |
static Compact7BitString.StaticDictionary |
sDict
Shared static dictionary for use with in-memory Compact7BitString metadata. |
private static long |
serialVersionUID
Our serial version... |
private java.awt.Dimension |
xyDimensions
X,Y dimensions in pixels for images (moving or still) that have a fixed rectangular dimension, else null. |
| Constructor Summary | |
|---|---|
private |
ExhibitPropsComputable()
Make an empty instance. |
private |
ExhibitPropsComputable(java.awt.Dimension xyDim,
java.lang.Object metadata)
Make non-empty instance. |
| Method Summary | |
|---|---|
private static java.lang.Object |
_compressTrimmedMetadata(java.lang.CharSequence mdTrimmed)
Attempt to compress supplied already-trimmed metadata; returns null if input is null. |
private int |
_computeHash()
Compute the hash value. |
static java.lang.String |
_trimStringFormOfOuterMetadataTag(java.lang.String mdString)
Remove explicit fixed outer tag to save a little space, or null if input is null. |
void |
compact()
Compact the internal representation of this instance (and its sub-objects) if possible. |
static ExhibitPropsComputable |
createExhibitPropsComputable(ExhibitStaticAttr esa,
AllExhibitProperties.ExhibitDataSource ds)
Factory method to create a fully populated ExhibitPropsComputable object. |
boolean |
equals(java.lang.Object obj)
Equal if all the members are. |
java.lang.String |
getCompactableInstanceName()
Get name of this Compactable instance for tracking purposes, or null if none. |
private static javax.xml.parsers.DocumentBuilderFactory |
getFactory()
Return a new factory each time to minimise chance of 'leaks'. |
org.w3c.dom.Node |
getMetadata()
Get exhibit metadata; null if none available. |
java.lang.String |
getMetadataAsXML()
Get metadata as full XML string surrounded with top-level tags; null if no metadata. |
java.lang.CharSequence |
getMetadataAsXMLTrimmed()
Get metadata as (immutable) trimmed XML, NOT surrounded with top-level tags; null if no metadata. |
java.awt.Dimension |
getXyDimensions()
Get x,y dimensions in pixels for images (moving or still) that have a fixed rectangular dimension, else null. |
int |
hashCode()
Hash based on the dimensions, else on the metadata. |
private static org.w3c.dom.Node |
parseMetadata(java.lang.String xml)
Parse metadata from internal XML String format; never null. |
protected java.lang.Object |
readResolve()
Deserialise: use constructor for validation, defensive copying, etc. |
java.lang.String |
toString()
Human-readable summary. |
void |
validateObject()
Validate fields/state. |
protected java.lang.Object |
writeReplace()
Serialise: write in the best format for the wire. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final ExhibitPropsComputable EMPTY
private static final java.lang.String MDPREFIX
private static final int MDPREFIX_LENGTH
private static final java.lang.String MDSUFFIX
private static final int MDSUFFIX_LENGTH
private final java.awt.Dimension xyDimensions
Because Dimension is mutable, we hand out copies of it to callers.
public static final Compact7BitString.StaticDictionary sDict
private volatile java.lang.Object metadata
Note that this is stored without the redundant top-level tag.
Marked volatile to allow safe lockless update by compact().
private static final boolean ATTEMPT_C7BS_COMPRESSION
private static final long serialVersionUID
private transient int _hash
private static final boolean DEFER_COMPACTION
Conversely, this could save a lot of time constructing/deserialising data before the first operations can be performed on it and where memory space is not the primary constraint.
| Constructor Detail |
|---|
private ExhibitPropsComputable()
private ExhibitPropsComputable(java.awt.Dimension xyDim,
java.lang.Object metadata)
This may defensively copy mutable argument values.
xyDim - xy (positive) dimensions in pixels or null if nonemetadata - normalised metadata else null if none.| Method Detail |
|---|
public java.awt.Dimension getXyDimensions()
We return a copy of our internal data.
public java.lang.CharSequence getMetadataAsXMLTrimmed()
public java.lang.String getMetadataAsXML()
public org.w3c.dom.Node getMetadata()
private static javax.xml.parsers.DocumentBuilderFactory getFactory()
private static org.w3c.dom.Node parseMetadata(java.lang.String xml)
throws java.io.IOException,
org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException
xml - well-formed non-null non-empty XML metadata
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationExceptionprivate static java.lang.Object _compressTrimmedMetadata(java.lang.CharSequence mdTrimmed)
public static ExhibitPropsComputable createExhibitPropsComputable(ExhibitStaticAttr esa,
AllExhibitProperties.ExhibitDataSource ds)
throws java.io.IOException
The data source object is not stored in the object.
This will veto any attempt at construction if the data object is not fully loaded, ie all available immediately with high bandwidth.
Underlying methods, such as getMetadata(), can throw all sorts of horrors, such as an Error, so we try very hard to fail gracefully if this happens and only throw an IOException.
java.io.IOExceptionpublic static java.lang.String _trimStringFormOfOuterMetadataTag(java.lang.String mdString)
protected java.lang.Object readResolve()
protected java.lang.Object writeReplace()
This allows a stream compressor to effectively remove the redundancy between instances of this class on the wire as well as internal redundancies.
We assume that there will almost never be identical instances on one stream so we don't mind writing new copies each time where it does happen.
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.InvalidObjectExceptionpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectprivate int _computeHash()
Note that this also means that the AEP hash contains a semantically-significant sampling of the exhibit data as well as such things as length and timestamp from the AEID.
public int hashCode()
hashCode in class java.lang.Objectpublic void compact()
This may be able to convert some state to a more memory-efficient representation after construction or deserialisation, and is suitable to be called by a background thread.
We don't prevent multiple concurrent calls to this routine, since they are at worst wasteful of CPU but not unsafe.
compact in interface MemoryTools.Compactablepublic java.lang.String getCompactableInstanceName()
getCompactableInstanceName in interface MemoryTools.Compactable
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||