|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.clApp.uploader.UploaderLogic
final class UploaderLogic
Uploader "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 | |
|---|---|
private class |
UploaderLogic.UploaderWorkerThread
Uploader worker thread. |
(package private) static class |
UploaderLogic.UploadStatus
Details of one selected file being uploaded; immutable except for progress value. |
| Field Summary | |
|---|---|
private AllExhibitProperties |
aep
Exhibit properties; never null. |
private static int |
AEP_EXPANSION_BYTES
Number of bytes of expansion room we allow for one growth in the AEP; non-negative. |
(package private) javax.jnlp.BasicService |
bs
Handle on JWS basic service; null if none. |
private java.lang.Boolean |
connectionGood
Note of polled connection state; TRUE is good, FALSE is bad, null is unknown. |
(package private) java.lang.String |
DEFAULT_EXHIBIT_NAME
Default exhibit name when there is an empty AEP. |
(package private) javax.jnlp.ExtendedService |
exs
Handle on JWS extended service; null if none. |
private static java.lang.String |
FNAME_AEP
Name under the codebase where we persist the AEP. |
private static java.lang.String |
FNAME_MAIN_PROPS
Name under the codebase where we persist the properties/preferences. |
(package private) javax.jnlp.FileOpenService |
fos
Handle on JWS file-open service; null if none. |
private GenProps |
gp
Generic properties; never null. |
private UploaderLogic.UploadStatus[] |
inProgressSlots
Our current uploads-in-progress; never null and always MAX_CONC_UPLOADS long. |
private long |
lastAEPUpdatePoll
Time we last polled for GP/AEP updates. |
(package private) SimpleLoggerIF |
logger
Reference to central logger; never null. |
private static int |
MAX_AEP_POLL_MS
Maximum interval between polls for new values of AEP (and GP); strictly positive. |
(package private) static int |
MAX_CONC_UPLOADS
Maximum simultaneous uploads (to overcome network latency, etc); strictly positive. |
private java.lang.String |
passwd
Our private note of the password supplied. |
(package private) UploaderProps |
props
Persistence properties; never null. |
(package private) javax.jnlp.PersistenceService |
ps
Handle on JWS persistence service; null if none. |
(package private) SelectedFilesDB |
selectedFiles
Database of selected files; never null. |
(package private) javax.jnlp.SingleInstanceService |
sis
Handle on JWS singleton service; null if none. |
private java.util.concurrent.atomic.AtomicLong |
smoothedUploadSpeedBps
Current smoothed upload performance in bytes-per-second, initially -1; never null. |
private static int |
TC_SUSB
Time-constant for updating smoothedUploadSpeedBps; strictly positive. |
(package private) ExhibitDataHTTPTunnelSource |
tunnel
Our end of main tunnel to server; null if no tunnel possible. |
private java.util.Set<ROByteArray> |
uploadedHashesMD5
Set of MD5 hashes of exhibits already uploaded (or rejected as duplicate content); never null. |
private java.util.List<java.lang.Thread> |
uploaderWorkerThreads
Our (daemon) uploader worker threads started by startup(); never null. |
(package private) SelectedFilesDB |
uploadingFiles
Database of files queued for upload; never null. |
private java.lang.String |
userID
Our private copy of the (less sensitive) valid user ID, or null if none or invalid ID/pass presented. |
private boolean |
userIDChanged
Set whenever the userID changes; cleared when we have attempted to test the connection. |
private long |
userLastActive
Last time the user was active in this run, eg in the UI; initially zero. |
| Constructor Summary | |
|---|---|
UploaderLogic(SimpleLoggerIF logger)
Package-visible constructor since need be seen only by the main GUI class. |
|
| Method Summary | |
|---|---|
(package private) java.lang.String |
addSelectedFiles(boolean autoGuessFormat,
javax.jnlp.FileContents[] files,
UploadInfoBean uib)
Propose/select/add selected files for upload. |
private void |
cacheAEP(AllExhibitProperties aepToSave)
Save/cache local copy of AEP in persistent store. |
(package private) boolean |
checkIfAlreadyUploadedByHashMD5(ROByteArray hashMD5)
Check (using the content MD5 hash) if a putative exhibit has already been uploaded (or rejected as duplicate content). |
(package private) AllExhibitProperties |
getAep()
Get the current AEP (exhibit properties); never null. |
(package private) int |
getCompletedUploadsThisSession()
Get number of exhibits successfully uploaded this session; non-negative. |
(package private) GenProps |
getGenProps()
Get the current set of GenProps (generic system properties); never null. |
(package private) UploaderLogic.UploadStatus |
getInProgressSlot(int index)
Get the current contents of an in-progress slot; may return null. |
(package private) long |
getSmoothedUploadSpeedBps()
Get current smoothed upload performance in bytes-per-second, initially -1. |
long |
getUserLastActive()
Get the last time the user was active in this run, eg in the UI; initially zero. |
private static java.net.URL |
makeAEPURL(javax.jnlp.BasicService bs)
Make the AEP persistence URL; only viable when in JWS/JNLP. |
private static java.net.URL |
makePropsURL(javax.jnlp.BasicService bs)
Make the props persistence URL; only viable when in JWS/JNLP. |
(package private) void |
poll()
Called (by a daemon thread) to perform async activity. |
private void |
saveProperties()
Save persistent properties (if possible). |
(package private) void |
setAuthenticationInfo(java.lang.String userID,
char[] passwd)
Set authentication information for this user. |
(package private) void |
setUserLastActive(java.lang.String doingWhat)
Note user as active. |
(package private) boolean |
shortNameValidAndUnique(java.lang.String newShortName)
Returns true if this (short) exhibit name is valid and unique. |
(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. |
(package private) void |
uibIncNumberIfNotZeroWhileNotUnique(UploadInfoBean uib)
If our name is not unique then increment the number-in-series (if non-zero) until we get a unique name. |
private void |
updateSmoothedUploadSpeedBps(long Bps)
Update our notion of mean upload speed (in bytes per second). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
final SimpleLoggerIF logger
final UploaderProps props
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
final ExhibitDataHTTPTunnelSource tunnel
private static final int TC_SUSB
A value of 1 gives no smoothing at all.
A power of two may result in very slightly faster computations.
A value in the range 2 to 64 is probably good.
private final java.util.concurrent.atomic.AtomicLong smoothedUploadSpeedBps
This represents a conservative performance measure, ie including overheads such as connection set-up time, but not dead time between uploads.
AtomicLong allows thread-safe lockless access for read and write.
private final java.util.Set<ROByteArray> uploadedHashesMD5
Private so as to prevent accidental deletion of entries!
Thread-safe.
static final int MAX_CONC_UPLOADS
private final java.util.List<java.lang.Thread> uploaderWorkerThreads
private final UploaderLogic.UploadStatus[] inProgressSlots
A slot is empty when not in use; all slots are initially empty.
Private so as to prevent accidental deletion of entries!
All access to the contents of this array should grab a lock on this array to ensure that an up-to-date/valid view is seen.
Worker threads keep a lock on this while looking for a file to start uploading, and thus the uploadingFiles instance lock may be grabbed inside this one; the reverse is not allowed so as to avoid deadlocks.
private static final java.lang.String FNAME_MAIN_PROPS
private static final java.lang.String FNAME_AEP
final SelectedFilesDB selectedFiles
Thread-safe.
final SelectedFilesDB uploadingFiles
Thread-safe.
private volatile long userLastActive
final java.lang.String DEFAULT_EXHIBIT_NAME
private volatile java.lang.String userID
private volatile java.lang.String passwd
private volatile boolean userIDChanged
This is simply a device to try to get a new user ID/passwd tested quietly in the background.
private volatile AllExhibitProperties aep
Volatile so as to be safe to access without a lock if need be.
private volatile GenProps gp
Volatile so as to be safe to access without a lock if need be.
private volatile java.lang.Boolean connectionGood
Volatile so as to be safe to access without a lock if need be.
private volatile long lastAEPUpdatePoll
Volatile so as to be safe to access without a lock if need be.
private static final int MAX_AEP_POLL_MS
Short enough to capture an AEP generated asynchronously for us at the server side of the HTTP tunnel.
We may suspend polling entirely if the UI/app appears to be idle.
private static final int AEP_EXPANSION_BYTES
Should typically allow for a few days' growth as new exhibits are added.
| Constructor Detail |
|---|
UploaderLogic(SimpleLoggerIF logger)
logger - reference to central logger; never null| Method Detail |
|---|
final long getSmoothedUploadSpeedBps()
This represents a conservative performance measure, ie including overheads such as connection set-up time, but not dead time between uploads.
This is thread-safe and lock-free.
Package-visible to allow access by GUI classes.
private void updateSmoothedUploadSpeedBps(long Bps)
This will be used to update a smoothed performance measure.
This tries to allow for concurrent uploads, ie where the total throughput is shared by several workers.
This is thread-safe and lock-free.
Bps - non-negative speed of upload in bytes per secondboolean checkIfAlreadyUploadedByHashMD5(ROByteArray hashMD5)
int getCompletedUploadsThisSession()
UploaderLogic.UploadStatus getInProgressSlot(int index)
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.
void 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 static java.net.URL makePropsURL(javax.jnlp.BasicService bs)
throws java.io.IOException
java.io.IOException
private static java.net.URL makeAEPURL(javax.jnlp.BasicService bs)
throws java.io.IOException
java.io.IOException
void setAuthenticationInfo(java.lang.String userID,
char[] passwd)
Package-visible so as to be directly usable by the main GUI class.
Ignored if there is no tunnel.
AllExhibitProperties getAep()
GenProps getGenProps()
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 cacheAEP(AllExhibitProperties aepToSave)
throws java.io.IOException
This save may be prevented on grounds of size, etc, by the JNLP runtime.
This should NOT be called by more than one thread at once.
aepToSave - AEP to save; usually not null
java.io.IOExceptionboolean shortNameValidAndUnique(java.lang.String newShortName)
void uibIncNumberIfNotZeroWhileNotUnique(UploadInfoBean uib)
java.lang.String addSelectedFiles(boolean autoGuessFormat,
javax.jnlp.FileContents[] files,
UploadInfoBean uib)
Duplicate entries may be silently discarded.
Package-visible to be callable from GUI classes.
autoGuessFormat - if true then the routine may try to guess the
type/format of files that do not match the type implied by the namefiles - one (or more if the number-in-series is not zero) files
that the user has selected for upload;
never null not zero-size no containing nullsuib - initialised with the first/desired name;
never null and must be in a state where enoughValidUniqueInfo()==true
private void saveProperties()
void shutdown()
Package-visible so as to be directly usable 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 | ||||||||