org.hd.d.pg2k.clApp.atHome
Class AHStandaloneMain.FakeTunnel

java.lang.Object
  extended by org.hd.d.pg2k.clApp.atHome.AHStandaloneMain.FakeTunnel
All Implemented Interfaces:
SimpleExhibitPipelineIF, BasicVarMgrInterface, SimpleVariablePipelineIF
Enclosing class:
AHStandaloneMain

private static final class AHStandaloneMain.FakeTunnel
extends java.lang.Object
implements SimpleExhibitPipelineIF

Fake data source cobbled together to just support the actions that some Scorers and their support need. Blocks all other activity, and does not have a real tunnel back to the server at all.

This fakes the fetching of thumbnails (on demand) using their normal URLs.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.hd.d.pg2k.svrCore.datasource.SimpleExhibitPipelineIF
SimpleExhibitPipelineIF.PropsKey
 
Field Summary
private  java.util.Map<Name.ExhibitFull,ExhibitThumbnails> _tnCache
          Thread-safe thumbnail cache, holding thumbnails for the calibration set.
private  java.util.concurrent.atomic.AtomicInteger _tnDownloadCount
          Thumbnail fetch count; watch those calories^Wbytes.
private  java.util.Map<Name.ExhibitFull,java.lang.Long> _tnNotFetchBefore
          Thread-safe cache for time before retry of thumbnail fetch is allowed.
private  AllExhibitImmutableData aeid
          Cache of AEID value; never null.
private  java.io.File cacheDir
          Handle on local cache dir; null if none.
private  GenProps gp
          Empty GP value; never null.
private  java.lang.String hostnameAndOptionalPort
          Hostname of our server to fetch thumbnails from; never null.
private  SimpleLoggerIF log
          Logger; never null.
private static int MIN_TN_RETRY_MS
          Minimum wait before retrying thumbnail fetch from server, ms; strictly positive.
private  java.util.Set<java.lang.String> supportedExhibits
          Immutable (atomically-replacable) current set of full exhibit names that we support; never null.
private  java.lang.Object tnFetchLock
          Serialise thumbnail fetches, ie limit calls back to server, on this lock.
 
Fields inherited from interface org.hd.d.pg2k.svrCore.datasource.SimpleExhibitPipelineIF
MAX_USER_READ_SIZE
 
Constructor Summary
AHStandaloneMain.FakeTunnel(java.lang.String hostnameAndOptionalPort, SimpleLoggerIF log, java.io.File cacheDir)
          Construct an instance, given the hostname and optional port.
 
Method Summary
 void destroy()
          Shut down the data pipeline.
 AllExhibitImmutableData getAllExhibitImmutableData(long oldStamp)
          Gets set of all static exhibit data if its timestamp is not that specified.
 AllExhibitProperties getAllExhibitProperties(long oldHash)
          AEP is too expensive (large, slow) to fetch and is more than we need, so forbid it.
 EventVariableValue getEventValue(SimpleVariableDefinition def, EventPeriod intervalSelector, boolean current)
          Always return empty values.
 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; never null for -1 argument.
 java.util.Properties getGenSecProps(long oldStamp)
          Gets the generic security properties as a Properties object if its timestamp is not that specified.
 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)
          Read a chunk of the raw exhibit binary into the given buffer.
 ExhibitStaticAttr getStaticAttr(Name.ExhibitFull name)
          Get the static attributes for a given exhibit.
 Stratum getStratum()
          Gets information about our stratum and upstream server; never null.
 ExhibitThumbnails getThumbnails(Name.ExhibitFull fullName, boolean create)
          Get std thumbnail; returns null if not currently available.
 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.
 void poll(GenProps gp)
          Poll periodically (of the order of seconds) to do background work.
(package private)  void setSupportedExhibits(java.util.Set<java.lang.String> s)
          Set/update the current set of full exhibit names.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hostnameAndOptionalPort

private final java.lang.String hostnameAndOptionalPort
Hostname of our server to fetch thumbnails from; never null.


log

private final SimpleLoggerIF log
Logger; never null.


cacheDir

private final java.io.File cacheDir
Handle on local cache dir; null if none.


supportedExhibits

private volatile java.util.Set<java.lang.String> supportedExhibits
Immutable (atomically-replacable) current set of full exhibit names that we support; never null.


aeid

private volatile AllExhibitImmutableData aeid
Cache of AEID value; never null.


gp

private final GenProps gp
Empty GP value; never null.


_tnDownloadCount

private final java.util.concurrent.atomic.AtomicInteger _tnDownloadCount
Thumbnail fetch count; watch those calories^Wbytes.


