diff --git a/src/jd/controlling/downloadcontroller/DownloadController.java b/src/jd/controlling/downloadcontroller/DownloadController.java index d0da0e90af6..6c9cb57214c 100644 --- a/src/jd/controlling/downloadcontroller/DownloadController.java +++ b/src/jd/controlling/downloadcontroller/DownloadController.java @@ -43,6 +43,19 @@ 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.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.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 { private final transient DownloadControllerEventSender eventSender = new DownloadControllerEventSender(); private final DelayedRunnable downloadSaver; @@ -178,7 +180,7 @@ public String toString() { } }); 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; @@ -601,15 +603,15 @@ private final void setFilePackage(FilePackage filePackage) { private final ArrayList downloadLinks = new ArrayList(); private final static Comparator COMPARATOR = new Comparator() { - private final int compare(int x, int y) { - return (x < y) ? -1 : ((x == y) ? 0 : 1); - } + private final int compare(int x, int y) { + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } - @Override - public int compare(IndexedDownloadLink o1, IndexedDownloadLink o2) { - return compare(o1.getIndex(), o2.getIndex()); - } - }; + @Override + public int compare(IndexedDownloadLink o1, IndexedDownloadLink o2) { + return compare(o1.getIndex(), o2.getIndex()); + } + }; private FilePackage getLoadedPackage() { final FilePackage filePackage = this.filePackage; @@ -1013,6 +1015,7 @@ public void removeListener(final DownloadControllerListener l) { * @param file */ private boolean save(java.util.List 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 void flush() throws IOException { } int childIndex = 0; for (final DownloadLink link : pkg.getChildren()) { + if (!isShuttingDown) { + final QueueAction 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); diff --git a/src/jd/controlling/packagecontroller/PackageController.java b/src/jd/controlling/packagecontroller/PackageController.java index c5eb4fc6302..b76cad4e410 100644 --- a/src/jd/controlling/packagecontroller/PackageController.java +++ b/src/jd/controlling/packagecontroller/PackageController.java @@ -15,9 +15,8 @@ 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 @@ protected ModifyLock getMapLock() { 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 addWait(QueueAction 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 @@ protected void addmovePackageAt(final PackageType pkg, final int index) { addmovePackageAt(pkg, index, false); } - public Queue getQueue() { + public PackageControllerQueue getQueue() { return QUEUE; } @@ -828,7 +812,7 @@ protected Void run() throws RuntimeException { /* remove all */ /* * TODO: speed optimization, we have to correct the index to match changes in children structure - * + * * TODO: optimize this loop. only process existing links in this package */ for (final ChildType child : elementsToMove) { @@ -1161,7 +1145,7 @@ public SelectionInfo getSelectionInfo() { if (lSelectionInfo != null && lSelectionInfo.getBackendVersion() == version) { return lSelectionInfo; } - return getQueue().addWait(new QueueAction, RuntimeException>(Queue.QueuePriority.HIGH) { + return getQueue().addWait(new ReadOnlyQueueAction, RuntimeException>(Queue.QueuePriority.HIGH) { @Override protected SelectionInfo run() throws RuntimeException { final long version = getBackendChanged(); diff --git a/src/jd/controlling/packagecontroller/PackageControllerQueue.java b/src/jd/controlling/packagecontroller/PackageControllerQueue.java new file mode 100644 index 00000000000..3a536a006e6 --- /dev/null +++ b/src/jd/controlling/packagecontroller/PackageControllerQueue.java @@ -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 extends QueueAction { + + 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 addWait(QueueAction 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 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(); + } + +} diff --git a/src/org/jdownloader/gui/views/SelectionInfo.java b/src/org/jdownloader/gui/views/SelectionInfo.java index 8c72a66f129..7a8e7669feb 100644 --- a/src/org/jdownloader/gui/views/SelectionInfo.java +++ b/src/org/jdownloader/gui/views/SelectionInfo.java @@ -18,13 +18,13 @@ 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, ChildrenType extends AbstractPackageChildrenNode> { @@ -114,7 +114,7 @@ public SelectionInfo(final AbstractNode contextObject, final List(QueuePriority.HIGH) { + queue.addWait(new ReadOnlyQueueAction(QueuePriority.HIGH) { @Override protected Void run() throws RuntimeException { aggregate(); diff --git a/src/org/jdownloader/gui/views/components/packagetable/PackageControllerTable.java b/src/org/jdownloader/gui/views/components/packagetable/PackageControllerTable.java index 4aa9abe7f76..dd0e34a77ed 100644 --- a/src/org/jdownloader/gui/views/components/packagetable/PackageControllerTable.java +++ b/src/org/jdownloader/gui/views/components/packagetable/PackageControllerTable.java @@ -31,6 +31,7 @@ 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 Void edtRun() { } }.start(invokeLater); } else { - getModel().getController().getQueue().add(new QueueAction(Queue.QueuePriority.HIGH) { + getModel().getController().getQueue().add(new ReadOnlyQueueAction(Queue.QueuePriority.HIGH) { @Override protected Void run() throws RuntimeException { final SelectionInfo selectionInfo = getModel().getController().getSelectionInfo();