diff --git a/src/dorkbox/util/storage/DiskStorage.java b/src/dorkbox/util/storage/DiskStorage.java index e19e868..5d24a79 100644 --- a/src/dorkbox/util/storage/DiskStorage.java +++ b/src/dorkbox/util/storage/DiskStorage.java @@ -371,10 +371,18 @@ class DiskStorage implements Storage { } } + /** + * Closes and removes this storage from the storage system. This is the same as calling {@link StorageSystem#close(Storage)} + */ + public + void close() { + StorageSystem.close(this); + } + /** * Closes the database and file. */ - void close() { + void closeFully() { // timer action runs on THIS thread, not timer thread if (timer != null) { this.timer.delay(0L); @@ -507,7 +515,7 @@ class DiskStorage implements Storage { /** * Save the storage to disk, immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ @Override public final @@ -523,9 +531,9 @@ class DiskStorage implements Storage { } /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then saves the storage to disk, immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ @Override public @@ -542,9 +550,9 @@ class DiskStorage implements Storage { } /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then save the storage to disk, immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ @Override public @@ -563,9 +571,9 @@ class DiskStorage implements Storage { } /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then save the storage to disk, immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ @Override public diff --git a/src/dorkbox/util/storage/MemoryStorage.java b/src/dorkbox/util/storage/MemoryStorage.java index c94fb87..63c44f8 100644 --- a/src/dorkbox/util/storage/MemoryStorage.java +++ b/src/dorkbox/util/storage/MemoryStorage.java @@ -210,53 +210,86 @@ class MemoryStorage implements Storage { return true; } + /** + * @return null. There is no file that backs this storage + */ @Override public File getFile() { return null; } + /** + * Gets the backing file size. + * + * @return 0. There is no file that backs this storage + */ @Override public long getFileSize() { return 0; } + /** + * @return false. Writes to in-memory storage are immediate. + */ @Override public boolean hasWriteWaiting() { return false; } + /** + * @return 0. There is no file that backs this storage + */ @Override public long getSaveDelay() { return 0; } + + /** + * There is no file that backs this storage, so saves/writes are immediate + */ @Override public void setSaveDelay(final long milliSeconds) { + // no-op } + /** + * @return the version of data stored in the database + */ @Override public synchronized int getVersion() { return version; } + /** + * Sets the version of data stored in the database + */ @Override public synchronized void setVersion(final int version) { this.version = version; } + /** + * There is no file that backs this storage, so writes are immediate and saves do nothgin + */ @Override public void save() { // no-op } + /** + * Adds a key/value pair to the storage. + *

+ * There is no file that backs this storage, so writes are immediate and saves do nothing + */ @Override public void putAndSave(final String key, final Object object) { @@ -264,17 +297,36 @@ class MemoryStorage implements Storage { // no-save! } + /** + /** + * Adds a key/value pair to the storage. + *

+ * There is no file that backs this storage, so writes are immediate and saves do nothing + */ @Override public void putAndSave(final byte[] key, final Object object) { put(key, object); - // no-save! + // no save because we are in memory! } + /** + * Adds a key/value pair to the storage. + *

+ * There is no file that backs this storage, so writes are immediate and saves do nothing + */ @Override public void putAndSave(final StorageKey key, final Object object) { put(key, object); - // no-save! + // no save because we are in memory! + } + + /** + * In-memory storage systems do not have a backing file, so there is nothing to close + */ + public + void close() { + StorageSystem.close(this); } } diff --git a/src/dorkbox/util/storage/Storage.java b/src/dorkbox/util/storage/Storage.java index c0e8e7b..329381e 100644 --- a/src/dorkbox/util/storage/Storage.java +++ b/src/dorkbox/util/storage/Storage.java @@ -177,23 +177,28 @@ interface Storage { void save(); /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then saves the storage immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ void putAndSave(String key, Object object); /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then saves the storage immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ void putAndSave(byte[] key, Object object); /** - * Save the storage to disk, immediately. + * Adds a key/value pair to the storage, then saves the storage immediately. *

- * This will save the ALL of the pending save actions to the file + * This will save ALL of the pending save actions to the file */ void putAndSave(StorageKey key, Object object); + + /** + * Closes this storage system + */ + void close(); } diff --git a/src/dorkbox/util/storage/StorageSystem.java b/src/dorkbox/util/storage/StorageSystem.java index 296b35b..79cb0a2 100644 --- a/src/dorkbox/util/storage/StorageSystem.java +++ b/src/dorkbox/util/storage/StorageSystem.java @@ -76,7 +76,7 @@ class StorageSystem { final DiskStorage diskStorage = (DiskStorage) storage; boolean isLastOne = diskStorage.decrementReference(); if (isLastOne) { - diskStorage.close(); + diskStorage.closeFully(); storages.remove(file); } } @@ -108,7 +108,7 @@ class StorageSystem { //noinspection StatementWithEmptyBody while (!diskStorage.decrementReference()) { } - diskStorage.close(); + diskStorage.closeFully(); } } storages.clear(); @@ -125,7 +125,7 @@ class StorageSystem { synchronized (storages) { Storage remove = storages.remove(file); if (remove != null && remove instanceof DiskStorage) { - ((DiskStorage) remove).close(); + ((DiskStorage) remove).closeFully(); } //noinspection ResultOfMethodCallIgnored file.delete(); @@ -203,7 +203,7 @@ class StorageSystem { * suppress serialization errors. */ public - DiskMaker nologger() { + DiskMaker noLogger() { this.logger = NOPLogger.NOP_LOGGER; return this; }