MIN_TN_RETRY_MS

private static final int MIN_TN_RETRY_MS
Minimum wait before retrying thumbnail fetch from server, ms; strictly positive.

See Also:
Constant Field Values

_tnNotFetchBefore

private final java.util.Map<Name.ExhibitFull,java.lang.Long> _tnNotFetchBefore
Thread-safe cache for time before retry of thumbnail fetch is allowed.


_tnCache

private final java.util.Map<Name.ExhibitFull,ExhibitThumbnails> _tnCache
Thread-safe thumbnail cache, holding thumbnails for the calibration set.


tnFetchLock

private final java.lang.Object tnFetchLock
Serialise thumbnail fetches, ie limit calls back to server, on this lock.

Constructor Detail

AHStandaloneMain.FakeTunnel

AHStandaloneMain.FakeTunnel(java.lang.String hostnameAndOptionalPort,
                            SimpleLoggerIF log,
                            java.io.File cacheDir)
Construct an instance, given the hostname and optional port.

Method Detail

setSupportedExhibits

void setSupportedExhibits(java.util.Set<java.lang.String> s)
Set/update the current set of full exhibit names.


destroy

public void destroy()
Description copied from interface: SimpleExhibitPipelineIF
Shut down the data pipeline. Free resources having saved any persistent state and shut down any upstream components.

Specified by:
destroy in interface SimpleExhibitPipelineIF

getAllExhibitImmutableData

public AllExhibitImmutableData getAllExhibitImmutableData(long oldStamp)
                                                   throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Gets set of all static exhibit data if its timestamp is not that specified. If the time specified is negative the object will be returned unconditionally.

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.

Specified by:
getAllExhibitImmutableData in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

getAllExhibitProperties

public AllExhibitProperties getAllExhibitProperties(long oldHash)
                                             throws java.io.IOException
AEP is too expensive (large, slow) to fetch and is more than we need, so forbid it.

Specified by:
getAllExhibitProperties in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

getGenProps

public GenProps getGenProps(long oldStamp)
                     throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Gets the general properties as a GenProps object if its timestamp is not that specified; never null for -1 argument. If the time specified is negative the object will be returned unconditionally.

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) null is returned.

Specified by:
getGenProps in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

getGenSecProps

public java.util.Properties getGenSecProps(long oldStamp)
                                    throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Gets the generic security properties as a Properties object if its timestamp is not that specified. If the time specified is negative the object will be returned unconditionally.

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) null is returned.

Specified by:
getGenSecProps in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

getProperties

public java.util.Properties getProperties(SimpleExhibitPipelineIF.PropsKey key,
                                          long versionID)
                                   throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Get requested Properties selected by key and versionID. Fetches a Properties set unconditionally (versionID == -1) else if the versionID presented is not current.

Specified by:
getProperties in interface SimpleExhibitPipelineIF
Parameters:
key - selector (with possible embedded sub-key) for desired properties set; never null
versionID - 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
Returns:
null, or Properties map guaranteed to contain only String keys and values
Throws:
java.io.IOException

getRawFile

public void getRawFile(java.nio.ByteBuffer buf,
                       Name.ExhibitFull exhibitName,
                       int position,
                       boolean dontCache)
                throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Read a chunk of the raw exhibit binary into the given buffer. The call may return less than the the buffer capacity, though will block until it has read at least one byte unless at EOF or for a zero-byte request; this will be clear from the state of the buffer.

Specified by:
getRawFile in interface SimpleExhibitPipelineIF
Parameters:
buf - 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 bytes
exhibitName - the full name of the exhibit to read from; never null and must be syntactically valid
position - position/index of first byte in exhibitFile to read; non-negative
dontCache - 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
Throws:
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

getStaticAttr

public ExhibitStaticAttr getStaticAttr(Name.ExhibitFull name)
                                throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Get the static attributes for a given exhibit. Returns null if the named exhibit does not exist.

Specified by:
getStaticAttr in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

poll

public void poll(GenProps gp)
          throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Poll periodically (of the order of seconds) to do background work. The current generic system properties are passed in...

Specified by:
poll in interface SimpleExhibitPipelineIF
Throws:
java.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

syncVariables

public void syncVariables(boolean force)
                   throws java.io.IOException
Description copied from interface: SimpleVariablePipelineIF
Synchronise variables with upstream values. Pushes updated values upstream to the source, calls sync on the source if called with the "force" argument true, and then retrieves changed values from upstream.

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 potentially 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 call this as it may be very expensive.

Specified by:
syncVariables in interface SimpleVariablePipelineIF
Parameters:
force - 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
Throws:
java.io.IOException - if one is received from upstream

