75 lines
3.4 KiB
Java
75 lines
3.4 KiB
Java
package com.liulishuo.filedownloader;
|
|
|
|
import com.liulishuo.filedownloader.BaseDownloadTask;
|
|
import com.liulishuo.filedownloader.message.MessageSnapshot;
|
|
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
|
|
import com.liulishuo.filedownloader.util.FileDownloadLog;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MessageSnapshotGate implements MessageSnapshotFlow.MessageReceiver {
|
|
private boolean a(List<BaseDownloadTask.IRunningTask> list, MessageSnapshot messageSnapshot) {
|
|
boolean b;
|
|
if (list.size() > 1 && messageSnapshot.getStatus() == -3) {
|
|
for (BaseDownloadTask.IRunningTask iRunningTask : list) {
|
|
synchronized (iRunningTask.y()) {
|
|
if (iRunningTask.k().c(messageSnapshot)) {
|
|
FileDownloadLog.a(this, "updateMoreLikelyCompleted", new Object[0]);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (BaseDownloadTask.IRunningTask iRunningTask2 : list) {
|
|
synchronized (iRunningTask2.y()) {
|
|
if (iRunningTask2.k().d(messageSnapshot)) {
|
|
FileDownloadLog.a(this, "updateKeepFlow", new Object[0]);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
if (-4 == messageSnapshot.getStatus()) {
|
|
for (BaseDownloadTask.IRunningTask iRunningTask3 : list) {
|
|
synchronized (iRunningTask3.y()) {
|
|
if (iRunningTask3.k().a(messageSnapshot)) {
|
|
FileDownloadLog.a(this, "updateSampleFilePathTaskRunning", new Object[0]);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (list.size() != 1) {
|
|
return false;
|
|
}
|
|
BaseDownloadTask.IRunningTask iRunningTask4 = list.get(0);
|
|
synchronized (iRunningTask4.y()) {
|
|
FileDownloadLog.a(this, "updateKeepAhead", new Object[0]);
|
|
b = iRunningTask4.k().b(messageSnapshot);
|
|
}
|
|
return b;
|
|
}
|
|
|
|
@Override // com.liulishuo.filedownloader.message.MessageSnapshotFlow.MessageReceiver
|
|
public void a(MessageSnapshot messageSnapshot) {
|
|
synchronized (Integer.toString(messageSnapshot.getId()).intern()) {
|
|
List<BaseDownloadTask.IRunningTask> b = FileDownloadList.b().b(messageSnapshot.getId());
|
|
if (b.size() > 0) {
|
|
BaseDownloadTask F = b.get(0).F();
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.a(this, "~~~callback %s old[%s] new[%s] %d", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(F.getStatus()), Byte.valueOf(messageSnapshot.getStatus()), Integer.valueOf(b.size()));
|
|
}
|
|
if (!a(b, messageSnapshot)) {
|
|
StringBuilder sb = new StringBuilder("The event isn't consumed, id:" + messageSnapshot.getId() + " status:" + ((int) messageSnapshot.getStatus()) + " task-count:" + b.size());
|
|
for (BaseDownloadTask.IRunningTask iRunningTask : b) {
|
|
sb.append(" | ");
|
|
sb.append((int) iRunningTask.F().getStatus());
|
|
}
|
|
FileDownloadLog.c(this, sb.toString(), new Object[0]);
|
|
}
|
|
} else {
|
|
FileDownloadLog.c(this, "Receive the event %d, but there isn't any running task in the upper layer", Byte.valueOf(messageSnapshot.getStatus()));
|
|
}
|
|
}
|
|
}
|
|
}
|