mirror of
https://bitbucket.org/projectswg/cucore.git
synced 2026-01-16 23:04:20 -05:00
Added additional information to errors in ObjectDatabase
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user