DiskStorage save delay is now part of the builder.
This commit is contained in:
parent
9d177a779b
commit
fe788c82c1
@ -53,14 +53,19 @@ class DiskStorage implements Storage {
|
||||
|
||||
private final AtomicInteger references = new AtomicInteger(1);
|
||||
private final AtomicBoolean isOpen = new AtomicBoolean(false);
|
||||
private volatile long milliSeconds = 3000L;
|
||||
private final long milliSeconds;
|
||||
|
||||
|
||||
/**
|
||||
* Creates or opens a new database file.
|
||||
*/
|
||||
DiskStorage(File storageFile, SerializationManager serializationManager, final boolean readOnly, final Logger logger) throws IOException {
|
||||
DiskStorage(File storageFile,
|
||||
SerializationManager serializationManager,
|
||||
final boolean readOnly,
|
||||
final long saveDelayInMilliseconds,
|
||||
final Logger logger) throws IOException {
|
||||
this.storage = new StorageBase(storageFile, serializationManager, logger);
|
||||
this.milliSeconds = saveDelayInMilliseconds;
|
||||
|
||||
if (readOnly) {
|
||||
this.timer = null;
|
||||
@ -328,19 +333,6 @@ class DiskStorage implements Storage {
|
||||
return this.milliSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param milliSeconds milliseconds to wait
|
||||
*/
|
||||
@Override
|
||||
public final
|
||||
void setSaveDelay(long milliSeconds) {
|
||||
if (!this.isOpen.get()) {
|
||||
throw new RuntimeException("Unable to act on closed storage");
|
||||
}
|
||||
|
||||
this.milliSeconds = milliSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the version of data stored in the database
|
||||
*/
|
||||
|
@ -158,19 +158,10 @@ class MemoryStorage implements Storage {
|
||||
@Override
|
||||
public
|
||||
long getSaveDelay() {
|
||||
return 0;
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -83,11 +83,6 @@ interface Storage {
|
||||
*/
|
||||
long getSaveDelay();
|
||||
|
||||
/**
|
||||
* @param milliSeconds milliseconds to wait
|
||||
*/
|
||||
void setSaveDelay(long milliSeconds);
|
||||
|
||||
/**
|
||||
* @return the version of data stored in the database
|
||||
*/
|
||||
|
@ -154,6 +154,7 @@ class StorageSystem {
|
||||
private SerializationManager serializationManager;
|
||||
private boolean readOnly = false;
|
||||
private Logger logger = null;
|
||||
private long saveDelayInMilliseconds = 3000L; // default
|
||||
|
||||
/**
|
||||
* Specify the file to write to on disk when saving objects
|
||||
@ -191,6 +192,15 @@ class StorageSystem {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this storage system as read only
|
||||
*/
|
||||
public
|
||||
DiskMaker setSaveDelay(long saveDelayInMilliseconds) {
|
||||
this.saveDelayInMilliseconds = saveDelayInMilliseconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a logger to use for the storage system. If null, then only errors will be logged to the error console.
|
||||
*/
|
||||
@ -243,7 +253,7 @@ class StorageSystem {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
storage = new DiskStorage(this.file, this.serializationManager, this.readOnly, this.logger);
|
||||
storage = new DiskStorage(this.file, this.serializationManager, this.readOnly, this.saveDelayInMilliseconds, this.logger);
|
||||
storages.put(this.file, storage);
|
||||
} catch (IOException e) {
|
||||
String message = e.getMessage().substring(0,e.getMessage().indexOf(OS.LINE_SEPARATOR));
|
||||
|
Loading…
Reference in New Issue
Block a user