|
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.*; |
|
|
|
|
public class DownloaderImpl implements Downloader { |
|
|
|
|
|
|
|
|
|
private static final ExecutorService pool = Executors.newCachedThreadPool(); |
|
|
|
|
private static final String BASE_DIRECTORY = "/var/opt/fias"; |
|
|
|
|
private static final String BASE_DIRECTORY = "/tmp/"; //todo path
|
|
|
|
|
private static final ConcurrentMap<String,CompletableFuture<File>> locks = new ConcurrentHashMap(); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -23,7 +23,9 @@ public class DownloaderImpl implements Downloader { |
|
|
|
|
CompletableFuture<File> start = new CompletableFuture<>(); |
|
|
|
|
|
|
|
|
|
//syncronized
|
|
|
|
|
final CompletableFuture<File> feature = locks.putIfAbsent(url, start); |
|
|
|
|
final CompletableFuture<File> add = locks.putIfAbsent(url, start); |
|
|
|
|
|
|
|
|
|
final CompletableFuture<File> feature = add!=null ? add : locks.get(url); |
|
|
|
|
|
|
|
|
|
//return earlier runned feature
|
|
|
|
|
if(feature != start) return feature; |
|
|
|
@ -39,6 +41,7 @@ public class DownloaderImpl implements Downloader { |
|
|
|
|
path = Paths.get(BASE_DIRECTORY, conn.getFile()); |
|
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
//todo log
|
|
|
|
|
feature.obtrudeException(e); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|