Module org.update4j

Class DefaultUpdateHandler

Object
DefaultUpdateHandler
All Implemented Interfaces:
Injectable, Service, UpdateHandler

public class DefaultUpdateHandler
extends Object
implements UpdateHandler
  • Constructor Details

  • Method Details

    • version

      public long version()
      Specified by:
      version in interface Service
    • init

      public void init​(UpdateContext context)
      Description copied from interface: UpdateHandler
      Called after injection (see Configuration.update(Injectable)) but before anything update related has started.

      To do any initialization before injection, do it in the constructor, but be aware that unless you specify the handler in the updateHandler section of the configuration, the constructor might be called even if this provider will not be used in the end. This happens as the service loading mechanism first loads all providers and then compares versions to use the one with the highest version.

      You can use the UpdateContext to get information or the current state of the update process, any time. Its values are updated along the process to reflect any change.

      Specified by:
      init in interface UpdateHandler
      Parameters:
      context - Check the state of the update with this object.
    • startDownloads

      public void startDownloads() throws Throwable
      Description copied from interface: UpdateHandler
      If there are any files that need an update, this method will get called once.
      Specified by:
      startDownloads in interface UpdateHandler
      Throws:
      Throwable - Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
    • startDownloadFile

      public void startDownloadFile​(FileMetadata file) throws Throwable
      Description copied from interface: UpdateHandler
      Called once for every file that requires an update, just before the connection is established.
      Specified by:
      startDownloadFile in interface UpdateHandler
      Parameters:
      file - The file that will now be downloaded.
      Throws:
      Throwable - Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
    • updateDownloadFileProgress

      public void updateDownloadFileProgress​(FileMetadata file, float frac) throws Throwable
      Description copied from interface: UpdateHandler
      Called repeatedly, updating the frac value to reflect the state of the download of this individual file. It will be called the first time with the value 0f.

      You can observe the remote server latency, by comparing the time between UpdateHandler.startDownloadFile(FileMetadata) and this method with the value of 0f.

      Specified by:
      updateDownloadFileProgress in interface UpdateHandler
      Parameters:
      file - The file currently being downloaded.
      frac - A value from 0f to 1f representing the percent of the job done.
      Throws:
      Throwable - Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
    • doneDownloadFile

      public void doneDownloadFile​(FileMetadata file, Path tempFile) throws Throwable
      Description copied from interface: UpdateHandler
      The file was successfully downloaded to tempFile and UpdateContext.getUpdated() was already updated to reflect this.

      The file will only be placed in its final location once all files successfully download.

      Specified by:
      doneDownloadFile in interface UpdateHandler
      Parameters:
      file - The file that just completed download
      tempFile - The temporary location of the file, only moved to its final location once all downloads succeed.
      Throws:
      Throwable - Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
    • failed

      public void failed​(Throwable t)
      Description copied from interface: UpdateHandler
      Called when the update process failed.

      If an exception arises in this method, the exception will bubble up to the Configuration.update() method.

      Specified by:
      failed in interface UpdateHandler
      Parameters:
      t - The exception thrown that failed the update process.
    • stop

      public void stop()
      Description copied from interface: UpdateHandler
      Called just before the Configuration.update() method returns, regardless of the error state (unless an exception was thrown in UpdateHandler.failed(Throwable) or UpdateHandler.succeeded()).

      If an exception arises in this method, the exception will bubble up to the Configuration.update() method.

      Specified by:
      stop in interface UpdateHandler
    • initProgress

      protected void initProgress()
    • resetProgress

      protected void resetProgress​(long bytes)
    • out

      protected PrintStream out()
    • consoleWidth

      protected int consoleWidth()
    • renderProgress

      protected String renderProgress()
    • renderFilename

      protected String renderFilename​(FileMetadata file)