- All Superinterfaces:
Injectable
,Service
- All Known Implementing Classes:
DefaultUpdateHandler
The order of the method invocation are precisely as follows:
init(UpdateContext)
startCheckUpdates()
updateCheckUpdatesProgress(float)
-- set to0f
shouldCheckForUpdate(FileMetadata)
updateCheckUpdatesProgress(float)
doneCheckUpdates()
startDownloads()
startDownloadFile(FileMetadata)
updateDownloadProgress(float)
-- on the first file only, set to0f
updateDownloadFileProgress(FileMetadata, float)
-- set to0f
. You can observe the remote server latency betweenstartDownloadFile()
and thisupdateDownloadFileProgress(FileMetadata, float)
-- updates the fraction of1f
updateDownloadProgress(float)
validatingFile(FileMetadata, Path)
doneDownloadFile(FileMetadata, Path)
doneDownloads()
stop()
For each file in the config:
If previous call returned true
:
If there are any files that need an update:
For each file requiring an update:
Repeatedly, until file download completes:
If successfully updated (or no updates were required, successfully):
Otherwise, for any exception, even if thrown by the update handler:
For more info how to use services, check out the GitHub Wiki.
- Author:
- Mordechai Meisels
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
doneCheckUpdateFile(FileMetadata file, boolean requires)
Checking if this file requires an update is complete, andUpdateContext.getRequiresUpdate()
was updated to include this file.default void
All files were passed for an update check (or not, ifshouldCheckForUpdate(FileMetadata)
returnedfalse
) and theUpdateContext.getRequiresUpdate()
is up-to-date.default void
doneDownloadFile(FileMetadata file, Path path)
The file was successfully downloaded topath
andUpdateContext.getUpdated()
was already updated to reflect this.default void
If the update was a regular — non-temp — update: All downloads completed and all temporary files were moved to its final location.default void
Called when the update process failed.default Object
Called byUpdateResult.result()
.default void
init(UpdateContext context)
Called after injection (seeConfiguration.update(Injectable)
) but before anything update related has started.default InputStream
openDownloadStream(FileMetadata file)
Do any logic to obtain anInputStream
for this file.default boolean
shouldCheckForUpdate(FileMetadata file)
Do your own logic here to decide whether a particular file should be updated.default void
startCheckUpdateFile(FileMetadata file)
Called before this individual file is checked if it is outdated.default void
Called afterinit(UpdateContext)
, just before starting to check for updates.default void
startDownloadFile(FileMetadata file)
Called once for every file that requires an update, just before the connection is established.default void
If there are any files that need an update, this method will get called once.default void
stop()
Called just before theConfiguration.update()
method returns, regardless of the error state (unless an exception was thrown infailed(Throwable)
orsucceeded()
).default void
Called when the update process is complete, even if no files actually required an update.default void
updateCheckUpdatesProgress(float frac)
Updates the 'check update' task progress.default void
updateDownloadFileProgress(FileMetadata file, float frac)
Called repeatedly, updating thefrac
value to reflect the state of the download of this individual file.default void
updateDownloadProgress(float frac)
Called repeatedly, updating thefrac
value to reflect the overall state of the download of all files.default void
validatingFile(FileMetadata file, Path path)
The file was successfully downloaded and is now about to be passed through a series of validations.
-
Method Details
-
init
Called after injection (seeConfiguration.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.- Parameters:
context
- Check the state of the update with this object.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
startCheckUpdates
Called afterinit(UpdateContext)
, just before starting to check for updates.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
shouldCheckForUpdate
Do your own logic here to decide whether a particular file should be updated. The default implementation returnstrue
for every file.This method is called before checking if the file is outdated.
- Parameters:
file
- The file to probe if it should be checked for updates.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
startCheckUpdateFile
Called before this individual file is checked if it is outdated.- Parameters:
file
- The file that will soon be checked if outdated.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
doneCheckUpdateFile
Checking if this file requires an update is complete, andUpdateContext.getRequiresUpdate()
was updated to include this file.- Parameters:
file
- The file that was just checked.requires
- Whether this file in fact requires an update.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
updateCheckUpdatesProgress
Updates the 'check update' task progress. Called once for every file in the config. It will be called the first time with the value0f
.The value is based on bytes of all files in the config, not file count.
- Parameters:
frac
- A value from0f
to1f
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.
-
doneCheckUpdates
All files were passed for an update check (or not, ifshouldCheckForUpdate(FileMetadata)
returnedfalse
) and theUpdateContext.getRequiresUpdate()
is up-to-date.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
startDownloads
If there are any files that need an update, this method will get called once.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
openDownloadStream
Do any logic to obtain anInputStream
for this file. You can do all kinds of interesting stuff here, as accessing authenticated API, use different protocols (as old-fashioned sockets if you really prefer) etc.Do not read anything from the stream, just return a newly opened stream and let the framework do the rest.
By default it will try to access the file from
FileMetadata.getUri()
assuming it is openly available without any authentication.- Parameters:
file
- The file to get an input stream for.- Returns:
- The newly opened input stream, unread.
- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
startDownloadFile
Called once for every file that requires an update, just before the connection is established.- 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
Called repeatedly, updating thefrac
value to reflect the state of the download of this individual file. It will be called the first time with the value0f
.You can observe the remote server latency, by comparing the time between
startDownloadFile(FileMetadata)
and this method with the value of0f
.- Parameters:
file
- The file currently being downloaded.frac
- A value from0f
to1f
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.
-
updateDownloadProgress
Called repeatedly, updating thefrac
value to reflect the overall state of the download of all files. It will be called the first time with the value0f
.- Parameters:
frac
- A value from0f
to1f
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.
-
validatingFile
The file was successfully downloaded and is now about to be passed through a series of validations.You can do your own validations here using the
tempFile
to read the actual file. Throw an exception to fail the download in case of validation fail.- Parameters:
file
- The file about to be passing through validations.path
- The actual file, only moved to its final location once all downloads succeed. In archive-based updates, the path is inside the archive.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
doneDownloadFile
The file was successfully downloaded topath
andUpdateContext.getUpdated()
was already updated to reflect this.The file will only be placed in its final location once all files successfully download. In archive-based updates the path is inside the archive.
- Parameters:
file
- The file that just completed downloadpath
- The temporary location of the file, only moved to its final location once all downloads succeed. In archive-based updates, the path is inside the archive.- Throws:
Throwable
- Freely throw any exception, it will gracefully terminate the update process and revert any file changes.
-
doneDownloads
If the update was a regular — non-temp — update: All downloads completed and all temporary files were moved to its final location. If an exception is thrown in this method, the new files remain untouched andfailed(Throwable)
will be called.If the update was a temp update: All downloads completed and reside in their temporary location. If an exception is thrown in this method, it will delete the update, revert any changes and
failed(Throwable)
will be called.If the update was an archive-based update: The archive is completed and ready to be installed.
This method will only be called if there were actually files that required updates.
- Throws:
Throwable
- Any exception will be passed tofailed(Throwable)
and theupdate()
method will return false.
-
failed
Called when the update process failed.If an exception arises in this method, the exception will bubble up to the
Configuration.update()
method.- Parameters:
t
- The exception thrown that failed the update process.
-
succeeded
default void succeeded()Called when the update process is complete, even if no files actually required an update.If an exception arises in this method, the exception will bubble up to the
Configuration.update()
method. -
stop
default void stop()Called just before theConfiguration.update()
method returns, regardless of the error state (unless an exception was thrown infailed(Throwable)
orsucceeded()
).If an exception arises in this method, the exception will bubble up to the
Configuration.update()
method. -
getResult
Called byUpdateResult.result()
. Ifresult()
is never called, this will never get called either.You're free to use any return type, it will automatically be cast to the receiver type of the caller of
UpdateResult.result()
:// When defining: public MyType getResult() { return new MyType(); } // You can do this without a cast: MyType myResult = update(...).result(); // But this fails with ClassCastException: String str = update(...).result();
- Returns:
-