92 lines
3.3 KiB
Java
92 lines
3.3 KiB
Java
package com.liulishuo.filedownloader.event;
|
|
|
|
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
|
|
import com.liulishuo.filedownloader.util.FileDownloadLog;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedList;
|
|
import java.util.concurrent.Executor;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DownloadEventPoolImpl implements IDownloadEventPool {
|
|
private final Executor a = FileDownloadExecutors.a(10, "EventPool");
|
|
private final HashMap<String, LinkedList<IDownloadListener>> b = new HashMap<>();
|
|
|
|
public boolean a(String str, IDownloadListener iDownloadListener) {
|
|
boolean add;
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.d(this, "setListener %s", str);
|
|
}
|
|
if (iDownloadListener == null) {
|
|
throw new IllegalArgumentException("listener must not be null!");
|
|
}
|
|
LinkedList<IDownloadListener> linkedList = this.b.get(str);
|
|
if (linkedList == null) {
|
|
synchronized (str.intern()) {
|
|
linkedList = this.b.get(str);
|
|
if (linkedList == null) {
|
|
HashMap<String, LinkedList<IDownloadListener>> hashMap = this.b;
|
|
LinkedList<IDownloadListener> linkedList2 = new LinkedList<>();
|
|
hashMap.put(str, linkedList2);
|
|
linkedList = linkedList2;
|
|
}
|
|
}
|
|
}
|
|
synchronized (str.intern()) {
|
|
add = linkedList.add(iDownloadListener);
|
|
}
|
|
return add;
|
|
}
|
|
|
|
public boolean b(IDownloadEvent iDownloadEvent) {
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.d(this, "publish %s", iDownloadEvent.a());
|
|
}
|
|
if (iDownloadEvent == null) {
|
|
throw new IllegalArgumentException("event must not be null!");
|
|
}
|
|
String a = iDownloadEvent.a();
|
|
LinkedList<IDownloadListener> linkedList = this.b.get(a);
|
|
if (linkedList == null) {
|
|
synchronized (a.intern()) {
|
|
linkedList = this.b.get(a);
|
|
if (linkedList == null) {
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.a(this, "No listener for this event %s", a);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
a(linkedList, iDownloadEvent);
|
|
return true;
|
|
}
|
|
|
|
public void a(final IDownloadEvent iDownloadEvent) {
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.d(this, "asyncPublishInNewThread %s", iDownloadEvent.a());
|
|
}
|
|
if (iDownloadEvent != null) {
|
|
this.a.execute(new Runnable() { // from class: com.liulishuo.filedownloader.event.DownloadEventPoolImpl.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
DownloadEventPoolImpl.this.b(iDownloadEvent);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("event must not be null!");
|
|
}
|
|
|
|
private void a(LinkedList<IDownloadListener> linkedList, IDownloadEvent iDownloadEvent) {
|
|
for (Object obj : linkedList.toArray()) {
|
|
if (obj != null && ((IDownloadListener) obj).a(iDownloadEvent)) {
|
|
break;
|
|
}
|
|
}
|
|
Runnable runnable = iDownloadEvent.a;
|
|
if (runnable != null) {
|
|
runnable.run();
|
|
}
|
|
}
|
|
}
|