This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 43 - Pages: 3 [ Previous | 1 2 3 ] - Last Post: 20 Sep 22, 13:57 Last Post By: davidekholm Threads: [ Previous | Next ]
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 17 Sep 22, 14:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
One more update. I figure that this will be the most common use case for skins:
dc.refresh(); // Files are now present and current in the primary cache dir
if (dc.getLastException() != null) {
	throw new OperationAbortedException(dc.getLastExcception().getMessage());
}
, so in order to save you typing, you can now simply call refresh(true); That version will abort in case there was a problem downloading something that's missing from the cache.

This isn't working. If the original file and the cached file are both missing, it doesn't throw any error. And that's really the only condition I'm trying to capture.

ETA: Correction. That's what happens if the now-missing file is still listed in the JSON file. If the JSON file is also gone, the add() simply blows up.

ETA: Still not working, even after I corrected the typo: dc.getLastExcception. ;)
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 17 Sep 22, 17:04   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:

BeanShell is very unhappy with this. It encounters a parse error when it hits dc.onError(dce -> {.

Naturally, it's because BeanShell doesn't support either generics nor lambdas. That's why I always use Groovy these days. The same Groovy code compiles as Java too, but if you REALLY want to use BeanShell, then it looks like this:
import net.jalbum.util.*;
import java.util.function.*;
 
dc = new DiskCache(rootFolder.file);
dc.onError(new Consumer() {
	public void accept(DiskCache.DCException dce) {
		System.err.println(dce.getMessage());
		System.err.println("Couldn't download font " + dce.getURL() + " to " + dce.getLocalFile().getName());
		if (!dce.getLocalFile().exists()) {
			dce.showDialog(window);
		}	
	}
});
 
dc.add("http://jalbum.net/download2/jalbum-core.jar");
dc.refresh(); // Files are now present and current in the primary cache dir
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 17 Sep 22, 17:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:

ETA: Correction. That's what happens if the now-missing file is still listed in the JSON file. If the JSON file is also gone, the add() simply blows up.

ETA: Still not working, even after I corrected the typo: dc.getLastExcception. ;)


It's working here :-). Please ensure that you're running the latest beta. I bumped the revision now to b11 and ensure that the database file writing isn't being affected by multiple threads. I've now uploaded it. When you say "blows up" what exactly do you mean then? I might need a reproducible case here.
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 17 Sep 22, 17:32   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Naturally, it's because BeanShell doesn't support either generics nor lambdas. That's why I always use Groovy these days.

That's pretty much what I suspected.

I take note of the fact that, AFAIK, there is not a single released skin that's using Groovy. Makes it a bit difficult to see how it differs from BeanShell, and to figure out what changes would be required. On my list, but not right now.
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 17 Sep 22, 17:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
It's working here :-). Please ensure that you're running the latest beta.

I still had b9, even after doing another download. Now I've got b11. Will test further after I get out of the "keep my wits about me" collection of things I'm in the middle of at the moment. Nothing like editing the template files of seven skins that have similar, but not identical, code. If I lose track of what I'm doing, I end up lost in the wilderness.
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 17 Sep 22, 18:12   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:

I take note of the fact that, AFAIK, there is not a single released skin that's using Groovy. Makes it a bit difficult to see how it differs from BeanShell, and to figure out what changes would be required. On my list, but not right now.

You know classic Java, then you know Groovy. Basically all Java statements work in Groovy too these days.
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 17 Sep 22, 18:15   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
BTW: I also made the console's scrolling a bit better. Now it scrolls to reveal the last printed line. Previously it simply scrolled to the bottom. If you had cleared the result pane but scrolled to the bottom and then printed something, then you'd have to scroll up to reveal it. Now the console scrolls in both directions in order to reveal the last printed stuff.
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 17 Sep 22, 18:24   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
RobM emailed me about the DiskCache API, which isn't "out there" yet. I emailed him the copy I had, but that one's now dangerously out-of-date. New version available?
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 17 Sep 22, 18:40   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 18 Sep 22, 03:37   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
When you say "blows up" what exactly do you mean then? I might need a reproducible case here.

Check your email.
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 19 Sep 22, 21:16   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Just for the sake of posterity, this led to the discovery of some deep bugs in the way DiskCache was handling IO errors. After the latest beta core update, the ultimate solution to error trapping proves to be something like this:
at the start of init.bsh:
 
import net.jalbum.util.*;
 
then later:
 
// Refresh disk cache and write to res
 
try {
	dc.refresh();
} catch (DiskCache.DCException ex) {
	System.err.println(ex.getMessage());
	ex.showDialog(window); 
}
dc.syncTo(resDirectory);
The skin developer can, of course, handle the catch however he likes, aborting the album build, or ignoring it completely. This example warns the user that something was amiss, and puts the warning in the console, but continues to build the album.
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 20 Sep 22, 12:43   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I can add that the DCException is only thrown if DiskCache can't download a particular file AND that one is missing from the local cache too.

Now the API is updated too.
JeffTucker

Posts: 8,321
Registered: 31-Jan-2006
Re: Some DiskCache questions
Posted: 20 Sep 22, 13:06   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
I can add that the DCException is only thrown if DiskCache can't download a particular file AND that one is missing from the local cache too.

Yes, that's the desired behavior. It's a bit like choosing "Copy" for adding objects to a project - you can move or delete the original, and things still work, as long as the copy is still there. It's only when both are missing that things get ugly. ;)
davidekholm

Posts: 4,255
Registered: 18-Oct-2002
Re: Some DiskCache questions
Posted: 20 Sep 22, 13:57   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
and we can further add that SHOULD a skin developer want to inform the user about a failed cache refresh when the local version exists, then he can use the onError callback and simply print a warning to the system console for instance. Use System.out to simply print a warning message and use System.err to also trigger the triangle to show in the bottom-right corner.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums