Package aQute.bnd.build
Class DownloadBlocker
- java.lang.Object
-
- aQute.bnd.build.DownloadBlocker
-
- All Implemented Interfaces:
RepositoryPlugin.DownloadListener
public class DownloadBlocker extends java.lang.Object implements RepositoryPlugin.DownloadListener
This class is intended to be used by the users of aRepositoryPlugin. TheRepositoryPlugin.get(String, aQute.bnd.version.Version, java.util.Map, aQute.bnd.service.RepositoryPlugin.DownloadListener...)method takes one or more Download Listeners. These are called back with the success or failure of a download. This class is a simple implementation of this model, just callgetReason()and it blocks until success or failure is called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDownloadBlocker.Stage
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>attrsprivate java.lang.Stringfailureprivate java.io.Filefileprivate static org.slf4j.Loggerloggerprivate Reporterreporterprivate java.util.concurrent.CountDownLatchresolvedprivate DownloadBlocker.Stagestage
-
Constructor Summary
Constructors Constructor Description DownloadBlocker(Reporter reporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfailure(java.io.File file, java.lang.String reason)Called when the file could not be downloaded from a remote repository.java.util.Map<java.lang.String,java.lang.String>getAttributes()java.io.FilegetFile()java.lang.StringgetReason()Return a failure reason or null.DownloadBlocker.StagegetStage()Return the stage we're inbooleanprogress(java.io.File file, int percentage)Can be called back regularly before success/failure but never after.voidsuccess(java.io.File file)Called when the file is successfully downloaded from a remote repository.voidsuccess(java.io.File file, java.util.Map<java.lang.String,java.lang.String> attrs)Called when the file is successfully downloaded from a remote repository.java.lang.StringtoString()
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
stage
private volatile DownloadBlocker.Stage stage
-
failure
private java.lang.String failure
-
file
private java.io.File file
-
attrs
private java.util.Map<java.lang.String,java.lang.String> attrs
-
reporter
private final Reporter reporter
-
resolved
private final java.util.concurrent.CountDownLatch resolved
-
-
Constructor Detail
-
DownloadBlocker
public DownloadBlocker(Reporter reporter)
-
-
Method Detail
-
success
public void success(java.io.File file) throws java.lang.ExceptionDescription copied from interface:RepositoryPlugin.DownloadListenerCalled when the file is successfully downloaded from a remote repository.- Specified by:
successin interfaceRepositoryPlugin.DownloadListener- Parameters:
file- The file that was downloaded- Throws:
java.lang.Exception- , are logged and ignored
-
success
public void success(java.io.File file, java.util.Map<java.lang.String,java.lang.String> attrs) throws java.lang.ExceptionDescription copied from interface:RepositoryPlugin.DownloadListenerCalled when the file is successfully downloaded from a remote repository.- Specified by:
successin interfaceRepositoryPlugin.DownloadListener- Parameters:
file- The file that was downloadedattrs- Additional attributes about the file. This may include maven coordinates.- Throws:
java.lang.Exception- , are logged and ignored
-
failure
public void failure(java.io.File file, java.lang.String reason) throws java.lang.ExceptionDescription copied from interface:RepositoryPlugin.DownloadListenerCalled when the file could not be downloaded from a remote repository.- Specified by:
failurein interfaceRepositoryPlugin.DownloadListener- Parameters:
file- The file that was intended to be downloaded.- Throws:
java.lang.Exception- , are logged and ignored
-
progress
public boolean progress(java.io.File file, int percentage) throws java.lang.ExceptionDescription copied from interface:RepositoryPlugin.DownloadListenerCan be called back regularly before success/failure but never after. Indicates how far the download has progressed in percents. Since downloads can be restarted, it is possible that the percentage decreases.- Specified by:
progressin interfaceRepositoryPlugin.DownloadListener- Parameters:
file- The file that was intended to be downloadedpercentage- Percentage of file downloaded (can go down)- Returns:
- true if the download should continue, fails if it should be canceled (and fail)
- Throws:
java.lang.Exception- , are logged and ignored
-
getReason
public java.lang.String getReason()
Return a failure reason or null. This method will block until eithersuccess(File)orfailure(File, String)has been called. It can be called many times.- Returns:
- null or a reason for a failure
-
getStage
public DownloadBlocker.Stage getStage()
Return the stage we're in- Returns:
- the current stage
-
getFile
public java.io.File getFile()
-
getAttributes
public java.util.Map<java.lang.String,java.lang.String> getAttributes()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-