getEventValue

public EventVariableValue getEventValue(SimpleVariableDefinition def,
                                        EventPeriod intervalSelector,
                                        boolean current)
Always return empty values.

Specified by:
getEventValue in interface BasicVarMgrInterface
Parameters:
def - event definition (must be for an event); never null
intervalSelector - never null
current - if true the current event set is returned, else the previous complete set is returned
Returns:
requested event set; never null

getEventValues

public EventVariableValue[] getEventValues(SimpleVariableDefinition def,
                                           EventPeriod intervalSelector,
                                           long intervalNumber,
                                           java.util.BitSet whichValues)
Description copied from interface: BasicVarMgrInterface
Get the specified event sets for the specified intervals; never null. This allows retrieval of zero or more event sets for the specified interval size.

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. However, if unable to fetch authoritative data (quickly) then we will return null or non-authoritative data as appropriate for each slot; this does not throw IOException.

Specified by:
getEventValues in interface BasicVarMgrInterface
Parameters:
def - event definition (must be for an event); never null
intervalSelector - never null
intervalNumber - the number of 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 select the "all" bucket
whichValues - 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; null is treated as the common case equivalent to just bit 0 set
Returns:
as many of the requested values as available, with as many of them authoritative as possible, with [0] corresponding to bit 0 in the BitSet, ie newest entry first and oldest last in the array; may contain nulls or be zero-length (or over-sized) but never null

getVariable

public SimpleVariableValue getVariable(SimpleVariableDefinition var)
                                throws java.io.IOException,
                                       java.lang.UnsupportedOperationException
Description copied from interface: BasicVarMgrInterface
Get a single variable value; returns null if no such value or wrong type. Implementations should, where possible, trim from the globalMap of returned values any apparently-stale data, so as to return only reasonably-live data to the caller.

Only the last event value for a given event variable is returned by this method.

Specified by:
getVariable in interface BasicVarMgrInterface
Parameters:
var - definition of variable to fetch; never null
Throws:
java.io.IOException - in case of I/O difficulty
java.lang.UnsupportedOperationException - if a variable is requested that we could never supply, eg a non-System-ID local variable at the client end of a tunnel

getVariables

public SimpleVariableValue[] getVariables(long changedSince)
                                   throws java.io.IOException
Description copied from interface: BasicVarMgrInterface
Get set of variable values altered on or after specified time, or get all values with -1; never null. This may be slow if there are many live variables.

Only the last event value of each event variable is returned by this method.

Specified by:
getVariables in interface BasicVarMgrInterface
Throws:
java.io.IOException - in case of I/O difficulty

setVariable

public void setVariable(SimpleVariableValue newValue)
                 throws java.io.IOException,
                        java.lang.UnsupportedOperationException
Description copied from interface: BasicVarMgrInterface
Set variable to the given value (the variable name and definition are implicit). The value set should be immediately readable with getVariable() as the "main" value of the variable even for global variables.

This is also used to send events, the last event value being the variable's value.

Specified by:
setVariable in interface BasicVarMgrInterface
Throws:
java.io.IOException - in case of I/O difficulty
java.lang.UnsupportedOperationException - if a variable is set that we could never handle, eg a non-System-ID local variable at the client end of a tunnel

setVariables

public int setVariables(SimpleVariableValue[] newValues)
                 throws java.io.IOException
Description copied from interface: BasicVarMgrInterface
Update a number of variables at once for efficiency; returns the number of variables set. Is passed a set of SimpleVariableValues and behaves as if it operates on all of them by calling setVariable() for each item in the set.

Furthermore 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)

Specified by:
setVariables in interface BasicVarMgrInterface
Returns:
the number of variable values set (the length of the array); never negative, never more than the number passed in
Throws:
java.io.IOException

getStratum

public Stratum getStratum()
                   throws java.io.IOException
Description copied from interface: SimpleExhibitPipelineIF
Gets information about our stratum and upstream server; never null.

Specified by:
getStratum in interface SimpleExhibitPipelineIF
Throws:
java.io.IOException

getThumbnails

public ExhibitThumbnails getThumbnails(Name.ExhibitFull fullName,
                                       boolean create)
                                throws java.io.IOException
Get std thumbnail; returns null if not currently available. Fetched only if part of the calibration set; cached too if so.

Specified by:
getThumbnails in interface SimpleExhibitPipelineIF
create - if true, and no thumbnail yet exists, try to create one if possible, else if create is false only return an existing one and return null if none is to hand
Throws:
java.io.IOException - if the operation cannot be completed due to I/O restrictions or failure

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.