|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.webSvr.threeD.ThreeDLogic
final class ThreeDLogic
3D Walkthrough "business-logic" holder. Is designed to be GUI-free and just contain the logic.
Package visible since need be seen only by the main GUI class.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.hd.d.pg2k.webSvr.threeD.LightweightMetaDataFetchInterface |
|---|
LightweightMetaDataFetchInterface.GalleryBasicMetaData |
| Field Summary | |
|---|---|
private java.lang.Object |
_c_fT
Private cache value for fetchTexture(). |
private Name.ExhibitFull[] |
_cache_getExhibitName
Cache for getExhibitName(); never null. |
private java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> |
_cache_getThumbnailImage_sml
Cache of small thumbnail images for getThumbnailImageAsTexture(); never null. |
private MemoryTools.SimpleLRUMap<Name.ExhibitFull,ROByteArray> |
_cache_getThumbnailImage_sml_binary
LRU cache of small thumbnail images for getThumbnailImageAsTexture() in binary form; never null. |
private java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> |
_cache_getThumbnailImage_std
Cache of standard (larger) thumbnail images for getThumbnailImageAsTexture(); never null. |
private long |
_metaDataCheckTime
Time after which we should check metadata with server. |
private java.util.BitSet |
_namesNeeded
Set of requested exhibit names by ordinal; never null. |
private static boolean |
ALLOW_FALLBACK_FS_FILE_ACCESS
If true then we can try the local filesystem as a fallback if not in JWS. |
private static boolean |
ALLOW_TEXTURE_FALLBACK
If true then allow fetchTexture() to return a small thumbnail where the standard one is unavailable. |
(package private) javax.jnlp.BasicService |
bs
Handle on JWS basic service; null if none. |
private static boolean |
CACHE_JWS_TN_SML
If true then allow local persistance of small thumbnails in their binary form using JWS. |
private static boolean |
CACHE_MEM_TN_SML
If true then allow local cacheing of small thumbnails in their binary form in memory. |
private LightweightMetaDataFetchInterface.GalleryBasicMetaData |
cachedBasicMetaData
Cached copy of the basic Gallery meta-data; never null. |
private static java.awt.image.BufferedImage |
defaultTNImage
Default thumbnail place-holder image; never null. |
private static int |
defaultTNImage_Edge
Power-of-two edge size of default/absent thumbnail stand-in. |
private static javax.media.j3d.Texture |
defaultTNTexture
Default thumbnail place-holder image as a texture; never null. |
private SimpleLoggerIF |
logger
Reference to central logger; never null. |
private static int |
MAX_SML_TN_CACHE_IN_MEMORY
Maximum number of small thumbnail binaries to cache in memory to limit resource use; strictly positive. |
private static int |
MAX_TN_CONC_FETCHES
Maximum number of thumbnails to fetch in parallel; strictly positive. |
private static int |
MIN_TN_RETRY_MS
Minimum time in milliseconds before retrying a thumbnail fetch after any previous failure to fetch it; strictly positive. |
private java.lang.Thread |
nameFetchWorker
Worker thread that does nothing but get names in the background. |
private static java.awt.image.BufferedImage |
notLoadedTNImage
Thumbnail image for items not yet loaded, minimal power-of-two-edge size; never null. |
private static javax.media.j3d.Texture |
notLoadedTNTexture
Thumbnail not-loaded image as a texture; never null. |
(package private) javax.jnlp.PersistenceService |
ps
Handle on JWS persistence service; null if none. |
private boolean |
shuttingDown
Set true when we are shutting down (and never set false again). |
(package private) javax.jnlp.SingleInstanceService |
sis
Handle on JWS singleton service; null if none. |
private static int |
TEXTURE_LOADER_FLAGS
Default flags for loading textures. |
private java.util.Map<Name.ExhibitFull,java.lang.Thread> |
thumbnailsBeingFetched
Map of names of exhibits whose thumbnails currently being fetched to the Threads fetching them; never null. |
(package private) static int |
TN_IMAGE_FORMAT
Thumbnail image format (from Java3D point of view). |
(package private) static int |
TN_SML_IMAGE_DIM
Thumbnail (small) rendered image width and height, positive power-of-two smaller than TN_STD_IMAGE_DIM. |
private static java.lang.String |
TN_SML_RRURL_PREFIX
Root-relatve absolute URL prefix for small thumbnails; starts and ends with '/'. |
(package private) static int |
TN_STD_IMAGE_DIM
Thumbnail (standard) rendered image width and height, positive power-of-two; fixed maximum value for all thumbnails. |
private static java.lang.String |
TN_STD_RRURL_PREFIX
Root-relatve absolute URL prefix for standard thumbnails; starts and ends with '/'. |
private java.util.Map<Name.ExhibitFull,java.lang.Long> |
tnNoRetryBefore
Map of thumbnail's full exhibit name to time before we may attempt to refetch following a failure; never null. |
private long |
userLastActive
Last time the user was active in this run, eg in the UI; initially object construction time. |
| Fields inherited from interface org.hd.d.pg2k.webSvr.threeD.LightweightMetaDataFetchInterface |
|---|
MAX_NAMES_REQUEST |
| Constructor Summary | |
|---|---|
ThreeDLogic(SimpleLoggerIF logger)
Package-visible constructor since need be seen only by the main GUI class. |
|
| Method Summary | |
|---|---|
private static java.net.URL |
_adjustURLForMuffin(java.net.URL full)
Adjust URLs to be suitable for JWS muffins. |
private void |
_fetchNames(long stopBy,
Name.ExhibitFull[] names)
Fetch all outstanding names that we can, up to the specified time limit. |
private void |
fetchTexture(Name.ExhibitFull exhibitName,
java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> cache,
boolean std)
Fetch the image/texture synchronously from the server. |
Name.ExhibitFull |
getExhibitName(int ordinal)
Fetch the full name of the given numbered exhibit; null if no such exhibit or not currently available. |
Name.ExhibitFull[] |
getExhibitNames(int[] ordinals)
Fetch the full name of the given numbered exhibits; each entry null if no such exhibit or not currently available, overall result never null. |
LightweightMetaDataFetchInterface.GalleryBasicMetaData |
getGalleryBasicMetaData()
Return cached copy (or EMPTY if none); never null. |
(package private) javax.media.j3d.Texture |
getThumbnailImageAsTexture(int ordinal,
boolean std,
boolean lowPriority)
Get thumbnail image as a power-of-two-side square Texture for given image index. |
long |
getUserLastActive()
Get the last time the user was active in this run, eg in the UI; initially zero. |
private void |
poll()
Called (by a daemon thread) to perform async activity. |
(package private) void |
setUserLastActive(java.lang.String doingWhat)
Note user as active. |
(package private) void |
shutdown()
Perform any activity required to shut down cleanly, eg save state. |
(package private) void |
startup()
Load any (large) persisted data from a previous execution and start a background worker thread. |
boolean |
userInactive()
Returns true iff the user is considered inactive. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final boolean ALLOW_FALLBACK_FS_FILE_ACCESS
private final SimpleLoggerIF logger
final javax.jnlp.BasicService bs
final javax.jnlp.PersistenceService ps
final javax.jnlp.SingleInstanceService sis
private volatile long userLastActive
private volatile LightweightMetaDataFetchInterface.GalleryBasicMetaData cachedBasicMetaData
Is volatile for thread-safe lock-free access.
private transient volatile long _metaDataCheckTime
private volatile Name.ExhibitFull[] _cache_getExhibitName
Length should be exhibit count.
This may be cleared (replaced by a new empty list of the right length) when a new exhibit set is detected by a changed hash code.
The data itself behind the reference is logically immutable.
Is volatile for safe lock-free access.
private final java.util.BitSet _namesNeeded
We use our poller thread to fetch names marked as needed.
static final int TN_STD_IMAGE_DIM
static final int TN_SML_IMAGE_DIM
static final int TN_IMAGE_FORMAT
private static final int defaultTNImage_Edge
private static final java.awt.image.BufferedImage defaultTNImage
private static final int TEXTURE_LOADER_FLAGS
private static final javax.media.j3d.Texture defaultTNTexture
private static final java.awt.image.BufferedImage notLoadedTNImage
private static final javax.media.j3d.Texture notLoadedTNTexture
private static final int MAX_SML_TN_CACHE_IN_MEMORY
We cap this to a fraction (~20%) of estimated total JVM memory available, though ensure that a we always set a minimum useful size. (If maxMemory() is not limited/set then we use totalMemory().)
private final MemoryTools.SimpleLRUMap<Name.ExhibitFull,ROByteArray> _cache_getThumbnailImage_sml_binary
A zero-length entry indicates a permanent failure to load the thumbnail.
private final java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> _cache_getThumbnailImage_sml
We use a non-strong reference because the memory requirements may be large and unpredictable.
TODO: This should be purged of stale entries periodically and/or when a new exhibit set is detected by a changed hash code in case those entries refer to exhibits that no longer exist.
Thread-safe.
private final java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> _cache_getThumbnailImage_std
We use a non-strong reference because the memory requirements may be large and unpredictable.
TODO: This should be purged of stale entries periodically and/or when a new exhibit set is detected by a changed hash code in case those entries refer to exhibits that no longer exist.
Thread-safe.
private static final int MAX_TN_CONC_FETCHES
Set to more than the number of available processors, to help make use of available resources and overcome I/O latency, though capped to protect our resources and those of the server.
private final java.util.Map<Name.ExhibitFull,java.lang.Thread> thumbnailsBeingFetched
This may be shared with other per-exhibit threads.
The size of this should never be larger than MAX_TN_CONC_FETCHES.
private static final int MIN_TN_RETRY_MS
private final java.util.Map<Name.ExhibitFull,java.lang.Long> tnNoRetryBefore
private static final java.lang.String TN_STD_RRURL_PREFIX
private static final java.lang.String TN_SML_RRURL_PREFIX
private static final boolean ALLOW_TEXTURE_FALLBACK
private static final boolean CACHE_JWS_TN_SML
private static final boolean CACHE_MEM_TN_SML
private transient volatile java.lang.Object _c_fT
private final java.lang.Thread nameFetchWorker
private volatile boolean shuttingDown
| Constructor Detail |
|---|
ThreeDLogic(SimpleLoggerIF logger)
logger - reference to central logger; never null| Method Detail |
|---|
public long getUserLastActive()
When the user has not been active for a long time, some activities, such as polling the server, may halt or slow down to conserve resources.
void setUserLastActive(java.lang.String doingWhat)
This may be triggered/called by a number of events that indicate that the user is active.
When the user has not been active for a long time, some activities, such as polling the server, may halt or slow down to conserve resources.
public boolean userInactive()
public LightweightMetaDataFetchInterface.GalleryBasicMetaData getGalleryBasicMetaData()
getGalleryBasicMetaData in interface LightweightMetaDataFetchInterfacepublic Name.ExhibitFull getExhibitName(int ordinal)
This assumes that there is a sensible stable ordering of exhibits, probably in "smart-sorted" order or similar.
This ordering is fixed from one exhibit set to the next, ie is stable while the exhibit set hash remains unchanged.
This may go across the Net to fetch its values, so may block for a while. (We aim to cache responses, however, so that repeated retrieval of the same value should be quick, at least until the exhibit set changes.)
getExhibitName in interface LightweightMetaDataFetchInterfacepublic Name.ExhibitFull[] getExhibitNames(int[] ordinals)
This assumes that there is a sensible stable ordering of exhibits, probably in "smart-sorted" order or similar.
This ordering is fixed from one exhibit set to the next, ie is stable while the exhibit set hash remains unchanged.
getExhibitNames in interface LightweightMetaDataFetchInterface
javax.media.j3d.Texture getThumbnailImageAsTexture(int ordinal,
boolean std,
boolean lowPriority)
This routine assumes that the caller will never alter the result, so instances can be safely cached/shared.
If the exhibit does not exist or a thumbnail is not available then this returns a standard "grey"/not-present image.
An out-of-range request returns a different "not-loaded" image.
The underlying image is (re)fetched from the server and cached as need be which should be largely invisible to the Java3D rendering engine.
This may release image data that is not used for a long time.
This fetches low-priority requests only when not fetching any others.
Kept package-visible-only for now.
ordinal - index of thumbnail texture to retrieve,
else -1 to get standard "not-yet-fetched" thumbnail texturestd - if true then fetch standard thumbnail, else smalllowPriority - fetch the texture only if the system is quiet
private static java.net.URL _adjustURLForMuffin(java.net.URL full)
throws java.net.MalformedURLException
java.net.MalformedURLException
private void fetchTexture(Name.ExhibitFull exhibitName,
java.util.Map<Name.ExhibitFull,java.lang.ref.SoftReference<javax.media.j3d.Texture>> cache,
boolean std)
This never deletes cache entries.
This may try to fall back to the small thumbnail if the large one cannot be fetched...
exhibitName - the full valid name of the exhibitcache - the cache to save the texture instd - if true then fetch standard thumbnail, else smallvoid startup()
We spin this off into a separate thread to avoid blocking startup.
This should be called at most once.
Package-visible so as to be directly usable by GUI classes.
private void poll()
This is not called until construction is complete.
Package-visible so as to be directly usable by the main GUI class.
private void _fetchNames(long stopBy,
Name.ExhibitFull[] names)
void shutdown()
Package-visible so as to be directly callable by the main GUI class.
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||