|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.clApp.atHome.AHStandaloneMain
public final class AHStandaloneMain
Core of at-home program: suitable to drive from a bare command-line or better. This can also form the core of a more-sophisticated GUI-based (eg JWS) app.
| Nested Class Summary | |
|---|---|
private static class |
AHStandaloneMain.Callback
Container of various items of information we need to run the worker threads. |
private static class |
AHStandaloneMain.FakeTunnel
Fake data source cobbled together to just support the actions some Scorers and their support need. |
| Field Summary | |
|---|---|
private static java.lang.Object |
_submitLock
Lock used to serialise new/best Scorer submissions back to the server; never null. |
private static boolean |
ALLOW_FILESYSTEM_TNCACHE
If true then attempt to use a primitive filesystem thumbnail/data cache where permitted. |
(package private) javax.jnlp.BasicService |
bs
Handle on JWS basic service; null if none. |
private AHStandaloneMain.Callback |
cb
Callback object for reporting new/best Scorer; never null. |
private int |
chunkMs
Target CPU work chunk in ms; strictly positive. |
static java.lang.String |
DATA_BLOCK_END
End sequence; we look for a line containing this to start our data. |
static java.lang.String |
DATA_BLOCK_START
Start sequence; we look for a line containing this to start our data. |
static int |
DEFAULT_CPU_CHUNK_MS
Default target CPU work chunk in ms; strictly positive. |
static int |
DEFAULT_CPU_PERCENT
Default target fractional CPU usage (of entire host) in exclusive range ]1,100[, ie strictly positive. |
private static java.lang.String |
DEFAULT_SERVER
Default server host name to connect back to; the generic/main host in this case. |
private static java.lang.String |
DEFAULT_TNCACHE_DIR
Default directory in which cache thumbnail/playback data; always relative to pwd/cwd. |
static SimpleLoggerIF |
defaultLogger
Default logger: writes to stdout. |
(package private) javax.jnlp.ExtendedService |
exs
Handle on JWS extended service; null if none. |
private AHStandaloneMain.FakeTunnel |
fakeTunnel
Synthetic data pipeline tunnel back to server; never null. |
(package private) javax.jnlp.FileOpenService |
fos
Handle on JWS file-open service; null if none. |
private int |
genTimeRemaining
Time remaining for this generation; reset if a new/best Scorer is found. |
private static java.lang.String |
GETDATA_METHOD
Method to use in getData() to connect to server (POST or GET). |
private long |
lastFetchedCalibrationData
Last time we polled the server for calibration data. |
private ScoreAndConf |
lastSAC
Score/confidence of last Scorer reported; never null. |
private SimpleLoggerIF |
log
Logger; never null. |
static int |
MIN_GENERATION_MS
Minimum time (in ms) spent working on one generation; strictly positive. |
static int |
MIN_SCORER_SERVER_REPORT_GAP_MS
Minimum time between reports back to the server; strictly positive but much less than MIN_GENERATION_MS. |
private int |
percentCPU
Target percent CPU usage (of all CPUs in host machine) in exclusive range ]1,100[, ie strictly positive. |
private static boolean |
PLAYBACK_NO_NET
If true then use playback calibration/thumbnail data rather than attempting to connect to the server. |
private static boolean |
PLAYBACK_SAVE_DATA
If true then save/record calibration data received from server. |
private boolean |
pleaseQuit
Set to try to force main loop to quit ASAP, never set back to false. |
(package private) javax.jnlp.PersistenceService |
ps
Handle on JWS persistence service; null if none. |
private java.util.concurrent.atomic.AtomicInteger |
scorersReported
Number of Scorers reported back home (ignoring failures); never null, never negative. |
private java.lang.String |
serverHostname
Server host name; never null. |
(package private) javax.jnlp.SingleInstanceService |
sis
Handle on JWS singleton service; null if none. |
private java.lang.String |
tunnelURL
Full URL for dedicated 'AH' tunnel on server; never null. |
private java.util.concurrent.ThreadPoolExecutor |
workerThreadPoolDiscardable
Thread pool; reconfigurable at run-time; never null. |
| Constructor Summary | |
|---|---|
AHStandaloneMain(SimpleLoggerIF log)
Create worker instance with all defaults and the supplied logger. |
|
AHStandaloneMain(java.lang.String serverHostname,
SimpleLoggerIF log,
int percentCPU,
int chunkMs)
Create worker instance with the suppied logger and other parameters. |
|
| Method Summary | |
|---|---|
(package private) void |
doWork()
Simple core worker routine, usually runs until JVM terminates. |
private java.io.File |
getCacheDir()
Get filesystem-based thumbnail/data cache directory, or null if none. |
private Tuple.Pair<java.util.Set<java.lang.String>,java.util.Map<java.lang.String,ScoreAndConf>> |
getCalibrationSet(java.lang.String tunnelURL,
java.lang.String baseName)
Get calibration data from server; never null but may be empty. |
(package private) int |
getCalibrationSetSize()
Get size of current calibration set, or zero if none. |
private java.util.List<java.lang.String> |
getData(java.lang.String tunnelURL,
java.lang.String dataType,
java.lang.String q)
Fetch specified ordered records from server; may be empty but never null. |
(package private) int |
getGeneration()
Get generation number; strictly positive. |
(package private) int |
getGenTimeRemaining()
Get time remaining for this generation; reset if a new/best Scorer is found. |
(package private) ScoreAndConf |
getLastSAC()
Get score/confidence of last Scorer reported; never null. |
(package private) int |
getPopulationSize()
Allow polling for population size; non-negative. |
(package private) int |
getScorersReported()
Get number of Scorers reported back home; never negative. |
(package private) int |
getTargetPercentCPU()
Get current target CPU load percentage in range ]1,100[. |
static void |
main(java.lang.String[] args)
Command-line start-up. |
private static boolean |
sendNewBestScorer(java.lang.String tunnelURL,
java.lang.String scorerNameAndParameters,
SimpleLoggerIF log)
Send the new Scorer back to the server. |
(package private) void |
setTargetPercentCPU(int pc)
Set current target CPU load percentage in range ]1,100[. |
void |
shutdown()
Try to shut down quickly and gracefully and with minimal loss of work. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final SimpleLoggerIF defaultLogger
private static final java.lang.String DEFAULT_SERVER
public static final int DEFAULT_CPU_PERCENT
public static final int DEFAULT_CPU_CHUNK_MS
A sub-1s value may look less weird/lumpy on a user's CPU meter (given a typical 1s sampling on GUI performance meters).
private static final boolean ALLOW_FILESYSTEM_TNCACHE
This may save a great deal of bandwidth avoiding refetching thumbnails.
The cache may also be prepopulated for stand-alone tests.
This cache is flat, ie contains no subdirectories, and will not be used unless already extant with appropriate permissions.
This may need to be periodically manually cleared of stale/old/bulk/corrupt data, and may become inefficient if it gains many entries.
private static final java.lang.String DEFAULT_TNCACHE_DIR
private static final boolean PLAYBACK_SAVE_DATA
Not viable/safe for JWS mode.
Should not be used (true) when PLAYBACK_NO_NET is true.
private static final boolean PLAYBACK_NO_NET
private final java.lang.String serverHostname
private final SimpleLoggerIF log
private volatile int percentCPU
private volatile int chunkMs
final javax.jnlp.BasicService bs
final javax.jnlp.PersistenceService ps
final javax.jnlp.FileOpenService fos
final javax.jnlp.SingleInstanceService sis
final javax.jnlp.ExtendedService exs
private final java.util.concurrent.ThreadPoolExecutor workerThreadPoolDiscardable
private volatile long lastFetchedCalibrationData
Marked volatile for thread-safe lock-free access.
public static final java.lang.String DATA_BLOCK_START
public static final java.lang.String DATA_BLOCK_END
private static final java.lang.String GETDATA_METHOD
private static final java.lang.Object _submitLock
private final java.lang.String tunnelURL
private final AHStandaloneMain.FakeTunnel fakeTunnel
private final AHStandaloneMain.Callback cb
private final java.util.concurrent.atomic.AtomicInteger scorersReported
private volatile ScoreAndConf lastSAC
private volatile int genTimeRemaining
public static final int MIN_GENERATION_MS
A value in the range of minutes to hours is probably appropriate.
public static final int MIN_SCORER_SERVER_REPORT_GAP_MS
Should be small enough to minimise any chance of significant work loss with unexpected shutdown.
private volatile boolean pleaseQuit
| Constructor Detail |
|---|
AHStandaloneMain(SimpleLoggerIF log)
Package-visible to be exposed only to this package.
AHStandaloneMain(java.lang.String serverHostname,
SimpleLoggerIF log,
int percentCPU,
int chunkMs)
Package-visible to be exposed only to this package.
| Method Detail |
|---|
public static void main(java.lang.String[] args)
Writes any log/status information to stdout.
Defaults to take ~50% of available CPU.
args - an optional first argument is interpretted as serverhost[:port]private java.io.File getCacheDir()
private java.util.List<java.lang.String> getData(java.lang.String tunnelURL,
java.lang.String dataType,
java.lang.String q)
throws java.io.IOException
q - if not null, part to pass as the generic (query) parameter (will be URL encoded)
java.io.IOException
private Tuple.Pair<java.util.Set<java.lang.String>,java.util.Map<java.lang.String,ScoreAndConf>> getCalibrationSet(java.lang.String tunnelURL,
java.lang.String baseName)
throws java.io.IOException
baseName - valid Scorer base name supported by current cache/population
java.io.IOException
private static boolean sendNewBestScorer(java.lang.String tunnelURL,
java.lang.String scorerNameAndParameters,
SimpleLoggerIF log)
tunnelURL - the full URL for the tunnel servlet; never nullscorerNameAndParameters - the Scorer description to send to the server
int getTargetPercentCPU()
void setTargetPercentCPU(int pc)
We also adjust the CPU chunk size for better scheduling and CPU behaviour at extremes.
pc - target percent CPU time in the range 1 to 100.int getGeneration()
int getPopulationSize()
int getCalibrationSetSize()
final int getScorersReported()
ScoreAndConf getLastSAC()
int getGenTimeRemaining()
void doWork()
Will quit immediately if it cannot "call home" when it starts up. Thereafter it will retry to overcome errors as necessary.
Not thread-safe (ie only one thread should call this at once for this instance).
Package-visible to be exposed only to this package.
public void shutdown()
|
DHD Multimedia Gallery V1.50.55 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||