|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.props.LocalProps
public final class LocalProps
This is a set of properties local to the JVM. This is the NEAR-minimum set of properties to do with security or local system configuration (such as the local layout of the file-system) that must not or cannot be sent over the network and shared between master and slaves. Much of this is bootstrapping data, such as the location of various configuration and persistent-state directories. Our aim is to minimise the need for other parts of the system to get at random JVM system properties and files, etc, where possible.
Some of the more sensitive data are made available via package-visible members so that the other props classes can use them but nothing else can see the values directly.
These properties are not Serializable and are never sent across the network (unlike GenProps), and have to be made available in a local file and/or system properties for example. (Do not include local properties file in the WAR or EAR file.)
These properties can be checked for being up-to-date from time to time, and the in-memory values will be refreshed if necessary.
Values set purely from system properties may be collected once at class creation and not again.
All access to values is via static methods appropriately synchronized to ensure thread-safety.
This is necessarily a rag-tag of values used all over the system, and will be loaded very early and should not depend on much of the rest of the system if at all.
| Field Summary | |
|---|---|
private static java.lang.String |
confDir
Local cache of name of subdirectory for read-only conf files. |
private static java.lang.String |
dataDir
Local cache of name of subdirectory for data files. |
static float |
DEFAULT_HEAVY_LOAD_FRACTION_MIN
Min fraction of available CPUs in use for system to be considered very heavily loaded; strictly positive. |
static float |
DEFAULT_LIGHT_LOAD_FRACTION_MAX
Default max fraction of available CPUs in use for system to be considered lightly loaded; positive range ]0.0,1.0[ exclusive. |
static java.lang.String |
DEFAULT_LOCAL_PROPS_FILENAME
Default filename of local properties file. |
static java.lang.String |
DEFAULT_PROPS_SUFFIX
Default suffix of local properties files, including the dot. |
static java.lang.String |
DEFAULT_STATE_DIR
Relative path from local properties directory to persistent state dir. |
static java.lang.String |
DEFAULT_THUMBNAIL_DIR
Relative path from exhibit directory to thumbnails dir. |
private static java.lang.Float |
heavyLoadMin
CPU heavy-load threshold; can be null if none set. |
private static long |
lastRecheck
The last time that we checked/refreshed the data that we hold. |
private static java.lang.Float |
lightLoadMax
CPU light-load threshold; can be null if none set. |
private static java.lang.String |
localPropsFilenameFromSystemProperties
Cache of name of props file for local config information; null if no explicit system property value set. |
private static java.util.Set<java.io.File> |
lowerPowerFileFlags
Local cache of immutable Set of low-power file-system flags; empty if none. |
private static java.util.Set<java.net.URI> |
lowerPowerFileURIs
Local cache of immutable Set of low-power file-system flags; empty if none. |
private static java.lang.String |
microTag
Validated value of micro tag, or null if not set or not valid. |
private static int |
MIN_RECHECK_MS
Minimum interval between rechecks of local properties file content (ms). |
private static java.lang.String |
mirrorTag
Local cache of mirror tag (micro tag if set); null if none. |
private static boolean |
noGeneralFileAccess
True if this instance should make no filesystem access outside the WAR cache. |
private static java.lang.String |
persistentStateDirFromSystemProperties
Local cache of name of local persistent-state directory; null if none. |
static java.lang.String |
PNAME_CONF_DIR
Name of local properties parameter for name of subdirectory for read-only conf files. |
static java.lang.String |
PNAME_DATA_DIR
Name of local properties parameter for name of subdirectory for (mainly read-only) data files. |
static java.lang.String |
PNAME_HEAVY_LOAD_FRACTION_MIN
Name of CPU heavy-load threshold. |
static java.lang.String |
PNAME_LIGHT_LOAD_FRACTION_MAX
Name of CPU light-load threshold. |
static java.lang.String |
PNAME_LOCAL_PROPS_FILENAME
Name of props file for local config information property. |
static java.lang.String |
PNAME_LOW_POWER_FILE_FLAGS
Name of local properties parameter for Set of low-power file-system flags. |
static java.lang.String |
PNAME_LOW_POWER_FILE_URIS
Name of local properties parameter for Set of low-power remote URI http: or https: flags. |
static java.lang.String |
PNAME_MAX_UPLOAD_PER_USER_BYTES
Name of Web server maximum-upload-space-per-user (bytes) property. |
static java.lang.String |
PNAME_MAX_UPLOAD_TOTAL_BYTES
Name of Web server maximum-upload-space-total (bytes) property. |
static java.lang.String |
PNAME_MICRO_CLOUD_TAG
Name of cloud-mirror tag system property; non-null and non-empty. |
static java.lang.String |
PNAME_MIRROR_TAG
Name of mirror-tag property. |
static java.lang.String |
PNAME_PERSISTENT_STATE_DIR
Name of local directory for store of persistent state property. |
static java.lang.String |
PNAME_PERSISTENT_THUMBNAIL_DIR
Name of local directory for store of thumbnail data property. |
static java.lang.String |
PNAME_SERVER_SLOWDOWN_FACTOR
Name of server slowdown factor; strictly positive. |
static java.lang.String |
PNAME_SIMPLEPASS_FILE
Name of local properties parameter for name of simple password file. |
static java.lang.String |
PNAME_UPLOAD_DIR
Name of local properties parameter for name of upload dir. |
static java.lang.String |
PNAME_WEBSVR_MAX_EX_CACHE_BYTES
Name of Web server maximum generic exhibit cache size (64-bit value, bytes). |
static java.lang.String |
PNAME_XFER_HMAC_KEY
Name of local properties parameter for HMAC key used to protect data in transit. |
private static java.lang.String |
rawMicroTag
Raw value of micro tag, or null if not set. |
private static boolean |
reportedSecurityException
Set true if we've noted a SecurityException trying to read LocalProperties. |
private static int |
SERVER_SLOWDOWN_FACTOR
Server slowdown factor; defaults to 1 except for cloud (CPU-sensitive) environment where it is higher. |
private static java.lang.String |
simplePassfile
Local cache of name of simple password file; null if none. |
private static long |
SYS_PROP_WEBSVR_MAX_EX_CACHE_BYTES_VALUE
System-property value for maximum generic exhibit cache size; 0 if unset. |
private static java.lang.String |
thumbnailDirFromSystemProperties
Local cache of name of local thumbnail directory; null if none. |
private static long |
timestamp
The last time our loaded values changed. |
private static java.lang.String |
uploadDir
Local cache of name of upload dir; null if none specified. |
private static int |
uploadMaxBytesPerUser
Web server maximum-upload-space-per-user (bytes). |
private static int |
uploadMaxBytesTotal
Web server maximum-upload-space-total (bytes). |
private static long |
WEBSVR_MAX_EX_CACHE_BYTES
Web server maximum generic exhibit cache size (64-bit value, bytes). |
private static javax.crypto.SecretKey |
xferHMACKey
Local cache of immutable HMAC (secret) key used to protect data in transit; null if none. |
| Constructor Summary | |
|---|---|
LocalProps()
|
|
| Method Summary | |
|---|---|
private static void |
_recheck()
This routine rechecks and refreshes the data items if necessary. |
static boolean |
fastStartMode()
If true then this instance should run in 'fast start' mode. |
static java.lang.String |
getConfDir()
Get name of subdirectory for read-only conf files; never null. |
static java.lang.String |
getDataDir()
Get name of subdirectory for data files; never null. |
static float |
getHeavyLoadMin()
Get heavy-load threshold; strictly positive and always higher than the light-load-threshold. |
static float |
getLightLoadMax()
Get CPU light-load threshold; range ]0.0,1.0[ exclusive. |
private static java.lang.String |
getLocalPropsFilename()
Name of props file for local config information; never null. |
static java.util.Set<java.io.File> |
getLowerPowerFileFlags()
Get immutable Set of low-power file-system flags; empty if none. |
static java.util.Set<java.net.URI> |
getLowerPowerFileURIs()
Get immutable Set of low-power file-system URIs; empty if none. |
static java.lang.String |
getMirrorTag()
Get valid "cc-xxxx" mirror-tag name for this host; null if none. |
static boolean |
getNoGeneralFileAccess()
True if this instance should make no filesystem access outside the WAR cache. |
static java.lang.String |
getPersistentStateDir()
Get name of directory for storing local persistent state; never null. |
static int |
getServerSlowdownFactor()
Get server-slowdown-factor; strictly positive. |
static java.lang.String |
getSimplePassfile()
Get name of simple password file; null if none. |
static java.lang.String |
getThumbnailRelDir()
Get name of directory for storing off-line master thumbnails; never null. |
static long |
getTimestamp()
Returns the timestamp of the current set of data values. |
static java.lang.String |
getUploadDir()
Get name of upload dir or null if none was specified. |
static int |
getUploadMaxBytesPerUser()
Get the Web server maximum-upload-space-per-user (bytes). |
static int |
getUploadMaxBytesTotal()
Get the Web server maximum-upload-space-total (bytes). |
static long |
getWEBSVR_MAX_EX_CACHE_BYTES()
Get the Web server maximum generic exhibit cache size (64-bit value, bytes); non-negative. |
static javax.crypto.SecretKey |
getXferHMACKey()
Get HMAC (secret) key used to protect data in transit; null if none. |
static boolean |
hasXferKey()
Returns true if there is an xfer key available, false otherwise. |
static boolean |
isCloudMirrorInstance()
If true then this (WAR) instance is (permanently) configured as a light-weight cloud-hosted mirror. |
private static javax.crypto.SecretKey |
processXferKey(java.lang.String rawKeyText)
Return computed SecretKey from raw text, or null if none/invalid. |
private static java.lang.String |
validateMirrorTag(java.lang.String putativeMirrorTag)
Validate putative mirror tag; returns non-null only if input is valid and non-null. |
private static void |
vetoFileAccessIfNecessary()
Veto attempted actual or implied file access with an exception if not permitted. |
| 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 PNAME_MICRO_CLOUD_TAG
This is unqualified to help keep command-line parameters short.
private static final java.lang.String rawMicroTag
private static final java.lang.String microTag
private static final boolean noGeneralFileAccess
private static final int MIN_RECHECK_MS
(Arguably the only way that system properties can be changed is by programmatic intervention want so we don't want to recheck such values at all for fear of setting up a covert channel as well as just wasting CPU time.)
We pick a prime-ish retry interval to try to avoid collisions with other regular events.
A value of a few seconds to a few tens of seconds is probably appropriate.
private static long lastRecheck
Initially zero to force immediate read on first use of these properties.
private static volatile boolean reportedSecurityException
private static long timestamp
Will never be newer than lastRecheck.
Initially zero, to indicate no (file-based) values loaded.
The timestamp is the latest timestamp of any of the files read to make up the dataset.
public static final java.lang.String DEFAULT_PROPS_SUFFIX
public static final java.lang.String DEFAULT_LOCAL_PROPS_FILENAME
public static final java.lang.String PNAME_LOCAL_PROPS_FILENAME
private static final java.lang.String localPropsFilenameFromSystemProperties
public static final java.lang.String PNAME_DATA_DIR
private static java.lang.String dataDir
public static final java.lang.String PNAME_CONF_DIR
private static java.lang.String confDir
public static final java.lang.String PNAME_SIMPLEPASS_FILE
private static java.lang.String simplePassfile
public static final java.lang.String PNAME_UPLOAD_DIR
private static java.lang.String uploadDir
public static final java.lang.String PNAME_MAX_UPLOAD_PER_USER_BYTES
private static int uploadMaxBytesPerUser
public static final java.lang.String PNAME_MAX_UPLOAD_TOTAL_BYTES
private static int uploadMaxBytesTotal
public static final java.lang.String PNAME_PERSISTENT_STATE_DIR
private static java.lang.String persistentStateDirFromSystemProperties
public static final java.lang.String DEFAULT_STATE_DIR
public static final java.lang.String PNAME_MIRROR_TAG
private static java.lang.String mirrorTag
public static final java.lang.String PNAME_PERSISTENT_THUMBNAIL_DIR
private static final java.lang.String thumbnailDirFromSystemProperties
public static final java.lang.String DEFAULT_THUMBNAIL_DIR
public static final java.lang.String PNAME_WEBSVR_MAX_EX_CACHE_BYTES
private static final long SYS_PROP_WEBSVR_MAX_EX_CACHE_BYTES_VALUE
private static long WEBSVR_MAX_EX_CACHE_BYTES
public static final java.lang.String PNAME_SERVER_SLOWDOWN_FACTOR
private static int SERVER_SLOWDOWN_FACTOR
public static final java.lang.String PNAME_XFER_HMAC_KEY
private static javax.crypto.SecretKey xferHMACKey
public static final java.lang.String PNAME_LOW_POWER_FILE_FLAGS
private static java.util.Set<java.io.File> lowerPowerFileFlags
public static final java.lang.String PNAME_LOW_POWER_FILE_URIS
private static java.util.Set<java.net.URI> lowerPowerFileURIs
public static final float DEFAULT_LIGHT_LOAD_FRACTION_MAX
Also avoid significant extra heating or power draw.
A value of between 0.1 and (say) 0.75 is probably reasonable.
public static final java.lang.String PNAME_LIGHT_LOAD_FRACTION_MAX
private static java.lang.Float lightLoadMax
public static final float DEFAULT_HEAVY_LOAD_FRACTION_MIN
Note that there may be immediate visual effects on the Web site of exceeding this, such as an obviously-'lite' UI to reduce load, and thus doing so prematurely may be annoying to users.
Must be higher than DEFAULT_LIGHT_LOAD_FRACTION_MAX to avoid confusion, and this can be easily achieved by having a value greater than 1.0.
Keeping this significantly below 1 will not soak up all available CPU cycles but may result in better interactivity/responsiveness.
Note also that on environment such as AWS as at 2011/05 the value returned by this does not accurately indicate spare CPU available to *this* virtual instance (eg may be underlying host's uptime) so this should be ultra-conservative to help compensate in such environments.
A value of between 0.25 and (say) 5.0 is probably reasonable.
public static final java.lang.String PNAME_HEAVY_LOAD_FRACTION_MIN
private static java.lang.Float heavyLoadMin
| Constructor Detail |
|---|
public LocalProps()
| Method Detail |
|---|
public static boolean isCloudMirrorInstance()
Implications of this being true are that CPU, bandwidth and file space may all be metered, and there may be no file access outside the WAR working cache.
Fast and non-blocking.
This state does not change for a running instance.
public static boolean getNoGeneralFileAccess()
private static void vetoFileAccessIfNecessary()
java.lang.UnsupportedOperationException - to veto such attempted accessprivate static void _recheck()
When this has finished it sets lastRecheck and possibly timestamp; if this fails to complete the update neither (but especially lastRecheck) may be set.
When running as a light-weight mirror without filesystem access, any configuration information is limited to that statically available, mainly from system properties, and so this returns immediately.
private static javax.crypto.SecretKey processXferKey(java.lang.String rawKeyText)
private static java.lang.String validateMirrorTag(java.lang.String putativeMirrorTag)
public static long getTimestamp()
The timestamp is the latest timestamp of any of the files read to make up the dataset.
private static java.lang.String getLocalPropsFilename()
This will specify a file in the current working directory if none explicitly specified, and will deliver a warning if it cannot be found.
This might be bad news if the current working directory changes or is inappropriate or unhelpful, so set the system property explicitly if this is the case.
This does not check that the specified file actually exists.
We only use this internally; for example this may be inefficient to continually recheck and we don't necessarily want to publicise the actual location more than we must!
java.lang.UnsupportedOperationException - if this is a light-weight mirror
and thus without general filesystem accesspublic static java.lang.String getDataDir()
The returned value is not necessarily canonical to avoid prodding/waking any filesystems unnecessarily.
java.lang.UnsupportedOperationException - if this is a light-weight mirror
and thus without general filesystem accesspublic static java.lang.String getConfDir()
java.lang.UnsupportedOperationException - if this is a light-weight mirror
and thus without general filesystem accesspublic static java.lang.String getSimplePassfile()
If the path supplied is not absolute, it is made relative to the result of getConfDir().
public static java.lang.String getUploadDir()
If a directory is specified but is not absolute, it is taken to be relative to the directory the local properties are in.
Warns if the specified directory is not present, but returns the path anyway if a path was specified; the caller should check if it is usable.
java.lang.UnsupportedOperationException - if this is a light-weight mirror
and thus without general filesystem accesspublic static int getUploadMaxBytesPerUser()
public static int getUploadMaxBytesTotal()
public static final java.lang.String getPersistentStateDir()
If the system property is not set, then we take this relative to the directory in which we look for the local properties.
Warns if the specified directory is not present.
java.lang.UnsupportedOperationException - if this is a light-weight mirror
and thus without general filesystem accesspublic static final java.lang.String getMirrorTag()
The entire tag is a lower-case printable ASCII (no whitespace) alphanumeric value.
This host should be reachable by the full name of "mirror-cc-xxxx.gallery.hd.org" for a tag of "cc-xxxx" and a main domain name of "gallery.hd.org".
This routine will not return an invalid/unsafe tag.
This routine does NOT attempt any DNS lookups or in other ways attempt to verify that the full mirror host name exists or is valid.
public static final java.lang.String getThumbnailRelDir()
If the system property is not set, then we take this relative to the directory in which we look for the exhibits.
If the property is set to "." then the exhibit directory is used.
public static long getWEBSVR_MAX_EX_CACHE_BYTES()
This value can be specified with a system property of the same name if no value is supplied in the properties file.
public static int getServerSlowdownFactor()
Is a factor by which the server under-reports its available capacity, etc.
When > 1 then this has the effect of:
public static javax.crypto.SecretKey getXferHMACKey()
This first attempts to initialised from the system property then any value in the local properties file overrides this.
The key returned is immutable.
The key should be handled with care, since it is sensitive data.
public static boolean hasXferKey()
public static java.util.Set<java.io.File> getLowerPowerFileFlags()
public static java.util.Set<java.net.URI> getLowerPowerFileURIs()
public static final float getLightLoadMax()
public static float getHeavyLoadMin()
public static boolean fastStartMode()
Useful for critical customer-facing machines where start-up latency should be minimised.
Enabled by setting the system property "org.hd.d.pg2k.faststart" to true or by being a light-weight cloud instance.
Defaults to false.
Is a method rather than a field to reduce class-initialisation circularity issues, so is possibly a little expensive to test continuously.
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||