jimu-decompiled/sources/com/liulishuo/filedownloader/message/MessageSnapshotThreadPool.java
2025-05-13 19:24:51 +02:00

85 lines
3.0 KiB
Java

package com.liulishuo.filedownloader.message;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
/* loaded from: classes.dex */
public class MessageSnapshotThreadPool {
private final List<FlowSingleExecutor> a = new ArrayList();
private final MessageSnapshotFlow.MessageReceiver b;
public class FlowSingleExecutor {
private final List<Integer> a = new ArrayList();
private final Executor b;
public FlowSingleExecutor(int i) {
this.b = FileDownloadExecutors.a(1, "Flow-" + i);
}
public void a(int i) {
this.a.add(Integer.valueOf(i));
}
public void a(final MessageSnapshot messageSnapshot) {
this.b.execute(new Runnable() { // from class: com.liulishuo.filedownloader.message.MessageSnapshotThreadPool.FlowSingleExecutor.1
@Override // java.lang.Runnable
public void run() {
MessageSnapshotThreadPool.this.b.a(messageSnapshot);
FlowSingleExecutor.this.a.remove(Integer.valueOf(messageSnapshot.getId()));
}
});
}
}
MessageSnapshotThreadPool(int i, MessageSnapshotFlow.MessageReceiver messageReceiver) {
this.b = messageReceiver;
for (int i2 = 0; i2 < i; i2++) {
this.a.add(new FlowSingleExecutor(i2));
}
}
public void a(MessageSnapshot messageSnapshot) {
FlowSingleExecutor flowSingleExecutor = null;
try {
synchronized (this.a) {
int id = messageSnapshot.getId();
Iterator<FlowSingleExecutor> it = this.a.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
FlowSingleExecutor next = it.next();
if (next.a.contains(Integer.valueOf(id))) {
flowSingleExecutor = next;
break;
}
}
if (flowSingleExecutor == null) {
int i = 0;
Iterator<FlowSingleExecutor> it2 = this.a.iterator();
while (true) {
if (!it2.hasNext()) {
break;
}
FlowSingleExecutor next2 = it2.next();
if (next2.a.size() <= 0) {
flowSingleExecutor = next2;
break;
} else if (i == 0 || next2.a.size() < i) {
i = next2.a.size();
flowSingleExecutor = next2;
}
}
}
flowSingleExecutor.a(id);
}
} finally {
flowSingleExecutor.a(messageSnapshot);
}
}
}