Package ca.corbett.updates
Class ExtensionDownloadThread
java.lang.Object
ca.corbett.extras.progress.SimpleProgressWorker
ca.corbett.updates.ExtensionDownloadThread
- All Implemented Interfaces:
Runnable
A SimpleProgressWorker implementation that can download the given Extension and
return it as a DownloadedExtension instance if the download succeeds. You can configure
which extension file(s) you wish to download using the setDownloadOptions() method,
but it must be invoked before the thread is started.
NOTE: This worker thread will not fire a progressError event! It will invoke progressComplete when all associated files have either succeeded or failed. Callers can check getErrors() to see if anything failed.
IMPORTANT: The callbacks in this listener will be invoked from the worker thread! If you need to update a Swing UI component as a result of one of these callbacks, you need to marshal that call to the Swing Event Dispatching Thread, like this:
@Override
boolean progressComplete() {
// Some operations are fine to do here on the worker thread.
// For example, verifying the signature on the downloaded jar:
DownloadedExtension ext = workerThread.getDownloadedExtension();
boolean isValid = false;
if (ext.getSignatureFile() != null) {
isValid = SignatureUtil.verifyFile(ext.getJarFile(),
ext.getSigFile(),
ext.getPublicKey());
}
// BUT! Now we need to display it in a Swing UI component:
SwingUtilities.invokeLater(() -> { // marshal to EDT
myStatusLabel.setText("Signature is valid: " + isValid);
});
}
Failure to do this may result in deadlocks or other threading issues, as Swing itself is not thread-safe.
- Since:
- swing-extras 2.5
- Author:
- scorbo2
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionExtensionDownloadThread(DownloadManager downloadManager, UpdateSources.UpdateSource updateSource, VersionManifest.ExtensionVersion extensionVersion) -
Method Summary
Modifier and TypeMethodDescriptionvoidrun()voidBefore starting the worker thread, you can decide which file(s) should be downloaded for the extension in question.voidsetDownloadTimeoutMs(long timeout) Before starting the download, you can set a download timeout - if the total time to download all requested files exceeds this value, the download will abort.Methods inherited from class ca.corbett.extras.progress.SimpleProgressWorker
addProgressListener, clearProgressListeners, fireProgressBegins, fireProgressCanceled, fireProgressComplete, fireProgressError, fireProgressUpdate, removeProgressListener
-
Constructor Details
-
ExtensionDownloadThread
public ExtensionDownloadThread(DownloadManager downloadManager, UpdateSources.UpdateSource updateSource, VersionManifest.ExtensionVersion extensionVersion)
-
-
Method Details
-
getErrors
-
getDownloadedExtension
-
setDownloadOptions
Before starting the worker thread, you can decide which file(s) should be downloaded for the extension in question. By default, all options are set to true. -
setDownloadTimeoutMs
public void setDownloadTimeoutMs(long timeout) Before starting the download, you can set a download timeout - if the total time to download all requested files exceeds this value, the download will abort. Default is 10 seconds. -
run
public void run()
-