![JAR search and dependency download from the Maven repository](/logo.png)
io.arivera.oss.embedded.rabbitmq.download.CachedDownloader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of embedded-rabbitmq Show documentation
Show all versions of embedded-rabbitmq Show documentation
A library to facilitate running RabbitMQ directly from a JVM application as if it was an embedded service.
The newest version!
package io.arivera.oss.embedded.rabbitmq.download;
import io.arivera.oss.embedded.rabbitmq.EmbeddedRabbitMqConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
class CachedDownloader extends Downloader.Decorator {
private static final Logger LOGGER = LoggerFactory.getLogger(CachedDownloader.class);
private final EmbeddedRabbitMqConfig config;
CachedDownloader(Downloader downloader, EmbeddedRabbitMqConfig config) {
super(downloader);
this.config = config;
}
@Override
public void run() {
if (isDownloadAlreadyCached()) {
LOGGER.debug("RabbitMQ has been downloaded before. Using file: {}", config.getDownloadTarget());
} else {
download();
}
}
private boolean isDownloadAlreadyCached() {
File downloadTarget = config.getDownloadTarget();
return downloadTarget.exists() && downloadTarget.isFile() && downloadTarget.canRead() && downloadTarget.length() > 0;
}
private void download() {
try {
innerDownloader.run();
} catch (DownloadException e) {
if (config.shouldDeleteCachedFileOnErrors()) {
if (config.getDownloadTarget().exists()) {
boolean deleted = config.getDownloadTarget().delete();
if (deleted) {
LOGGER.info("Removed partially downloaded file: {}", config.getDownloadTarget());
} else {
LOGGER.warn("Could not remove partially downloaded file. Please remove it manually: {}", config.getDownloadTarget());
}
}
} else {
LOGGER.info("Partially downloaded file will not be deleted: {}", config.getDownloadTarget());
}
throw e;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy