|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.webSvr.exhibit.DataSourceBean
public final class DataSourceBean
JavaBean encapsulating access to exhibit data and meta-data. This is expected to exist in one copy for the exhibit servlet, enabling (cached) access exhibit data and meta data.
This also provides access to shared data-pipeline and cache facilities, and is expected to be created on demand at application level. This, therefore, is designed to be used as a bean, and is suitable for direct instantiation from a JSP.
We have a public no-arg constructor to allow use from JSPs.
This object is thread-safe, and maximises concurrency while synchronising where necessary. (Quick calls are synchronized on this instance; longer-running calls may be synchronized on a private lock.)
This creates an internal thread to maintain the cache, and the thread is destroyed when the object is GCed. We only hold a SoftReference back to this instance from the background thread.
External callers can call the poll() method, though it is not recommended. They can also call the destroy method to close down the cache and stop the background thread, though this object must not be used thereafter.
When initialised for first use a number of parameters need to be set. (For JSP, these should only be done upon creation, eg between the useBean ... /useBean tags, to save cycles.) Many of the actual values passed are not stored but just used to extract other necessary parameters. Some parameters, notably contextPath and servletContext, should be set just before each use after retrieving the data from attributes, in case this instance has been passivated and restored.
(The servlet context parameter should be set every time the bean is used so that we always have a valid value to hand; we don't persist this if the bean is serialised.)
If an attempt to made to use the bean without initialising it, or to reinitialise it with conflicting values, an exception is thrown.
If an attempt is made to serialise/deserialise is made, the internal cache is reconstructed; careless use may result in multiple cache copies per servlet context which is wasteful, and may be unsafe.
One item created here is the by-word inverted index of the exhibits, created on first use.
This supports simple logging; by preference to the servlet context log, but failing that to System.out.
This is Serializable so as to be able to be stored in a servlet session; nothing especially long-lived or sensitive.
| Nested Class Summary | |
|---|---|
static class |
DataSourceBean.AEPLinkedKey
Key for AEP-linked store. |
private static class |
DataSourceBean.BackGroundThread
Operates the poll()ing/background Thread. |
private static class |
DataSourceBean.EDVHObservable
An Observable that changes when its "currentEDVH" value changes. |
private static class |
DataSourceBean.EFH
Emergency-free hook for when very low on memory. |
private static class |
DataSourceBean.KeyBase
Base of (immutable) lookup key for AEP-linked and non-AEP-linked tables. |
static class |
DataSourceBean.SortByEPCMRecalcUrgency
Sorts first those exhibits whose EPCM recalculation/check is most urgent. |
static class |
DataSourceBean.UnlinkedKey
Key for non-AEP-linked store. |
| Nested classes/interfaces inherited from interface org.hd.d.pg2k.svrCore.datasource.SimpleExhibitPipelineIF |
|---|
SimpleExhibitPipelineIF.PropsKey |
| Field Summary | |
|---|---|
private SimpleExhibitPipelineIF |
_dataPipeline
Non-persistable data pipeline. |
private static java.lang.Object |
_dataPipeline_build_lock
Private lock to ensure only one thread tries to build _dataPipeline. |
private DataSourceBean.EFH |
_efh
Set up emergency to clear these stores under extreme memory stress. |
private ORG.hd.d.jIndexer.server.JIndexBean |
_getJIB_cache
Cache for, and private to, _getJIB(); initially null. |
private long |
_lastGoodPostProps
Note of the last time that we successfully ran raw properties repost without error. |
private DataSourceBean.EDVHObservable |
_observable
Can be observed by an Observer that wants to know when the underlying data has changed; never null. |
private java.util.concurrent.locks.ReentrantLock |
_rebuildJIB_lock
Private lock for _rebuildJIB. |
private javax.servlet.ServletContext |
_servletContext
A valid servlet context, or null. |
private java.lang.Boolean |
_slave
Indicates if this is a master or a slave Web server, or not known. |
private boolean |
aggressive
The aggressiveness flag; defaulting to false. |
static java.lang.String |
BEAN_NAME
Name that should be used for unique application-level instance. |
private static boolean |
CACHE_INDEX_AS_FILE
If true then attempt to cache index in a file for potentially-faster system restart. |
private static java.lang.String |
CACHED_BYWORD_INDEX_FNAME
Name under which we attempt to cache the by-word index on disc (relative to servlet temp directory) if we do; not null. |
private static java.util.Iterator<Name.ExhibitFull> |
deadIt
'Dead' iterator with hasNext() always false; never null. |
private boolean |
destroyed
Set true when the servlet is destroyed. |
static int |
FEBY_MATCH_TYPE_ALL
Query type or findExhibitsByWord() to return entries matching all words. |
static int |
FEBY_MATCH_TYPE_ANY
Query type or findExhibitsByWord() to return entries matching any word. |
static int |
FEBY_MATCH_TYPE_MOST
Query type or findExhibitsByWord() to return entries matching most words. |
private static boolean |
FORCE_INDEX_REBUILD_IN_POLL
If true, ensure that index is up-to-date on each poll() call if possible. |
private DataSourceBean.AEPLinkedKey |
iterEPCM
Key for systematic EPCM recomputation (linked to AEP), Iterator |
static boolean |
LOG_QUERIES
If true, log queries made on the system for analysis. |
private WebUtils.ServletLoggerWithFallback |
logger
Our logger which falls back to System.out if servlet log not available; never null. |
private static int |
MEAN_POLL_INTERVAL_MS
Approximate target mean interval between poll() calls (ms); strictly positive. |
private static java.lang.String |
NAMEDESC_ENCODING
Encoding we use to convert name or name+description to byte stream for indexing. |
private int |
PROPS_REPOST_INTERVAL_MS
How often do we repost properties (ms, approx); strictly positive. |
private static boolean |
SCORER_BG_EMERGENCY_CUTOFF
If true then we stop all poll()-driven background/speculative Scorer processing. |
private static DataSourceBean.UnlinkedKey |
scorerKey
The non-AEP-linked key for the Scorer cache; never null. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<DataSourceBean.AEPLinkedKey,java.lang.Object>> |
storeLinked
Thread-safe (highly-concurrent) AEP-linked store; initialised on demand; never null after construction/deserialisation. |
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<DataSourceBean.UnlinkedKey,java.lang.Object>> |
storeUnlinked
Thread-safe (highly-concurrent) non-AEP-linked store; initialised on demand; never null after construction/deserialisation. |
| Fields inherited from interface org.hd.d.pg2k.svrCore.datasource.SimpleExhibitPipelineIF |
|---|
MAX_USER_READ_SIZE |
| Constructor Summary | |
|---|---|
DataSourceBean()
Public no-arg constructor for ease of use as a JavaBean. |
|
| Method Summary | |
|---|---|
private SimpleExhibitPipelineIF |
_createPipeline()
Do the heavy-lifting of creating the data pipeline; never null. |
private ORG.hd.d.jIndexer.server.JIndexBean |
_getJIB()
Get the by-word-index, possibly recreating it (without blocking if possible) if not cached or if out of date; null if not available. |
private SimpleExhibitPipelineIF |
_getPipeline()
Get data pipeline; never null. |
private void |
_keepEPCMUpToDate(GenProps gp,
long startTime,
boolean lightlyLoaded,
boolean overloaded)
Attempt to keep EPCM values up to date from within poll. |
private void |
_postProps()
Update and post properties to application level as required. |
private void |
_precomputePopularPages(GenProps gp,
long startTime)
Attempt to to precompute or keep like some pages likely to be popular/busy. |
private void |
_preloadBestAndNewest(GenProps gp,
long startTime,
SimpleExhibitPipelineIF pipeline,
javax.servlet.ServletContext servletContext)
Attempt to preload the best and newest exhibits and/or keep them fresh/live. |
private void |
_rebuildJIB()
Rebuild the JIB (index bean) if necessary and possible, avoiding blocking if possible. |
private static void |
_startBackgroundThread(DataSourceBean dsb)
Start background thread... |
void |
addObserver(java.util.Observer obs)
Register Observer to be told when exhibit data changes. |
boolean |
byWordIndexIsAvailable()
Returns true if there is a by-word index available. |
boolean |
byWordIndexIsAvailableAndUpToDate()
Returns true if there is a by-word index available and it is up-to-date. |
static java.lang.CharSequence |
canonicaliseSimpleByWordQuery(java.lang.CharSequence s,
int maxLength)
Canonicalises a simple by-word query string and sanitises it; useful for potentially-unsafe user input. |
static ORG.hd.d.jIndexer.server.JIndexBean |
computeByWordIndex(AllExhibitProperties aep)
Computes a (compact) by-word index of the current exhibits; never null. |
void |
deleteObserver(java.util.Observer o)
Remove an Observer. |
void |
destroy()
Free up some system resources and make our poller thread go away. |
int |
exhibitDataVersionHash()
Computes a hash on the versions of immutable and mutable exhibit data currently held. |
java.util.List<Name.ExhibitFull> |
findExhibitsByWord(java.lang.CharSequence query,
int matchType,
int maxResults,
ORG.hd.d.jIndexer.server.JIndexBean.SearchFilterByName docFilter)
Perform simple query on the exhibit data with candidate filtering; never null. |
java.util.List<Name.ExhibitFull> |
findExhibitsByWord(java.lang.String query,
int matchType,
int maxResults)
Perform simple query on the exhibit data without filtering. |
java.lang.Object |
getAEPLinkedValue(DataSourceBean.AEPLinkedKey key)
Get value against supplied key in AEP-linked store; result may be null. |
AllExhibitImmutableData |
getAllExhibitImmutableData(long oldStamp)
Gets all static exhibit data if its timestamp is not that specified. |
AllExhibitProperties |
getAllExhibitProperties(long oldHash)
Gets set of all exhibit properties if its hash is not that specified. |
static DataSourceBean |
getApplicationInstance(javax.servlet.ServletContext ctxt)
Factory method to create/return the unique application-level instance; never returns null. |
EventVariableValue |
getEventValue(SimpleVariableDefinition def,
EventPeriod intervalSelector,
boolean current)
Get the current partial, or previous full, event set at the specified interval; never null. |
EventVariableValue[] |
getEventValues(SimpleVariableDefinition def,
EventPeriod intervalSelector,
long intervalNumber,
java.util.BitSet whichValues)
Get the specified event sets for the specified intervals; never null. |
GenProps |
getGenProps(long oldStamp)
Gets the general properties as a GenProps object if its timestamp is not that specified. |
java.util.Properties |
getGenSecProps(long oldStamp)
Gets the security properties as a Properties object if its timestamp is not that specified. |
SimpleLoggerIF |
getLogger()
Get logger; never null. |
java.util.Properties |
getProperties(SimpleExhibitPipelineIF.PropsKey key,
long versionID)
Get requested Properties selected by key and versionID. |
void |
getRawFile(java.nio.ByteBuffer buf,
Name.ExhibitFull exhibitName,
int position,
boolean dontCache)
Get a chunk of the raw exhibit binary. |
ScorerCacheIF |
getScorerCache()
Get the Scorer cache; never null. |
javax.servlet.ServletContext |
getServletContext()
Get the servlet context associated with this bean; may be null. |
ExhibitStaticAttr |
getStaticAttr(java.lang.CharSequence name)
Deprecated. use ExhibitFull version if possible for efficiency |
ExhibitStaticAttr |
getStaticAttr(Name.ExhibitFull name)
Get the static attributes for a given exhibit. |
private java.util.concurrent.ConcurrentHashMap<DataSourceBean.AEPLinkedKey,java.lang.Object> |
getStoreLinked()
Get AEP-linked store, creating if necessary; never null. |
private java.util.concurrent.ConcurrentHashMap<DataSourceBean.UnlinkedKey,java.lang.Object> |
getStoreUnlinked()
Get non-AEP-linked store, creating if necessary; never null. |
Stratum |
getStratum()
Gets information about our stratum and upstream server; never null. |
ExhibitThumbnails |
getThumbnails(Name.ExhibitFull name,
boolean create)
Gets the thumbnails for an exhibit. |
java.lang.Object |
getUnlinkedValue(DataSourceBean.UnlinkedKey key)
Get value against supplied key in non-AEP-linked store; result may be null. |
SimpleVariableValue |
getVariable(SimpleVariableDefinition var)
Get a single variable value; returns null if no such value or wrong type. |
SimpleVariableValue[] |
getVariables(long changedSince)
Get set of variable values altered on or after specified time, or get all values with -1; never null. |
boolean |
isAggressive()
Check if we are going to be aggressive in cacheing. |
private boolean |
isDestroyed()
Check if destroyed... |
java.lang.Boolean |
isSlave()
Get status of this server; master, slave or unknown. |
void |
log(java.lang.String message)
Log the given message. |
void |
poll(GenProps gp)
Poll periodically (of the order of a second) to do background tasks. |
java.lang.Object |
putAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object value)
Store value against supplied key in AEP-linked store. |
java.lang.Object |
putIfAbsentAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object value)
Store value against supplied key in AEP-linked store only if no value already mapped for that key. |
java.lang.Object |
putIfAbsentUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object value)
Store value against supplied key in non-AEP-linked store only if no value already mapped for that key. |
java.lang.Object |
putUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object value)
Store value against supplied key in non-AEP-linked store. |
private void |
readObject(java.io.ObjectInputStream ois)
Deserialise. |
java.lang.Object |
removeAEPLinkedValue(DataSourceBean.AEPLinkedKey key)
Remove any value associated with the supplied key in AEP-linked store. |
java.lang.Object |
removeUnlinkedValue(DataSourceBean.AEPLinkedKey key)
Remove any value associated with the supplied key in non-AEP-linked store. |
boolean |
replaceAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object oldValue,
java.lang.Object newValue)
Replace value for supplied key in AEP-linked store. |
boolean |
replaceUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object oldValue,
java.lang.Object newValue)
Replace value for supplied key in non-AEP-linked store. |
void |
setContextPath(java.lang.String cPath)
We examine the context path to see if we can tell if we are slave or master. |
void |
setServletContext(javax.servlet.ServletContext context)
Set a valid servlet context. |
private void |
setSlave(boolean isASlave)
Set disposition. |
private void |
setSlave(java.lang.String masterSlave)
Set slave from context or property value. |
void |
setVariable(SimpleVariableValue newValue)
Set variable to the given value (the variable name and definition are implicit). |
int |
setVariables(SimpleVariableValue[] newValues)
Update a number of variables at once for efficiency; returns the number of variables set. |
void |
syncVariables(boolean force)
Synchronise variables with upstream values. |
void |
validateObject()
Validate fields/state. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String BEAN_NAME
private static final boolean FORCE_INDEX_REBUILD_IN_POLL
We may try to avoid a forced rebuild if the system is busy or else do each (re)build in a low-priority thread.
private final WebUtils.ServletLoggerWithFallback logger
private final DataSourceBean.AEPLinkedKey iterEPCM
private static final java.util.Iterator<Name.ExhibitFull> deadIt
private static final boolean SCORER_BG_EMERGENCY_CUTOFF
A "true" value will have to be supplied on the the command line to effect this stop.
private final int PROPS_REPOST_INTERVAL_MS
private long _lastGoodPostProps
private volatile boolean destroyed
private transient volatile DataSourceBean.EDVHObservable _observable
Volatile so that access to the reference itself does not need a lock.
May be cleared once a notification has been delivered during a poll(), ie may be at most one-shot.
Missed notifications are not considered very important.
private volatile java.lang.Boolean _slave
This value may be persisted.
Volatile to be accessed without a lock by isSlave() and setSlave().
Must be set non-null to initialise the bean for use.
May be able to be set immediately from the context.
private transient volatile javax.servlet.ServletContext _servletContext
Declared volatile to allow safe lock-free access.
Should only be accessed by setServletContext() for write and generally by _getPipeline() and _postProps() and getServletContext() for read.
private transient volatile boolean aggressive
Is volatile so that no lock is needed to access it.
Private to setServletContext() and isAggressive().
private static final java.lang.Object _dataPipeline_build_lock
private transient volatile SimpleExhibitPipelineIF _dataPipeline
Should be accessed only by _getPipeline(), and (without a lock) nulled out in destroy().
private static final int MEAN_POLL_INTERVAL_MS
Normally polling is just about once per second.
private static final java.lang.String NAMEDESC_ENCODING
private final java.util.concurrent.locks.ReentrantLock _rebuildJIB_lock
private static final boolean CACHE_INDEX_AS_FILE
private static final java.lang.String CACHED_BYWORD_INDEX_FNAME
private transient volatile ORG.hd.d.jIndexer.server.JIndexBean _getJIB_cache
Is volatile so that access without a lock is safe.
public static final int FEBY_MATCH_TYPE_ANY
public static final int FEBY_MATCH_TYPE_MOST
public static final int FEBY_MATCH_TYPE_ALL
public static final boolean LOG_QUERIES
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<DataSourceBean.AEPLinkedKey,java.lang.Object>> storeLinked
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<DataSourceBean.UnlinkedKey,java.lang.Object>> storeUnlinked
private final DataSourceBean.EFH _efh
private static final DataSourceBean.UnlinkedKey scorerKey
private static final long serialVersionUID
| Constructor Detail |
|---|
public DataSourceBean()
However, if the system property CoreConsts.WAR_SYSPROPNAME_DISPOSITION_PRESET is set to a usable value, this may allow us to start the cache sooner.
| Method Detail |
|---|
public static DataSourceBean getApplicationInstance(javax.servlet.ServletContext ctxt)
Grabs appropriate locks to ensure that there are no data races and that there is at most one instance per servlet context.
The instance has the name ``dataSource'' and can be accessed from JSPs by that name.
ctxt - current servlet context; must not be nullpublic SimpleLoggerIF getLogger()
public void log(java.lang.String message)
log in interface SimpleLoggerIF
public final void poll(GenProps gp)
throws java.io.IOException
Not expected to be called by more than one thread at a time.
poll in interface SimpleExhibitPipelineIFjava.io.IOException - in case of difficulty, but even if a sub-ordinate
call throws IOException then poll() call should continue
to do as much of its remaining work as reasonably possible
private void _precomputePopularPages(GenProps gp,
long startTime)
throws java.io.IOException
java.io.IOException
private void _keepEPCMUpToDate(GenProps gp,
long startTime,
boolean lightlyLoaded,
boolean overloaded)
throws java.io.IOException
java.io.IOException
private void _preloadBestAndNewest(GenProps gp,
long startTime,
SimpleExhibitPipelineIF pipeline,
javax.servlet.ServletContext servletContext)
throws java.io.IOException
java.io.IOException
private void _postProps()
throws java.io.IOException
java.io.IOException
public Stratum getStratum()
throws java.io.IOException
SimpleExhibitPipelineIF
getStratum in interface SimpleExhibitPipelineIFjava.io.IOExceptionpublic final void destroy()
destroy in interface SimpleExhibitPipelineIFprivate boolean isDestroyed()
public void addObserver(java.util.Observer obs)
We may discard Observers at will, and will certainly do so if serialised and deserialised.
public void deleteObserver(java.util.Observer o)
public java.lang.Boolean isSlave()
private void setSlave(boolean isASlave)
throws java.lang.IllegalStateException
If value is passed that conflicts with a non-null value already set, an IllegalStateException is thrown, ie the disposition cannot be changed once set.
java.lang.IllegalStateException
private void setSlave(java.lang.String masterSlave)
throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void setContextPath(java.lang.String cPath)
throws java.lang.IllegalStateException
This must be set before calling any of the get...() methods of the bean (since we may need this to set up our cache, for example) and is idempotent so long as we call it with the same value. If we call it with a different value the call may be aborted.
java.lang.IllegalStateExceptionpublic boolean isAggressive()
public void setServletContext(javax.servlet.ServletContext context)
We don't persist the value if the bean is serialised.
Note that if we are going to be aggressive and we already know if we are master or slave then we automatically start the data pipeline and thread if necessary, but not inside the instance lock.
If the context path is set before the servlet context and we are in aggressive mode then that will force an immediate pipeline start.
public javax.servlet.ServletContext getServletContext()
private static void _startBackgroundThread(DataSourceBean dsb)
private SimpleExhibitPipelineIF _getPipeline()
throws java.lang.IllegalStateException
Operates under the instance lock except to start any background thread.
Should be small enough to inline, statically or with JIT compiler.
java.lang.IllegalStateException - if the cache cannot be created
due to incorrect initialisation
private SimpleExhibitPipelineIF _createPipeline()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the cache cannot be created
due to incorrect initialisation
@Deprecated
public ExhibitStaticAttr getStaticAttr(java.lang.CharSequence name)
throws java.io.IOException
Convenience method supporting wider variety of types including older String-valued argument.
java.io.IOException
public ExhibitStaticAttr getStaticAttr(Name.ExhibitFull name)
throws java.io.IOException
getStaticAttr in interface SimpleExhibitPipelineIFjava.io.IOException - if the operation cannot be completed due to I/O
restrictions or failure
public void getRawFile(java.nio.ByteBuffer buf,
Name.ExhibitFull exhibitName,
int position,
boolean dontCache)
throws java.io.IOException
getRawFile in interface SimpleExhibitPipelineIFbuf - the buffer into which to read the data;
must be non-null, in put()able state,
and with remaining capacity of at least the requested number of bytesexhibitName - the full name of the exhibit to read from;
never null and must be syntactically validposition - position/index of first byte in exhibitFile to read;
non-negativedontCache - if true, this is a hint not to attempt to cache this
or displace anything from extant caches for this data
as it may for example be precaching or random activity;
by default callers should leave this false to allow cacheing
java.io.IOException - for requests that cannot be fulfilled because of
I/O restrictions or problems, such as link failure or
an upper bound on the length of a request
public AllExhibitImmutableData getAllExhibitImmutableData(long oldStamp)
throws java.io.IOException
If no exhibits are currently installed a default set with a zero timestamp is returned.
If the caller's copy appears to be up-to-date (eg the oldStamp matches that that would have been returned) null is returned.
getAllExhibitImmutableData in interface SimpleExhibitPipelineIFjava.io.IOException - if the operation cannot be completed due to I/O
restrictions or failure
public AllExhibitProperties getAllExhibitProperties(long oldHash)
throws java.io.IOException
If no exhibits are currently installed a default set with a zero timestamp is returned.
If the caller's copy appears to be up-to-date (eg the oldHash matches that that would have been returned then null is returned.
getAllExhibitProperties in interface SimpleExhibitPipelineIFjava.io.IOException - if the operation cannot be completed due to I/O
restrictions or failure
public final int exhibitDataVersionHash()
throws java.io.IOException
java.io.IOException
private ORG.hd.d.jIndexer.server.JIndexBean _getJIB()
throws java.io.IOException
We know all names to be 7-bit (printable) ASCII, and assume all descriptions to be either 7-bit ASCII or at most 8-bit ISO-8859-1 (Latin-1) text, and we use that when converting to a byte stream for indexing.
This may not force a synchronous rebuild since this may take too long, and therefore may return a stale or null index while a new one is being computed. This may also defer a build temporarily if the system is heavily loaded.
THUS: keys/docnames held in the index must be relatively stable and sane even across a (minor) change of AEP, eg exhibit short names or equivalent, so that a lookup result is still very likely to make sense.
java.io.IOExceptionpublic boolean byWordIndexIsAvailable()
If this returns true it does not guarantee that the index is up-to-date, simply that one exists and can be used, probably without blocking.
public boolean byWordIndexIsAvailableAndUpToDate()
private void _rebuildJIB()
throws java.io.IOException
Directly updates the cache used by _getJIB() if the index needs recomputing, ie if it is null or out of date wrt the AEP.
If a second thread tries to enter while one is already rebuilding the index, then the second thread returns immediately (does not block), but meaning that the cache will not be guaranteed rebuilt by the time that the second thread returns, so any caller has to be prepared to deal with the cache still null when this routine returns.
If the system is too busy then we will not attempt to (re)build the index.
Note that normally a rebuild is attempted in the background and at low priority and may be vetoed if the system is busy. However, were there is no index present at all this will force a higher-priority build and may possibly block until done.
java.io.IOException
public static ORG.hd.d.jIndexer.server.JIndexBean computeByWordIndex(AllExhibitProperties aep)
throws java.io.IOException,
java.lang.InterruptedException
java.io.IOException
java.lang.InterruptedException
public static java.lang.CharSequence canonicaliseSimpleByWordQuery(java.lang.CharSequence s,
int maxLength)
This also converts the query string to pure ASCII, having first converted any non-ISO-Latin-1 characters to spaces, trimmed any obvious whitespace, and truncated to the given length (if non-negative).
This can be directly handed the result of an HTTP request parameter, for example. The output is suitable to hand to findExhibitsByWord().
This keeps words in the order supplied especially the first.
This returns an empty sequence (eg "") if the input is null.
If the input string does not need transforming then it is returned as-is.
Any new CharSequence returned is immutable.
public java.util.List<Name.ExhibitFull> findExhibitsByWord(java.lang.String query,
int matchType,
int maxResults)
throws java.io.IOException
This returns an immutable ranked list of (full) exhibit names; possibly zero-length if no matches (but never null).
The underlying index is (re)built on first use or when the underlying data has changed.
This may take longer than we'd like and use more memory than we'd like.
query - a plain-text query of search words, space-separatedmatchType - the number of input words to match;
-1 means any word,
0 means most words,
1 means all words.maxResults - is the maximum number of results returned; should
be at least twice the maximum shown to reduce the risk
of having abandoned good results prematurely
java.io.IOException
public java.util.List<Name.ExhibitFull> findExhibitsByWord(java.lang.CharSequence query,
int matchType,
int maxResults,
ORG.hd.d.jIndexer.server.JIndexBean.SearchFilterByName docFilter)
throws java.io.IOException
This returns an immutable ranked list of (full) exhibit names; possibly zero-length if no matches (but never null).
The underlying index is (re)built on first use or when the underlying data has changed.
This may take longer than we'd like and use more memory than we'd like.
query - a plain-text query of search words, space-separatedmatchType - the number of input words to match;
-1 means any word,
0 means most words,
1 means all words.maxResults - is the maximum number of results returned; should
be at least twice the maximum shown to reduce the risk
of having abandoned good results prematurelydocFilter - if non-null, any documents for which the
accept method returns false are excluded from the search
java.io.IOException
public GenProps getGenProps(long oldStamp)
throws java.io.IOException
If no props are currently installed/available then a default set with a zero timestamp is returned.
If the caller's copy appears to be up-to-date (eg the oldStamp matches that that would have been returned) then null is returned.
getGenProps in interface SimpleExhibitPipelineIFjava.io.IOException - if the operation cannot be completed due to I/O
restrictions or failure
public java.util.Properties getGenSecProps(long oldStamp)
throws java.io.IOException
If no props are currently installed/available a default set with a zero timestamp is returned.
If the caller's copy appears to be up-to-date (eg the oldStamp matches that that would have been returned) then null is returned.
getGenSecProps in interface SimpleExhibitPipelineIFjava.io.IOException - if the operation cannot be completed due to I/O
restrictions or failure
public ExhibitThumbnails getThumbnails(Name.ExhibitFull name,
boolean create)
As a kindness to callers, we convert any IOException thrown to returning a null instead, to fold the two cases together.
getThumbnails in interface SimpleExhibitPipelineIFcreate - if true, and no thumbnail yet exists, try to
create one if possible, else only return an existing one
public void setVariable(SimpleVariableValue newValue)
throws java.io.IOException
BasicVarMgrInterfaceThis is also used to send events, the last event value being the variable's value.
setVariable in interface BasicVarMgrInterfacejava.io.IOException - in case of I/O difficulty
public int setVariables(SimpleVariableValue[] newValues)
throws java.io.IOException
BasicVarMgrInterfaceFurthermore it behaves as if the set operations are done in order, from low index to high index, unless variables are coalesced (multiple sets of the same simple variable can keep just the last value). Set operations of different variables may be re-ordered with respect to one another in order that redundancy may reduced for transmission and storage, so this implicitly allows, for example, events to be re-ordered with respect to non-event variables.
An implementation may "fail fast" on the first error/exception, or may attempt to continue and do as much as possible.
An implementation may throw an IllegalArgumentException on attempt to: set a variable with value of wrong type or incompatible definition, set a non-existent or read-only variable (or these may be ignored)
setVariables in interface BasicVarMgrInterfacejava.io.IOException
public SimpleVariableValue getVariable(SimpleVariableDefinition var)
throws java.io.IOException
BasicVarMgrInterfaceOnly the last event value for a given event variable is returned by this method.
getVariable in interface BasicVarMgrInterfacevar - definition of variable to fetch; never null
java.io.IOException - in case of I/O difficulty
public SimpleVariableValue[] getVariables(long changedSince)
throws java.io.IOException
BasicVarMgrInterfaceOnly the last event value of each event variable is returned by this method.
getVariables in interface BasicVarMgrInterfacejava.io.IOException - in case of I/O difficulty
public EventVariableValue getEventValue(SimpleVariableDefinition def,
EventPeriod intervalSelector,
boolean current)
The current set is the most timely, but may not contain enough data to be meaningful if the new interval has just started.
The previous set is complete and thus most likely to have enough samples to be useful, but is not completely current.
getEventValue in interface BasicVarMgrInterfacedef - event definition (must be for an event); never nullintervalSelector - one of EVENT_INTERVAL_SELECTOR_xxx valuescurrent - if true the current event set is returned,
else the previous complete set is returned
public EventVariableValue[] getEventValues(SimpleVariableDefinition def,
EventPeriod intervalSelector,
long intervalNumber,
java.util.BitSet whichValues)
Requests for more than SystemVariables.EVENT_SAMPLES_RETAINED in the past (or for the future!) cannot be satisfied and data will not be returned for them.
Usually not more than SystemVariables.EVENT_SAMPLES_RETAINED samples will be returned in response to any one request as a safety measure.
(An implementation that is not an end-point may go upstream to fetch missing values and cache them to satisfy future requests.)
getEventValues in interface BasicVarMgrInterfacedef - event definition (must be for an event); never nullintervalSelector - one of EVENT_INTERVAL_SELECTOR_xxx valuesintervalNumber - a time (as from System.currentTimeMillis())
which identifies the first interval for which data is potentially
required; if too far in the past or future then possibly no data
will be available,
zero is used to access the "all" bucketwhichValues - each true bit represents a slot for which data is
required, bit 0 indicating data from the slot within which
firstIntervalTime is located, bit 1 the previous slot, etc
public void syncVariables(boolean force)
throws java.io.IOException
When called with force==true, this acts like a full "memory barrier", flushing all write-cached items downstream immediately and afterwards getting the value of all upstream values with getVariables(-1), but may be expensive in terms of CPU or bandwidth, so use sparingly.
When called with force=false, this incrementally flushes outstanding writes and will then fetch all, or only new, values from upstream, so is potentally much less resource-intensive. In particular, this does not propagate the sync() upstream.
In any case, it is rarely the right thing for a casual user to vall this as it may be very expensive.
syncVariables in interface SimpleVariablePipelineIFforce - if true, this will force a full write flush,
a full sync upstream,
then full read with getVariables(-1),
to get the effect of a full "barrier";
otherwise, in general, a more incremental and non-propagating
mode is used which still does a write flush but may chose
to do a partial read of "new" upstream values
java.io.IOException - if one is received from upstream
public java.util.Properties getProperties(SimpleExhibitPipelineIF.PropsKey key,
long versionID)
throws java.io.IOException
getProperties in interface SimpleExhibitPipelineIFkey - selector (with possible embedded sub-key)
for desired properties set; never nullversionID - if -1 then map is always returned if available,
else must be non-negative and null is returned if the versionID
presented matches that of the current version
(ie if the caller has presumably got the up-to-date version);
may be a timestamp or a hash or other value,
and by convention is zero only for an empty properties set
java.io.IOExceptionprivate java.util.concurrent.ConcurrentHashMap<DataSourceBean.AEPLinkedKey,java.lang.Object> getStoreLinked()
public java.lang.Object getAEPLinkedValue(DataSourceBean.AEPLinkedKey key)
This is designed for good concurrency and as little locking as possible.
public java.lang.Object putAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object value)
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
public boolean replaceAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object oldValue,
java.lang.Object newValue)
Null values are not allowed.
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
public java.lang.Object removeAEPLinkedValue(DataSourceBean.AEPLinkedKey key)
public java.lang.Object putIfAbsentAEPLinkedValue(DataSourceBean.AEPLinkedKey key,
java.lang.Object value)
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
private java.util.concurrent.ConcurrentHashMap<DataSourceBean.UnlinkedKey,java.lang.Object> getStoreUnlinked()
public java.lang.Object getUnlinkedValue(DataSourceBean.UnlinkedKey key)
public java.lang.Object putUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object value)
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
public boolean replaceUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object oldValue,
java.lang.Object newValue)
Null values are not allowed.
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
public java.lang.Object removeUnlinkedValue(DataSourceBean.AEPLinkedKey key)
public java.lang.Object putIfAbsentUnlinkedValue(DataSourceBean.UnlinkedKey key,
java.lang.Object value)
This is designed for good concurrency and as little locking as possible.
This may be cleared automatically if we become very short of memory.
public ScorerCacheIF getScorerCache()
We may restrict access in future.
private void readObject(java.io.ObjectInputStream ois)
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.)
java.io.InvalidObjectException
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||