Iterator<Entry<Object, Operation>> iterator = entries.iterator();
try {
while (true) {
Entry<Object, Operation> entry = iterator.next();
Object key = entry.getKey();
Operation op = entry.getValue();
if (op.type == Operation.NOOP) continue;
// if (logmon.isLoggable(BasicLevel.DEBUG)) {
// if (op.type == Operation.SAVE) {
// logmon.log(BasicLevel.DEBUG, "NTransaction save " + op.name);
// } else if (op.type == Operation.CREATE) {
// logmon.log(BasicLevel.DEBUG, "NTransaction create " + op.name);
// } else if (op.type == Operation.DELETE) {
// logmon.log(BasicLevel.DEBUG, "NTransaction delete " + op.name);
// } else {
// logmon.log(BasicLevel.DEBUG, "NTransaction unknown(" + op.type + ") " + op.name);
// }
// }
op.logidx = logidx;
op.logptr = current + count;
// Save the operation to the log on disk
write(op.type);
if (op.dirName != null) {
writeUTF(op.dirName);
} else {
write(emptyUTFString);
}
writeUTF(op.name);
if ((op.type == Operation.SAVE) || (op.type == Operation.CREATE)) {
writeInt(op.value.length);
write(op.value);
}
// TODO: Use SoftReference ?
op.value = null;
// Reports all committed operation in current log
Operation old = log.put(key, op);
logFile[logidx%nbLogFile].logCounter += 1;
if (old != null) {
logFile[old.logidx%nbLogFile].logCounter -= 1;
// There is 6 different cases:
//
// new |
// old | C | S | D
// ------+-----+-----+-----+
// C | C | C | NOP
// ------+-----+-----+-----+
// S | S | S | D
// ------+-----+-----+-----+
// D | S | S | D
//
if (old.type == Operation.CREATE) {
if (op.type == Operation.SAVE) {
// The object has never been created on disk, the resulting operation
// is still a creation.
op.type = Operation.CREATE;
} else if (op.type == Operation.DELETE) {
// There is no more need to memorize the deletion the object will be
// never created on disk.
op.type = Operation.NOOP;
log.remove(key);
op.free();
logFile[logidx%nbLogFile].logCounter -= 1;
}
}
old.free();
}
}
} catch (NoSuchElementException exc) {}
write(Operation.END);