Get updated in the wonderful world of jAlbum

For those of you that read my other blogs, yep yet another one dealing with the Jalbum Webserver.

If you want to get an overview of the Webserver, you can see my other blogs with links to manuals and tutorials, this one starts to get a bit more technical.  There is a potential problem with the current implementation of the Auto-update feature of the built-in Webserver in Jalbum, that as soon as a change is detected, it begins an auto-update and regeneration of an Album.

Why is this bad you ask? Well for starters, there's no guarantee that all your picture changes will be complete before the album is done regenerating.  So if you are still adding or removing files, and the auto-update triggered, your new album could be missing a lot of pictures or changes.

So, armed with Google and a few cans of Mountain Dew, I went about messing around with the Java Code in Jalbum's Webserver.  On my last can of Mountain Dew, things started to drop in place as well as a muscle twitch in my left eye surfaced, probably from all the caffeine......

The goal was to find a way to detect file changes, but put the Auto-Update feature on hold until NO further changes were detected.  So, you can be adding files or deleting folders, and as long a change is happening once every minute, the auto-update feature will be placed on hold.

After a minute has passed, and no further changes are detected, then the auto-update album command kicks off.  This is really handy if you are using Hamachi (again read my other blogs !!!) and family and friends continue to add files and folders regularly.

Below is the snippet of what code needs to be modified in which file, a simple change but it really helps out when using the auto-update feature of Jalbum.

I hacked the "Server Mode.bsh" file to first detect a change occurred. In then enters a loop and checks for changes every minute. If it still detects changes occurring, it waits for another minute and loops. After a minute of no file changes, it then goes off and updates the album.

The original source code at the bottom of the .bsh file:

long lastModified = IO.deepLastModified(rootImageDirectory);

log.println("Monitoring directory " + rootImageDirectory.getName() + "...");
while (running) {
Thread.currentThread().sleep(SLEEP_TIME);
long newLastModified = IO.deepLastModified(rootImageDirectory);
if (newLastModified > lastModified) {
log.println("Detected file system change. Making album at " + new Date() + "...");
lastModified = newLastModified;
if (window != null) window.doMakeAlbum();
else engine.makeAlbum();
log.println("Done");
log.println("Monitoring directory " + rootImageDirectory.getName() + "...");
}
}
System.out.println("Exiting server mode");


My hacked code:

long lastModified = IO.deepLastModified(rootImageDirectory);

log.println("Monitoring directory " + rootImageDirectory.getName() + "...");
while (running) {
Thread.currentThread().sleep(SLEEP_TIME);
long newLastModified = IO.deepLastModified(rootImageDirectory);
if (newLastModified > lastModified) {
while (newLastModified != lastModified) {
lastModified = IO.deepLastModified(rootImageDirectory);
Thread.currentThread().sleep(60000);
log.println("Waiting for Changes to stop before regenerating Album " + "...");
newLastModified = IO.deepLastModified(rootImageDirectory);
}

log.println("Detected file system change. Making album at " + new Date() + "...");
lastModified = newLastModified;
if (window != null) window.doMakeAlbum();
else exec ("jalbum_update.bat");
log.println("Done");
log.println("Monitoring directory " + rootImageDirectory.getName() + "...");
}
}
System.out.println("Exiting server mode");


Hold on buckaroo, we aren't done yet.

In the original code the following code started the album generation:

if (window != null) window.doMakeAlbum();
else engine.makeAlbum();


This would generate all, and would be very, very time consuming, each time a change is detected. So, yet another hack.

In my code, I call an external batch file using the command instead:

if (window != null) window.doMakeAlbum();
else exec ("jalbum_update.bat");


Inside that batch file, the following command exists:

JAlbumwin.exe -appendImages -projectFile "E:\Data Drive\Pictures\jalbum-settings.jap"

Now, instead of using the engine.makeAlbum command, you can then call a batch file with almost unlimited options for building. With mine, I set it to "Make Changes" only by using the -appendImages flag.  Also, once you go outside to a batch file, you now have many options dealing with manipulate of files through batch commands.

So, in the end, my hacked code now tells the server to detect changes to the directory structure, if a change is detected wait until no changes have been detected for at least 1 minute. If one minute passes and no changes detected, then kick off an Album Regen.

 Happy Jalbuming,

Cinoaz (aka Chris Bomicino) 

Comments

Sign in to post

Add your comment

trevorbray

2 years ago trevorbray

Just found this, thanks. However when i use Notepad to edit it won't let me save BSH. tells me the path is incorrect. Any ideas?

appreciate it, Trev

new

2 years ago new

Thread.currentThread().sleep(SLEEP_T IME);
should be written as
Thread.sleep(SLEEP_TIME);