* make sure each filebot instance gets it's own locked ehcache dir

This commit is contained in:
Reinhard Pointner 2012-07-28 10:04:52 +00:00
parent 01d7650e9b
commit ae6a2cb0ae
8 changed files with 69 additions and 14 deletions

View File

@ -1,2 +1,2 @@
#!/bin/bash
java -Dunixfs=false -Xmx256m -Dapplication.deployment=deb -Dapplication.dir=$HOME/.filebot -Djava.io.tmpdir=$HOME/.filebot/temp -Djna.library.path=/usr/share/filebot -Djava.library.path=/usr/share/filebot -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -jar /usr/share/filebot/FileBot.jar "$@"
java -Dunixfs=false -Xmx256m -Dapplication.deployment=deb -Dapplication.dir=$HOME/.filebot -Djava.io.tmpdir=$HOME/.filebot/.temp -Djna.library.path=/usr/share/filebot -Djava.library.path=/usr/share/filebot -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -jar /usr/share/filebot/FileBot.jar "$@"

View File

@ -1,2 +1,2 @@
#!/bin/bash
java -Dunixfs=false -Dapplication.deployment=ipkg -Dapplication.dir=$HOME/.filebot -Djava.io.tmpdir=$HOME/.filebot/temp -Djna.library.path=/usr/share/filebot -Djava.library.path=/usr/share/filebot -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -jar /usr/share/filebot/FileBot.jar "$@"
java -Dunixfs=false -Dapplication.deployment=ipkg -Dapplication.dir=$HOME/.filebot -Djava.io.tmpdir=$HOME/.filebot/.temp -Djna.library.path=/usr/share/filebot -Djava.library.path=/usr/share/filebot -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -jar /usr/share/filebot/FileBot.jar "$@"

View File

@ -21,7 +21,7 @@
-Dsun.net.client.defaultReadTimeout=25000
# put all temporary files here
-Djava.io.tmpdir="%EXEDIR%/temp"
-Djava.io.tmpdir="%EXEDIR%/.temp"
# look for native libs here
-Djna.library.path="%EXEDIR%"

View File

@ -3,4 +3,4 @@ SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
dir_bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
java -Dunixfs=false -Xmx256m -Dapplication.deployment=portable "-Dapplication.dir=$dir_bin" "-Djava.io.tmpdir=$dir_bin/temp" "-Duser.home=$dir_bin" "-Djna.library.path=$dir_bin" "-Djava.library.path=$dir_bin" -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -Djava.util.prefs.PreferencesFactory=net.sourceforge.tuned.prefs.FilePreferencesFactory -Dnet.sourceforge.tuned.prefs.file=prefs.properties -jar "$dir_bin/FileBot.jar" "$@"
java -Dunixfs=false -Xmx256m -Dapplication.deployment=portable "-Dapplication.dir=$dir_bin" "-Djava.io.tmpdir=$dir_bin/.temp" "-Duser.home=$dir_bin" "-Djna.library.path=$dir_bin" "-Djava.library.path=$dir_bin" -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 -Djava.util.prefs.PreferencesFactory=net.sourceforge.tuned.prefs.FilePreferencesFactory -Dnet.sourceforge.tuned.prefs.file=prefs.properties -jar "$dir_bin/FileBot.jar" "$@"

View File

@ -3,7 +3,7 @@
<!--
Persistent disk store location
-->
<diskStore path="${ehcache.disk.store.dir}" />
<diskStore path="${cache.disk.store.dir}" />
<!--
Mandatory Default Cache configuration. These settings will be applied to caches

View File

@ -5,6 +5,7 @@ package net.sourceforge.filebot;
import static java.awt.GraphicsEnvironment.*;
import static javax.swing.JFrame.*;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.tuned.FileUtilities.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.Desktop;
@ -14,8 +15,10 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.FileLock;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
@ -86,6 +89,11 @@ public class Main {
if (args.clearUserData()) {
// clear preferences and cache
System.out.println("Reset preferences and clear cache");
for (File cache : getApplicationFolder().listFiles(FOLDERS)) {
if (cache.getName().startsWith(".")) {
delete(cache);
}
}
Settings.forPackage(Main.class).clear();
CacheManager.getInstance().clearAll();
}
@ -314,15 +322,56 @@ public class Main {
/**
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
*/
private static void initializeCache() {
System.setProperty("ehcache.disk.store.dir", new File(getApplicationFolder(), "cache").getAbsolutePath());
private static void initializeCache() throws Exception {
// prepare cache folder for this application instance
File cacheRoot = new File(getApplicationFolder(), ".cache");
try {
for (int i = 0; true; i++) {
File cache = new File(cacheRoot, String.format("%d", i));
if (!cache.isDirectory() && !cache.mkdirs()) {
throw new IOException("Failed to create cache dir: " + cache);
}
File lockFile = new File(cache, ".lock");
final RandomAccessFile handle = new RandomAccessFile(lockFile, "rw");
final FileLock lock = handle.getChannel().tryLock();
if (lock != null) {
// setup cache dir for ehcache
System.setProperty("cache.disk.store.dir", cache.getAbsolutePath());
// make sure to orderly shutdown cache
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
CacheManager.getInstance().shutdown();
try {
lock.release();
} catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString());
}
try {
handle.close();
} catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString());
}
}
});
// cache for this application instance is successfully set up and locked
return;
}
// try next lock file
handle.close();
}
} catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString(), e);
}
// use cache root itself as fail-safe fallback
System.setProperty("cache.disk.store.dir", cacheRoot.getAbsolutePath());
}

View File

@ -122,7 +122,7 @@ public class ArgumentProcessor {
}
} else {
// execute user script
System.setProperty("grape.root", new File(getApplicationFolder(), "grape").getAbsolutePath());
System.setProperty("grape.root", new File(getApplicationFolder(), ".grape").getAbsolutePath());
Bindings bindings = new SimpleBindings();
bindings.put("args", args.getFiles(false));

View File

@ -101,6 +101,12 @@ public final class FileUtilities {
}
public static boolean delete(File file) {
// delete files or files
return org.apache.commons.io.FileUtils.deleteQuietly(file);
}
public static byte[] readFile(File source) throws IOException {
InputStream in = new FileInputStream(source);