Class AbstractUpdateServiceImpl
- All Implemented Interfaces:
Remote, UpdateService
Derives the update info purely from a naming convention below the update base URL:
<updateURL>/<artifactName>-<version>-<platform>-<architecture>[-pkg].zip <updateURL>/<artifactName>-<version>-<platform>-<architecture>[-pkg].sha256where
-pkg denotes a jpackage installation. The checksum hashes and the (known) download sizes
are cached per URL, so the HTTP server is contacted only once per artifact.
The service is invoked by all clients concurrently and is therefore thread-safe.
Applications only implement getArtifactName() and getVersion() and must provide
a public constructor with a single String argument, the update base URL,
as required by ServerUpdateUtilities.startUpdateService(String, String, Class).
All other steps are protected methods that can be overridden to deviate from the convention.
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractUpdateServiceImpl(String updateURL) Creates an update service object. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateBaseUrlName(ClientInfo clientInfo) Creates the base URL name without extension.
The default implementation returns<updateURL>/<artifactName>-<version>-<platform>-<architecture>with-pkgappended for jpackage installations.protected URLcreateChecksumURL(ClientInfo clientInfo) Creates the URL for the checksum hash file.protected StringcreateUpdateExecutor(ClientInfo clientInfo) Creates the name of the update executor.
The script is located in thebindirectory of the unzipped update.protected UpdateInfocreateUpdateInfo(String version, URL zipURL, String checksumHash, long size, String updateExecutor) Creates the update info to be returned to the client.protected URLcreateZipURL(ClientInfo clientInfo) Creates the URL for the ZIP file.protected StringdetermineChecksumHash(URL checksumURL) Determines the checksum hash.
The hash is the first whitespace-delimited token of the checksum file, so the output ofsha256sumcan be used as is.protected longdetermineDownloadSize(URL zipURL) Determines the download size of the ZIP file.
Sends an HTTPHEADrequest and takes thecontent-lengthof the response.abstract StringGets the artifact name excluding the version.getUpdateInfo(ClientInfo clientInfo) Gets the info on how to download and install the update.
The client is expected to update only if the returned version differs from its own.Gets the update base URL.abstract StringGets the application version offered to the clients.
Usually the version of the server itself.protected booleanisSuccessful(int statusCode) Returns whether an HTTP status code denotes success.voidsetUpdateURL(String updateURL) Sets the update base URL.
A trailing slash is appended, if missing.
-
Constructor Details
-
AbstractUpdateServiceImpl
Creates an update service object.- Parameters:
updateURL- the HTTP(S) base URL to download the updates from
-
-
Method Details
-
getArtifactName
Gets the artifact name excluding the version.Example:
admin-jlink-client
- Returns:
- the artifact name
-
getVersion
Gets the application version offered to the clients.
Usually the version of the server itself.- Returns:
- the version
-
getUpdateURL
Gets the update base URL.- Returns:
- the URL, always with a trailing slash
-
setUpdateURL
Sets the update base URL.
A trailing slash is appended, if missing.- Parameters:
updateURL- the URL
-
getUpdateInfo
Gets the info on how to download and install the update.
The client is expected to update only if the returned version differs from its own.The version offered is always
getVersion(), regardless of the client's version.- Specified by:
getUpdateInfoin interfaceUpdateService- Parameters:
clientInfo- the client application info- Returns:
- the update info
- Throws:
org.tentackle.common.TentackleRuntimeException- if the checksum or the download size could not be determined, for example because the artifact is not published
-
createUpdateInfo
protected UpdateInfo createUpdateInfo(String version, URL zipURL, String checksumHash, long size, String updateExecutor) Creates the update info to be returned to the client.- Parameters:
version- the new application versionzipURL- the URL to download the ZIP filechecksumHash- the SHA-256 checksum hash of the ZIP filesize- the download size in bytes, -1 if unknownupdateExecutor- the filename of the script to execute to perform the update- Returns:
- the update info
-
createUpdateExecutor
Creates the name of the update executor.
The script is located in thebindirectory of the unzipped update.- Parameters:
clientInfo- the client info- Returns:
- the executor name,
update.cmdfor Windows, elseupdate.sh
-
createZipURL
Creates the URL for the ZIP file.- Parameters:
clientInfo- the client info- Returns:
- the URL
-
createChecksumURL
Creates the URL for the checksum hash file.- Parameters:
clientInfo- the client info- Returns:
- the URL
-
createBaseUrlName
Creates the base URL name without extension.
The default implementation returns<updateURL>/<artifactName>-<version>-<platform>-<architecture>with-pkgappended for jpackage installations.- Parameters:
clientInfo- the client info- Returns:
- the URL string
-
determineChecksumHash
Determines the checksum hash.
The hash is the first whitespace-delimited token of the checksum file, so the output ofsha256sumcan be used as is. The hash is cached.- Parameters:
checksumURL- the URL of the checksum hash file- Returns:
- the hash value
- Throws:
IOException- if the download failed or the file is empty
-
determineDownloadSize
Determines the download size of the ZIP file.
Sends an HTTPHEADrequest and takes thecontent-lengthof the response. Redirects are followed, so the ZIP may be served by a CDN or mirror.Only a determinate size is cached. An unknown size is not, because it would otherwise be answered for this artifact until the server is restarted, even though the very next request might get a proper content-length.
- Parameters:
zipURL- the download URL- Returns:
- the size in bytes, -1 if no content-length in header response
- Throws:
IOException- if failed or the artifact is not available (HTTP status other than 2xx)
-
isSuccessful
protected boolean isSuccessful(int statusCode) Returns whether an HTTP status code denotes success.- Parameters:
statusCode- the status code- Returns:
- true if 2xx
-