Class AbstractUpdateServiceImpl

java.lang.Object
org.tentackle.update.AbstractUpdateServiceImpl
All Implemented Interfaces:
Remote, UpdateService

public abstract class AbstractUpdateServiceImpl extends Object implements UpdateService
Server side update service implementation.

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].sha256
where -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 Details

    • AbstractUpdateServiceImpl

      public AbstractUpdateServiceImpl(String updateURL)
      Creates an update service object.
      Parameters:
      updateURL - the HTTP(S) base URL to download the updates from
  • Method Details

    • getArtifactName

      public abstract String getArtifactName()
      Gets the artifact name excluding the version.

      Example:

      admin-jlink-client
      Returns:
      the artifact name
    • getVersion

      public abstract String getVersion()
      Gets the application version offered to the clients.
      Usually the version of the server itself.
      Returns:
      the version
    • getUpdateURL

      public String getUpdateURL()
      Gets the update base URL.
      Returns:
      the URL, always with a trailing slash
    • setUpdateURL

      public void setUpdateURL(String updateURL)
      Sets the update base URL.
      A trailing slash is appended, if missing.
      Parameters:
      updateURL - the URL
    • getUpdateInfo

      public UpdateInfo 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.

      The version offered is always getVersion(), regardless of the client's version.

      Specified by:
      getUpdateInfo in interface UpdateService
      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 version
      zipURL - the URL to download the ZIP file
      checksumHash - the SHA-256 checksum hash of the ZIP file
      size - the download size in bytes, -1 if unknown
      updateExecutor - the filename of the script to execute to perform the update
      Returns:
      the update info
    • createUpdateExecutor

      protected String createUpdateExecutor(ClientInfo clientInfo)
      Creates the name of the update executor.
      The script is located in the bin directory of the unzipped update.
      Parameters:
      clientInfo - the client info
      Returns:
      the executor name, update.cmd for Windows, else update.sh
    • createZipURL

      protected URL createZipURL(ClientInfo clientInfo)
      Creates the URL for the ZIP file.
      Parameters:
      clientInfo - the client info
      Returns:
      the URL
    • createChecksumURL

      protected URL createChecksumURL(ClientInfo clientInfo)
      Creates the URL for the checksum hash file.
      Parameters:
      clientInfo - the client info
      Returns:
      the URL
    • createBaseUrlName

      protected String createBaseUrlName(ClientInfo clientInfo)
      Creates the base URL name without extension.
      The default implementation returns <updateURL>/<artifactName>-<version>-<platform>-<architecture> with -pkg appended for jpackage installations.
      Parameters:
      clientInfo - the client info
      Returns:
      the URL string
    • determineChecksumHash

      protected String determineChecksumHash(URL checksumURL) throws IOException
      Determines the checksum hash.
      The hash is the first whitespace-delimited token of the checksum file, so the output of sha256sum can 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

      protected long determineDownloadSize(URL zipURL) throws IOException
      Determines the download size of the ZIP file.
      Sends an HTTP HEAD request and takes the content-length of 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