Added additional information to errors in ObjectDatabase

This commit is contained in:
Obique PSWG
2015-12-30 16:58:48 -06:00
parent 74b4096125
commit b816d62b24
2 changed files with 5 additions and 12 deletions

View File

@@ -135,8 +135,10 @@ public class CachedObjectDatabase<V extends Serializable> extends ObjectDatabase
}
public synchronized boolean load() {
if (!fileExists())
if (!fileExists()) {
Log.e("CachedObjectDatabase", "load() - file '%s' does not exist!", getFile());
return false;
}
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(getFile()));
@@ -152,6 +154,7 @@ public class CachedObjectDatabase<V extends Serializable> extends ObjectDatabase
} catch (EOFException e) {
loaded = true;
} catch (IOException | ClassNotFoundException | ClassCastException e) {
Log.e("CachedObjectDatabase", "load() - unable to load with error: %s - %s", e.getClass().getSimpleName(), e.getMessage());
System.err.println("CachedObjectDatabase: Unable to load with error: " + e.getClass().getSimpleName() + " - " + e.getMessage());
return false;
} finally {

View File

@@ -40,7 +40,6 @@ public abstract class ObjectDatabase<V extends Serializable> {
private final File file;
private final ScheduledExecutorService autosaveService;
private final Runnable autosaveRunnable;
public ObjectDatabase(String filename) {
this(filename, TimeUnit.MINUTES.toMillis(5));
@@ -56,13 +55,8 @@ public abstract class ObjectDatabase<V extends Serializable> {
if (autosaveInterval < 60000)
autosaveInterval = 60000;
this.autosaveService = Executors.newSingleThreadScheduledExecutor(ThreadUtilities.newThreadFactory("odb-autosave-"+file.getName()));
this.autosaveRunnable = new Runnable() {
public void run() {
autosavePeriodic();
}
};
// Setup
autosaveService.scheduleAtFixedRate(autosaveRunnable, autosaveInterval, autosaveInterval, TimeUnit.MILLISECONDS);
autosaveService.scheduleAtFixedRate(() -> save(), autosaveInterval, autosaveInterval, TimeUnit.MILLISECONDS);
try {
createFilesAndDirectories();
} catch (IOException e) {
@@ -70,10 +64,6 @@ public abstract class ObjectDatabase<V extends Serializable> {
}
}
private void autosavePeriodic() {
save();
}
private void createFilesAndDirectories() throws IOException {
if (file.exists())
return;