-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDownload.java
More file actions
44 lines (36 loc) · 1.09 KB
/
Copy pathDownload.java
File metadata and controls
44 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package behavioral.observer;
import java.util.List;
import java.util.concurrent.ExecutorService;
public class Download implements Observable {
private List<Observer> observers;
private ExecutorService executor;
public Download(List<Observer> observers, ExecutorService executor) {
this.executor = executor;
this.observers = observers;
}
@Override
public void subscribe(Observer observer) {
observers.add(observer);
}
@Override
public void unSubscribe(Observer observer) {
int index = observers.indexOf(observer);
observers.remove(index);
}
@Override
public void notifyObserver() {
for (Observer observer : observers) {
observer.update();
}
}
public void downloadAsset(String uri) {
System.out.println("Download asset '" + uri);
Runnable run = () -> {
System.out.println("Downloading ...");
//do stuff to download file,
//when asset download is completed
notifyObserver();
};
executor.submit(run);
}
}