Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Acerbic/Bandcamp-downloader
base: 2015f665db
...
head fork: Acerbic/Bandcamp-downloader
compare: 8884a9dd05
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 04, 2012
Acerbic little fixes here and there 255255e
Commits on Oct 06, 2012
Acerbic fixes on GUI layout e6088b2
Acerbic isOK() page check and incorporated calling to TreeModel for visual
update into TreeNodePageWrapper
297e27e
Acerbic late night coding fix 8884a9d
View
182 src/dloader/GUI.java
@@ -16,7 +16,6 @@
import dloader.gui.MyWorker;
import dloader.gui.TreeNodePageWrapper;
import dloader.page.AbstractPage;
-import dloader.page.Track;
import javax.swing.tree.*;
@@ -43,7 +42,7 @@
private JButton btnFix;
private JButton btnUpdate;
private JButton btnRetag;
- private MyWorker newWorker;
+ private MyWorker theWorker;
// @SuppressWarnings("serial")
@@ -87,13 +86,13 @@ public GUI() throws HeadlessException {
JLabel lblNewLabel = new JLabel("Source URL:");
textFieldURL = new JTextField();
- lblNewLabel.setLabelFor(textFieldURL);
- textFieldURL.setColumns(10);
textFieldURL.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reInit();
}
});
+ lblNewLabel.setLabelFor(textFieldURL);
+ textFieldURL.setColumns(10);
textFieldDirectory = new JTextField();
textFieldDirectory.setEditable(false);
@@ -105,12 +104,11 @@ public void actionPerformed(ActionEvent e) {
tree = new JTree();
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
-// tree.setModel(new DefaultTreeModel(new TreeNodePageWrapper(null)));
tree.setModel(new DefaultTreeModel(null));
// tree.setCellRenderer(new MyRenderer());
tree.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
- lblStatus = new JLabel("kkkkss");
+ lblStatus = new JLabel("Status messages");
lblStatus.setHorizontalAlignment(SwingConstants.CENTER);
lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 18));
@@ -120,6 +118,7 @@ public void actionPerformed(ActionEvent e) {
reInit();
}
});
+
btnFetch = new JButton("Fetch");
btnFetch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -141,37 +140,37 @@ public void actionPerformed(ActionEvent e) {
JScrollPane scrollPane = new JScrollPane();
SpringLayout sl_panel = new SpringLayout();
- sl_panel.putConstraint(SpringLayout.WEST, textFieldURL, 10, SpringLayout.EAST, lblNewLabel_1);
- sl_panel.putConstraint(SpringLayout.WEST, textFieldDirectory, 10, SpringLayout.EAST, lblNewLabel_1);
+ sl_panel.putConstraint(SpringLayout.NORTH, scrollPane, 10, SpringLayout.SOUTH, btnFetch);
+ sl_panel.putConstraint(SpringLayout.NORTH, lblStatus, 2, SpringLayout.NORTH, btnFetch);
+ sl_panel.putConstraint(SpringLayout.WEST, lblStatus, 6, SpringLayout.EAST, btnUpdate);
sl_panel.putConstraint(SpringLayout.EAST, lblStatus, -10, SpringLayout.EAST, panel);
+ sl_panel.putConstraint(SpringLayout.NORTH, chckbxLog, 10, SpringLayout.SOUTH, textFieldDirectory);
+ sl_panel.putConstraint(SpringLayout.NORTH, chckbxUseCache, 10, SpringLayout.SOUTH, textFieldDirectory);
+ sl_panel.putConstraint(SpringLayout.EAST, chckbxUseCache, -10, SpringLayout.EAST, panel);
sl_panel.putConstraint(SpringLayout.EAST, chckbxLog, 0, SpringLayout.WEST, chckbxUseCache);
+ sl_panel.putConstraint(SpringLayout.NORTH, btnUpdate, 0, SpringLayout.NORTH, btnFetch);
+ sl_panel.putConstraint(SpringLayout.WEST, btnUpdate, 6, SpringLayout.EAST, btnFix);
+ sl_panel.putConstraint(SpringLayout.NORTH, btnFix, 0, SpringLayout.NORTH, btnFetch);
+ sl_panel.putConstraint(SpringLayout.WEST, btnFix, 6, SpringLayout.EAST, btnFetch);
+ sl_panel.putConstraint(SpringLayout.NORTH, btnFetch, 6, SpringLayout.SOUTH, btnRetag);
+ sl_panel.putConstraint(SpringLayout.WEST, btnFetch, 0, SpringLayout.WEST, scrollPane);
+ sl_panel.putConstraint(SpringLayout.EAST, btnFetch, 78, SpringLayout.WEST, panel);
+ sl_panel.putConstraint(SpringLayout.NORTH, btnRetag, 10, SpringLayout.SOUTH, lblNewLabel_1);
+ sl_panel.putConstraint(SpringLayout.NORTH, textFieldDirectory, -2, SpringLayout.NORTH, lblNewLabel_1);
+ sl_panel.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 15, SpringLayout.SOUTH, lblNewLabel);
+ sl_panel.putConstraint(SpringLayout.WEST, textFieldURL, 35, SpringLayout.EAST, lblNewLabel);
+ sl_panel.putConstraint(SpringLayout.EAST, textFieldURL, -6, SpringLayout.WEST, btnPrefetch);
+ sl_panel.putConstraint(SpringLayout.NORTH, btnPrefetch, -5, SpringLayout.NORTH, lblNewLabel);
+ sl_panel.putConstraint(SpringLayout.EAST, btnPrefetch, 0, SpringLayout.EAST, scrollPane);
+ sl_panel.putConstraint(SpringLayout.NORTH, textFieldURL, -2, SpringLayout.NORTH, lblNewLabel);
+ sl_panel.putConstraint(SpringLayout.WEST, textFieldDirectory, 115, SpringLayout.WEST, panel);
sl_panel.putConstraint(SpringLayout.EAST, textFieldDirectory, -10, SpringLayout.EAST, panel);
- sl_panel.putConstraint(SpringLayout.EAST, btnPrefetch, -10, SpringLayout.EAST, panel);
- sl_panel.putConstraint(SpringLayout.EAST, chckbxUseCache, -10, SpringLayout.EAST, panel);
sl_panel.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.SOUTH, panel);
sl_panel.putConstraint(SpringLayout.EAST, scrollPane, -10, SpringLayout.EAST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, btnPrefetch, 14, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.EAST, textFieldURL, -6, SpringLayout.WEST, btnPrefetch);
- sl_panel.putConstraint(SpringLayout.NORTH, textFieldURL, 15, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, textFieldDirectory, 48, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, chckbxUseCache, 70, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, chckbxLog, 70, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, lblStatus, 100, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.WEST, lblStatus, 214, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, btnUpdate, 103, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.WEST, btnUpdate, 137, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, btnFix, 103, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.WEST, btnFix, 84, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, btnFetch, 103, SpringLayout.NORTH, panel);
- sl_panel.putConstraint(SpringLayout.WEST, btnFetch, 10, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.EAST, btnFetch, 78, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, btnRetag, 71, SpringLayout.NORTH, panel);
sl_panel.putConstraint(SpringLayout.WEST, btnRetag, 10, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 51, SpringLayout.NORTH, panel);
sl_panel.putConstraint(SpringLayout.WEST, lblNewLabel_1, 10, SpringLayout.WEST, panel);
sl_panel.putConstraint(SpringLayout.NORTH, lblNewLabel, 18, SpringLayout.NORTH, panel);
sl_panel.putConstraint(SpringLayout.WEST, lblNewLabel, 10, SpringLayout.WEST, panel);
- sl_panel.putConstraint(SpringLayout.NORTH, scrollPane, 144, SpringLayout.NORTH, panel);
sl_panel.putConstraint(SpringLayout.WEST, scrollPane, 10, SpringLayout.WEST, panel);
panel.setLayout(sl_panel);
@@ -205,12 +204,17 @@ public GUI(String title, GraphicsConfiguration gc) {
public void init() {
textFieldDirectory.setText(Main.saveTo);
- textFieldURL.setText(Main.baseURL);
- rootPage = AbstractPage.bakeAPage(null, Main.baseURL, Main.saveTo, null);
- lblStatus.setText("Preparing");
chckbxLog.setSelected( Main.logger != null);
chckbxUseCache.setSelected(Main.allowFromCache);
- ((DefaultTreeModel) tree.getModel()).setRoot(new TreeNodePageWrapper(rootPage));
+ try {
+ rootPage = AbstractPage.bakeAPage(null, Main.baseURL, Main.saveTo, null);
+ textFieldURL.setText(rootPage.url.toString());
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ lblStatus.setText("Preparing");
+
+ setRootNodeForRootPage();
initPrefetch();
}
@@ -218,11 +222,15 @@ public void init() {
* Starting cache-only quick lookup
*/
private void initPrefetch() {
- if (newWorker == null) {
+ if (theWorker == null) {
lblStatus.setText("Prefetching");
- newWorker = new MyWorker(rootPage, JobType.READCACHEPAGES);
- newWorker.execute();
+ theWorker = new MyWorker(rootPage, JobType.READCACHEPAGES);
+ theWorker.execute();
btnPrefetch.setEnabled(false);
+ btnFetch.setEnabled(false);
+ btnFix.setEnabled(false);
+ btnRetag.setEnabled(false);
+ btnUpdate.setEnabled(false);
}
}
@@ -230,22 +238,35 @@ private void finishPrefetch() {
if (lblStatus.getText().equals("Prefetching"))
lblStatus.setText("");
btnPrefetch.setEnabled(true);
- newWorker = null;
+ btnPrefetch.setEnabled(true);
+ btnFetch.setEnabled(true);
+ btnFix.setEnabled(true);
+ btnRetag.setEnabled(true);
+ btnUpdate.setEnabled(true);
+ theWorker = null;
+ unfoldFirst();
+ // commented out for later. now we are in testing mode.
+// initScan();
+ }
+
+ /**
+ * Shows children of the rootPage's node elements
+ */
+ private void unfoldFirst() {
TreeNodePageWrapper target = (TreeNodePageWrapper)tree.getModel().getRoot();
try {
target = (TreeNodePageWrapper) target.getFirstChild();
tree.expandPath(new TreePath(target.getPath()));
} catch (NoSuchElementException e) {
}
-
}
private void initScan() {
- if (newWorker == null) {
+ if (theWorker == null) {
lblStatus.setText("Scanning");
- newWorker = new MyWorker(rootPage, JobType.UPDATEPAGES);
- newWorker.execute();
+ theWorker = new MyWorker(rootPage, JobType.UPDATEPAGES);
+ theWorker.execute();
btnFetch.setEnabled(false);
}
}
@@ -253,8 +274,10 @@ private void initScan() {
private void finishScan() {
if (lblStatus.getText().equals("Scanning"))
lblStatus.setText("");
- newWorker = null;
+ theWorker = null;
btnFetch.setEnabled(true);
+
+ unfoldFirst();
}
private void reInit() {
@@ -263,16 +286,44 @@ private void reInit() {
textFieldURL.setText(newURL);
if (newURL.equals(rootPage.url.toString())) return;
- AbstractPage newRootPage = AbstractPage.bakeAPage(null, newURL, textFieldDirectory.getText(), null);
+ AbstractPage newRootPage = null;
+ try {
+ newRootPage = AbstractPage.bakeAPage(null, newURL, textFieldDirectory.getText(), null);
+ } catch (IllegalArgumentException e) {
+ textFieldURL.setText(rootPage.url.toString());
+ }
if (newRootPage != null) {
rootPage = newRootPage;
+ setRootNodeForRootPage();
- TreeNodePageWrapper x = new TreeNodePageWrapper(null);
- x.add(new TreeNodePageWrapper(rootPage)); // proxy null root for better display
- ((DefaultTreeModel) tree.getModel()).setRoot(x);
initPrefetch();
+ btnPrefetch.setEnabled(false);
}
}
+
+ private void setRootNodeForRootPage() {
+ DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
+ TreeNodePageWrapper x = new TreeNodePageWrapper(null, model); // proxy null root for better display
+ x.add(new TreeNodePageWrapper(rootPage, model));
+ model.setRoot(x);
+
+ }
+ /**
+ * Captures SwingWorker finish jobs event
+ * @param root - root job for the work in question (not used atm)
+ * @param jobType - job type
+ */
+ public void myWorkerDone (AbstractPage root, JobMaster.JobType jobType) {
+ switch (jobType) {
+ case READCACHEPAGES: finishPrefetch(); break;
+ case SAVEDATA:
+ break;
+ case UPDATEPAGES: finishScan(); break;
+ default:
+ break;
+ }
+ }
+
/**
* Receiving message from MyWorker (SwingWorker)
* @param p - page node to update
@@ -305,7 +356,7 @@ else if (!p.getParent().childPages.contains(p))
// currentPage's node was not found in parent node
// add new item under this parent
- childNode = new TreeNodePageWrapper(childPage);
+ childNode = new TreeNodePageWrapper(childPage, model);
if (childPage.getParent() == null)
parentNode.add(childNode); // to the end
@@ -320,9 +371,10 @@ else if (!p.getParent().childPages.contains(p))
// new item's children if any (that way they maintain their order)
for (AbstractPage subPage: childPage.childPages) {
- TreeNodePageWrapper subChild = new TreeNodePageWrapper(subPage);
+ TreeNodePageWrapper subChild = new TreeNodePageWrapper(subPage, model);
childNode.add(subChild);
}
+
int[] indices = new int[1];
indices[0] = parentNode.getIndex(childNode);
model.nodesWereInserted(parentNode, indices); // notification to repaint
@@ -342,20 +394,16 @@ else if (!p.getParent().childPages.contains(p))
)
trimBranch(parentNode, model);
- // pass message to the user object and refresh its visual if needed
-// TreeNodePageWrapper parentWrapper = (TreeNodePageWrapper)parentNode.getUserObject();
+ // usually unfolding happens only after job is finished (for performance), but in
+ // case of new page downloads it is visually more pleasing to see what is going on asap
+ if (message.equals("download finished") && parentNode.page.equals(pathToPage.getFirst()))
+ unfoldFirst();
- // TODO: consider using EventListener mechanic
- if (parentNode.update(message, value)) {
- model.nodeChanged(parentNode);
- if (parentNode.page instanceof Track) {
- TreeNodePageWrapper gParentNode = (TreeNodePageWrapper) parentNode.getParent();
- if (gParentNode != null) {
- gParentNode.kidChanged(parentNode, gParentNode, message, value);
- model.nodeChanged(gParentNode);
- }
- }
- }
+ // pass message to the user object and refresh its visual if needed
+ parentNode.update(message, value);
+// if (parentNode.update(message, value)) {
+// model.nodeChanged(parentNode);
+// }
}
@@ -441,22 +489,10 @@ private void trimBranch(TreeNodePageWrapper branch, DefaultTreeModel model) {
// with updated net data.
model.removeNodeFromParent(element);
//since this page is no more of our concern, all jobs executing and pending are irrelevant CPU consumers
- newWorker.stopJobsForPage(element.page);
+ theWorker.stopJobsForPage(element.page);
}
}
- // captures SwingWorker finish jobs event
- public void myWorkerDone (AbstractPage root, JobMaster.JobType jobType) {
- switch (jobType) {
- case READCACHEPAGES: finishPrefetch(); break;
- case SAVEDATA:
- break;
- case UPDATEPAGES: finishScan(); break;
- default:
- break;
- }
- }
-
/**
* Search children nodes of a parentNode for a TreeNodePageWrapper containing given AbstractPage.
* @param parentNode - parent of nodes to search among
View
33 src/dloader/gui/TreeNodePageWrapper.java
@@ -3,6 +3,8 @@
import java.util.Enumeration;
import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeModel;
import dloader.page.AbstractPage;
import dloader.page.Track;
@@ -24,6 +26,7 @@
private static final long serialVersionUID = -265090747493368344L;
public final AbstractPage page; //wrapped object
+ public final DefaultTreeModel model; //backref to model
// TODO job progress flags and logs
boolean readFromCache = false;
@@ -36,20 +39,21 @@
int kidsInProcessing = 0;
- public TreeNodePageWrapper(AbstractPage page) {
+ public TreeNodePageWrapper(AbstractPage page, TreeModel treeModel) {
super(null);
+ this.model = (DefaultTreeModel) treeModel;
this.page = page;
}
/**
* Update flags and states of this node visual representation
- * @param type
- * @param report
+ * @param message
+ * @param value
* @return true if node must be repainted
*/
- public boolean update(String type, long report) {
+ public boolean update(String message, long value) {
boolean updateVisuals = false;
- switch (type) {
+ switch (message) {
//messages reported by ReadCacheJob and GetPageJob:
case "checking cache": break;
case "read from cache":
@@ -95,6 +99,16 @@ public boolean update(String type, long report) {
*/
}
+
+ if (page instanceof Track) {
+ TreeNodePageWrapper parentNode = (TreeNodePageWrapper) getParent();
+ if (parentNode != null) {
+ parentNode.kidChanged(this, message, value);
+ model.nodeChanged(parentNode);
+ }
+ }
+ if (updateVisuals)
+ model.nodeChanged(this);
return updateVisuals;
}
@@ -126,13 +140,13 @@ public String toString() {
page.childPages.size()+"]</span>";
if (downloading) {
- title = "Scanning... " + title;
+ title = title + " (Scanning...)";
}
else if (downloadPageFailed) {
title = "Scan failed: " + title;
styleCompilation += "span#title {font: bold}";
} else if (downloadPageQ) {
- title = "In queue for scan... " + title;
+ title = title + " (In queue for scan...)";
}
// finalize title
@@ -153,12 +167,11 @@ else if (downloadPageFailed) {
"</u>"+ bottom;
}
- public void kidChanged(TreeNodePageWrapper kidWrapper,
- DefaultMutableTreeNode thisNode, String message, long value) {
+ public void kidChanged(TreeNodePageWrapper kidWrapper, String message, long value) {
kidsInProcessing = 0;
for (@SuppressWarnings("unchecked")
- Enumeration<DefaultMutableTreeNode> children = thisNode.children(); children.hasMoreElements();) {
+ Enumeration<DefaultMutableTreeNode> children = children(); children.hasMoreElements();) {
TreeNodePageWrapper kid = (TreeNodePageWrapper) children.nextElement();
if (kid.downloading || kid.downloadPageQ)
View
22 src/dloader/page/AbstractPage.java
@@ -87,7 +87,6 @@
* Due to efficiency issues, elements should be added as .addAll(...) when possible
*/
public final
-// Queue<AbstractPage> childPages = new ConcurrentLinkedQueue<>();
List<AbstractPage> childPages = new CopyOnWriteArrayList<>();
@@ -121,10 +120,6 @@ public AbstractPage(String stringURL, String saveTo, AbstractPage parent) throws
catch (MalformedURLException e) {throw new IllegalArgumentException(e);}
catch (NullPointerException e) {throw new IllegalArgumentException(e);}
- //path in question may not exist at this point and will be created by parent page later.
-// Path p = Paths.get(saveTo);
-// if (! (Files.isDirectory(p) && Files.isWritable(p)))
-// throw new IllegalArgumentException();
this.saveTo = saveTo;
this.parent = parent;
}
@@ -161,6 +156,7 @@ String getFSSafeName(String name) throws IOException {
return name;
}
+ // TODO: this assumes children type is fixed and controlled by parent type, but it may not hold true, i.e. Track within Discography without intermediary album
/**
* Returns an XPath string to get links to children pages
* from current page. All tags in the path are in "pre" namespace.
@@ -416,12 +412,13 @@ boolean updateFromNet(ProgressReporter reporter) throws ProblemsReadingDocumentE
setTitle(tempPage.getTitle());
// somewhat awkward way to copy custom object data from temp object
readCacheSelf(tempPage.getSpecificDataXML());
-
+
+ // modifying child without locking because child pages are not published yet.
+ for (AbstractPage child: tempPage.childPages)
+ child.parent = this;
+
// lets try to save some existing children for performance
mergeNewChildren(new LinkedList<>(childPages), tempPage.childPages);
-
- for (AbstractPage child: childPages)
- child.parent = this;
}
return true;
}
@@ -433,6 +430,8 @@ boolean updateFromNet(ProgressReporter reporter) throws ProblemsReadingDocumentE
*/
private void mergeNewChildren (Collection<AbstractPage> oldChildren, Collection<AbstractPage> newChildren) {
childPages.clear(); // discard previous data if any.
+ List<AbstractPage> resultChildren = new LinkedList<>();
+
for (AbstractPage newChild: newChildren) {
// search if exactly that child existed.
AbstractPage oldChild = null;
@@ -443,13 +442,12 @@ private void mergeNewChildren (Collection<AbstractPage> oldChildren, Collection<
oldChild = current; break;
}
- List<AbstractPage> resultChildren = new LinkedList<>();
if (oldChild != null) {
resultChildren.add(oldChild);
} else
resultChildren.add(newChild);
- childPages.addAll(resultChildren);
}
+ childPages.addAll(resultChildren); // at this point new children become published, as childPages is of unprotected access
}
/**
* Saves this page data into XML tree.
@@ -591,7 +589,7 @@ public AbstractPage getChildByURLString(String string) {
*/
//XXX: may be should be complemented with "lastUpdated" time stamp.
public
- boolean isPageOK() {
+ boolean isOK() {
if (getTitle()==null || getTitle().isEmpty())
return false;
return true;
View
4 src/dloader/page/Album.java
@@ -163,7 +163,7 @@ boolean isSavingNotRequired() {
}
@Override
- public boolean isPageOK() {
- return super.isPageOK() && (coverUrl != null);
+ public boolean isOK() {
+ return super.isOK() && (coverUrl != null);
}
}
View
4 src/dloader/page/Track.java
@@ -351,8 +351,8 @@ String getTrackFileName() {
}
@Override
- public boolean isPageOK() {
- if (! super.isPageOK() ) return false;
+ public boolean isOK() {
+ if (! super.isOK() ) return false;
for (String p: XMLCacheDataKeys)
if (getProperty(p) == null)
View
6 src/dloader/pagejob/GetPageJob.java
@@ -7,7 +7,7 @@
* Job to read page data from cache and if cache is unavailable - download.
* Starts the same jobs for children nodes.
*
- * NOTE the "package-default" visibility on class, as it is used only be other class - DownloadPage.
+ * NOTE the "package-default" visibility on class, as it is used only be other class - UpdatePageJob.
* @author Acerbic
*
*/
@@ -26,12 +26,12 @@ public GetPageJob(AbstractPage page, JobMaster owner) {
@Override
public void run() {
report ("checking cache", 1);
- if (page.loadFromCache()) {
+ if (page.loadFromCache() && page.isOK()) {
//note: this iterator does not require locking because of CopyOnWriteArrayList implementation
for (AbstractPage child: page.childPages)
jobMaster.submit(new GetPageJob(child,jobMaster));
report("read from cache", 1);
- } else {
+ } else {
report("cache reading failed, submitting download job", 1);
jobMaster.submit(new UpdatePageJob(page,jobMaster, false));
}
View
5 src/dloader/pagejob/UpdatePageJob.java
@@ -47,11 +47,6 @@ public void run() {
else
report("cache reading failed", 1);
try {
-// try {
-// Thread.sleep(3000);
-// } catch (InterruptedException e) {
-// e.printStackTrace();
-// }
if (page.updateFromNet(this) || forceDownload) {
page.saveToCache();
//note: this iterator does not require locking because of CopyOnWriteArrayList implementation
View
14 test/dloader/page/DiscographyTest.java
@@ -46,9 +46,9 @@ public void tearDown() throws Exception {
public void testCaching() {
Main.cache = new XMLCache("test/pages_scan_cache.xml");
Discography page = new Discography("http://homestuck.bandcamp.com",null,null);
- assertFalse(page.isPageOK());
+ assertFalse(page.isOK());
assertTrue(page.loadFromCache());
- assertTrue(page.isPageOK());
+ assertTrue(page.isOK());
assertEquals("Homestuck", page.getTitle());
assertEquals(15, page.childPages.size());
@@ -56,9 +56,9 @@ public void testCaching() {
page.saveToCache();
Discography page2 = new Discography("http://homestuck.bandcamp.com",null,null);
- assertFalse(page2.isPageOK());
+ assertFalse(page2.isOK());
assertTrue(page2.loadFromCache());
- assertTrue(page2.isPageOK());
+ assertTrue(page2.isOK());
assertEquals("Homestuck", page2.getTitle());
assertEquals(15, page2.childPages.size());
@@ -75,7 +75,7 @@ public void testUpdating() {
fail("can't load from file");
}
assertNotNull(page.getChildByURLString("file:/album/homestuck-vol-9")); //the way relative url is resolved
- assertTrue(page.isPageOK());
+ assertTrue(page.isOK());
assertEquals("Homestuck", page.getTitle());
assertEquals(20, page.childPages.size());
try {
@@ -83,7 +83,7 @@ public void testUpdating() {
} catch (ProblemsReadingDocumentException e) {
fail("can't load from file");
}
- assertTrue(page.isPageOK());
+ assertTrue(page.isOK());
page.childPages.clear(); // now page is different.
try {
@@ -91,7 +91,7 @@ public void testUpdating() {
} catch (ProblemsReadingDocumentException e) {
fail("can't load from file");
}
- assertTrue(page.isPageOK());
+ assertTrue(page.isOK());
}
@Test

No commit comments for this range

Something went wrong with that request. Please try again.