mirror of
https://github.com/mirror/jdownloader.git
synced 2024-11-26 21:40:38 +00:00
PackageControllerQueue:
-extends Queue -allows peek/executeQueuedAction PackageController/PackageControllerTable/SelectionInfo: -updated to make use of ReadOnlyQueueAction LinkCollector/DownloadController: -updated save to make use of new PackageControllerQueue.peek and PackageControllerQueue.executeQueuedAction methods refs thread 96430 git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@49880 ebf7c1c2-ba36-0410-9fe8-c592906822b4 Former-commit-id: 2074a51dd9aed84af6ed31fb194060c5f0901079
This commit is contained in:
parent
24958d3837
commit
d47e9aa03b
@ -43,6 +43,19 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageChildrenNodeFilter;
|
||||
import jd.controlling.packagecontroller.PackageController;
|
||||
import jd.controlling.packagecontroller.PackageControllerQueue.ReadOnlyQueueAction;
|
||||
import jd.parser.Regex;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.DownloadLinkProperty;
|
||||
import jd.plugins.DownloadLinkStorable;
|
||||
import jd.plugins.FilePackage;
|
||||
import jd.plugins.FilePackageProperty;
|
||||
import jd.plugins.PluginForHost;
|
||||
import jd.utils.JDUtilities;
|
||||
|
||||
import org.appwork.controlling.SingleReachableState;
|
||||
import org.appwork.exceptions.WTFException;
|
||||
import org.appwork.scheduler.DelayedRunnable;
|
||||
@ -55,6 +68,7 @@ import org.appwork.storage.TypeRef;
|
||||
import org.appwork.storage.config.JsonConfig;
|
||||
import org.appwork.storage.simplejson.JSonFactory;
|
||||
import org.appwork.utils.Application;
|
||||
import org.appwork.utils.DebugMode;
|
||||
import org.appwork.utils.IO;
|
||||
import org.appwork.utils.StringUtils;
|
||||
import org.appwork.utils.event.Eventsender;
|
||||
@ -86,18 +100,6 @@ import org.jdownloader.settings.GeneralSettings;
|
||||
import org.jdownloader.settings.GeneralSettings.CreateFolderTrigger;
|
||||
import org.jdownloader.settings.staticreferences.CFG_GENERAL;
|
||||
|
||||
import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageChildrenNodeFilter;
|
||||
import jd.controlling.packagecontroller.PackageController;
|
||||
import jd.parser.Regex;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.DownloadLinkProperty;
|
||||
import jd.plugins.DownloadLinkStorable;
|
||||
import jd.plugins.FilePackage;
|
||||
import jd.plugins.FilePackageProperty;
|
||||
import jd.plugins.PluginForHost;
|
||||
import jd.utils.JDUtilities;
|
||||
|
||||
public class DownloadController extends PackageController<FilePackage, DownloadLink> {
|
||||
private final transient DownloadControllerEventSender eventSender = new DownloadControllerEventSender();
|
||||
private final DelayedRunnable downloadSaver;
|
||||
@ -178,7 +180,7 @@ public class DownloadController extends PackageController<FilePackage, DownloadL
|
||||
}
|
||||
});
|
||||
final DownloadControllerConfig cfg = JsonConfig.create(DownloadControllerConfig.class);
|
||||
final long minimumDelay = Math.max(5000, cfg.getMinimumSaveDelay());
|
||||
final long minimumDelay = Math.max(DebugMode.TRUE_IN_IDE_ELSE_FALSE ? 1 : 5000, cfg.getMinimumSaveDelay());
|
||||
long maximumDelay = cfg.getMaximumSaveDelay();
|
||||
if (maximumDelay <= 0) {
|
||||
maximumDelay = -1;
|
||||
@ -1013,6 +1015,7 @@ public class DownloadController extends PackageController<FilePackage, DownloadL
|
||||
* @param file
|
||||
*/
|
||||
private boolean save(java.util.List<FilePackage> packages, File file) throws IOException {
|
||||
final boolean isShuttingDown = ShutdownController.getInstance().isShuttingDown();
|
||||
synchronized (SAVELOADLOCK) {
|
||||
if (file == null) {
|
||||
if (downloadLists.size() > 0) {
|
||||
@ -1142,6 +1145,12 @@ public class DownloadController extends PackageController<FilePackage, DownloadL
|
||||
}
|
||||
int childIndex = 0;
|
||||
for (final DownloadLink link : pkg.getChildren()) {
|
||||
if (!isShuttingDown) {
|
||||
final QueueAction<?, ? extends Throwable> waiting = DownloadController.this.getQueue().peek();
|
||||
if (waiting instanceof ReadOnlyQueueAction) {
|
||||
DownloadController.this.getQueue().executeQueuedAction(waiting);
|
||||
}
|
||||
}
|
||||
final DownloadLinkStorable linkStorable = new DownloadLinkStorable(link);
|
||||
final String childEntryID = String.format(childFormat, childIndex++);
|
||||
final ZipEntry linkEntry = new ZipEntry(packageEntryID + "_" + childEntryID);
|
||||
|
@ -15,9 +15,8 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import jd.controlling.packagecontroller.PackageControllerQueue.ReadOnlyQueueAction;
|
||||
|
||||
import org.appwork.utils.DebugMode;
|
||||
import org.appwork.utils.ModifyLock;
|
||||
import org.appwork.utils.Regex;
|
||||
import org.appwork.utils.StringUtils;
|
||||
@ -104,22 +103,7 @@ public abstract class PackageController<PackageType extends AbstractPackageNode<
|
||||
return mapLock;
|
||||
}
|
||||
|
||||
protected final Queue QUEUE = new Queue(getClass().getName()) {
|
||||
@Override
|
||||
public void killQueue() {
|
||||
org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().log(new Throwable("YOU CANNOT KILL ME!"));
|
||||
/*
|
||||
* this queue can't be killed
|
||||
*/
|
||||
}
|
||||
|
||||
public <E, T extends Throwable> E addWait(QueueAction<E, T> item) throws T {
|
||||
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE && SwingUtilities.isEventDispatchThread()) {
|
||||
new Exception("This should be done via callback to avoid queue<->edt deadlocks").printStackTrace();
|
||||
}
|
||||
return super.addWait(item);
|
||||
};
|
||||
};
|
||||
protected final PackageControllerQueue QUEUE = new PackageControllerQueue(getClass().getName());
|
||||
|
||||
/**
|
||||
* add a Package at given position position in this PackageController. in case the Package is already controlled by this
|
||||
@ -132,7 +116,7 @@ public abstract class PackageController<PackageType extends AbstractPackageNode<
|
||||
addmovePackageAt(pkg, index, false);
|
||||
}
|
||||
|
||||
public Queue getQueue() {
|
||||
public PackageControllerQueue getQueue() {
|
||||
return QUEUE;
|
||||
}
|
||||
|
||||
@ -1161,7 +1145,7 @@ public abstract class PackageController<PackageType extends AbstractPackageNode<
|
||||
if (lSelectionInfo != null && lSelectionInfo.getBackendVersion() == version) {
|
||||
return lSelectionInfo;
|
||||
}
|
||||
return getQueue().addWait(new QueueAction<SelectionInfo<PackageType, ChildType>, RuntimeException>(Queue.QueuePriority.HIGH) {
|
||||
return getQueue().addWait(new ReadOnlyQueueAction<SelectionInfo<PackageType, ChildType>, RuntimeException>(Queue.QueuePriority.HIGH) {
|
||||
@Override
|
||||
protected SelectionInfo<PackageType, ChildType> run() throws RuntimeException {
|
||||
final long version = getBackendChanged();
|
||||
|
@ -0,0 +1,73 @@
|
||||
package jd.controlling.packagecontroller;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.appwork.utils.DebugMode;
|
||||
import org.appwork.utils.event.queue.Queue;
|
||||
import org.appwork.utils.event.queue.QueueAction;
|
||||
import org.appwork.utils.logging2.LogInterface;
|
||||
|
||||
public class PackageControllerQueue extends Queue {
|
||||
|
||||
public static abstract class ReadOnlyQueueAction<T, E extends Throwable> extends QueueAction<T, E> {
|
||||
|
||||
public ReadOnlyQueueAction() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ReadOnlyQueueAction(QueuePriority prio) {
|
||||
super(prio);
|
||||
}
|
||||
}
|
||||
|
||||
protected PackageControllerQueue(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killQueue() {
|
||||
getLogger().log(new Throwable("YOU CANNOT KILL ME!"));
|
||||
/*
|
||||
* this queue can't be killed
|
||||
*/
|
||||
}
|
||||
|
||||
public <E, T extends Throwable> E addWait(QueueAction<E, T> item) throws T {
|
||||
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE && SwingUtilities.isEventDispatchThread()) {
|
||||
getLogger().log(new Exception("This should be done via callback to avoid queue<->edt deadlocks"));
|
||||
}
|
||||
return super.addWait(item);
|
||||
};
|
||||
|
||||
@Override
|
||||
public QueueAction<?, ? extends Throwable> peek() {
|
||||
if (!DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return super.peek();
|
||||
} catch (Throwable e) {
|
||||
// compatibility with incompatible core
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean executeQueuedAction(final QueueAction<?, ?> item) {
|
||||
if (item != null && !item.gotStarted() && isQueueThread(item) && isQueued(item)) {
|
||||
try {
|
||||
super.startItem(item, true);
|
||||
} catch (Throwable e) {
|
||||
getLogger().log(e);
|
||||
}
|
||||
remove(item);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected LogInterface getLogger() {
|
||||
return org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger();
|
||||
}
|
||||
|
||||
}
|
@ -18,13 +18,13 @@ import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageNode;
|
||||
import jd.controlling.packagecontroller.PackageController;
|
||||
import jd.controlling.packagecontroller.PackageControllerQueue.ReadOnlyQueueAction;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.FilePackage;
|
||||
import jd.plugins.PluginForHost;
|
||||
|
||||
import org.appwork.utils.event.queue.Queue;
|
||||
import org.appwork.utils.event.queue.Queue.QueuePriority;
|
||||
import org.appwork.utils.event.queue.QueueAction;
|
||||
import org.jdownloader.controlling.UniqueAlltimeID;
|
||||
|
||||
public class SelectionInfo<PackageType extends AbstractPackageNode<ChildrenType, PackageType>, ChildrenType extends AbstractPackageChildrenNode<PackageType>> {
|
||||
@ -114,7 +114,7 @@ public class SelectionInfo<PackageType extends AbstractPackageNode<ChildrenType,
|
||||
|
||||
protected void aggregate(Queue queue) {
|
||||
if (queue != null) {
|
||||
queue.addWait(new QueueAction<Void, RuntimeException>(QueuePriority.HIGH) {
|
||||
queue.addWait(new ReadOnlyQueueAction<Void, RuntimeException>(QueuePriority.HIGH) {
|
||||
@Override
|
||||
protected Void run() throws RuntimeException {
|
||||
aggregate();
|
||||
|
@ -31,6 +31,7 @@ import jd.controlling.packagecontroller.AbstractNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
|
||||
import jd.controlling.packagecontroller.AbstractPackageNode;
|
||||
import jd.controlling.packagecontroller.PackageController;
|
||||
import jd.controlling.packagecontroller.PackageControllerQueue.ReadOnlyQueueAction;
|
||||
import jd.gui.swing.jdgui.BasicJDTable;
|
||||
|
||||
import org.appwork.exceptions.WTFException;
|
||||
@ -344,7 +345,7 @@ public abstract class PackageControllerTable<ParentType extends AbstractPackageN
|
||||
}
|
||||
}.start(invokeLater);
|
||||
} else {
|
||||
getModel().getController().getQueue().add(new QueueAction<Void, RuntimeException>(Queue.QueuePriority.HIGH) {
|
||||
getModel().getController().getQueue().add(new ReadOnlyQueueAction<Void, RuntimeException>(Queue.QueuePriority.HIGH) {
|
||||
@Override
|
||||
protected Void run() throws RuntimeException {
|
||||
final SelectionInfo<ParentType, ChildrenType> selectionInfo = getModel().getController().getSelectionInfo();
|
||||
|
Loading…
Reference in New Issue
Block a user