/** The Sone to insert. */
private volatile Sone sone;
- /** Whether a modification has been detected. */
- private volatile boolean modified = false;
-
/** The fingerprint of the last insert. */
private volatile String lastInsertFingerprint;
* otherwise
*/
public boolean isModified() {
- return modified;
+ return !lastInsertFingerprint.equals(sone.getFingerprint());
}
//
Sone sone = this.sone;
if (core.isLocked(sone)) {
/* trigger redetection when the Sone is unlocked. */
- synchronized (sone) {
- modified = !sone.getFingerprint().equals(lastInsertedFingerprint);
- }
lastFingerprint = "";
lastModificationTime = absent();
continue;
}
- InsertInformation insertInformation = null;
+ boolean insertSoneNow = false;
synchronized (sone) {
String fingerprint = sone.getFingerprint();
if (!fingerprint.equals(lastFingerprint)) {
if (fingerprint.equals(lastInsertedFingerprint)) {
- modified = false;
lastModificationTime = absent();
logger.log(Level.FINE, String.format("Sone %s has been reverted to last insert state.", sone));
} else {
lastModificationTime = of(currentTimeMillis());
- modified = true;
logger.log(Level.FINE, String.format("Sone %s has been modified, waiting %d seconds before inserting.", sone.getName(), insertionDelay));
}
lastFingerprint = fingerprint;
}
- if (modified && lastModificationTime.isPresent() && ((currentTimeMillis() - lastModificationTime.get()) > (insertionDelay * 1000))) {
+ if (lastModificationTime.isPresent() && ((currentTimeMillis() - lastModificationTime.get()) > (insertionDelay * 1000))) {
lastInsertedFingerprint = fingerprint;
- insertInformation = new InsertInformation(sone);
+ insertSoneNow = true;
}
}
- if (insertInformation != null) {
+ if (insertSoneNow) {
+ InsertInformation insertInformation = new InsertInformation(sone);
logger.log(Level.INFO, String.format("Inserting Sone “%s”…", sone.getName()));
boolean success = false;
*/
if (success) {
synchronized (sone) {
- if (lastInsertedFingerprint.equals(sone.getFingerprint())) {
+ if (insertInformation.getFingerprint().equals(sone.getFingerprint())) {
logger.log(Level.FINE, String.format("Sone “%s” was not modified further, resetting counter…", sone));
lastModificationTime = absent();
- lastInsertFingerprint = lastInsertedFingerprint;
+ lastInsertFingerprint = insertInformation.getFingerprint();
core.touchConfiguration();
- modified = false;
}
}
}
*/
private class InsertInformation {
+ private final String fingerprint;
+
/** All properties of the Sone, copied for thread safety. */
private final Map<String, Object> soneProperties = new HashMap<String, Object>();
* The sone to insert
*/
public InsertInformation(Sone sone) {
+ this.fingerprint = sone.getFingerprint();
soneProperties.put("id", sone.getId());
soneProperties.put("name", sone.getName());
soneProperties.put("time", sone.getTime());
// ACCESSORS
//
+ private String getFingerprint() {
+ return fingerprint;
+ }
+
/**
* Returns the insert URI of the Sone.
*