private void generateTransactionLog(ObjectOutput oo) throws Exception {
// todo this should be configurable
int maxNonProgressingLogWrites = 100;
int flushTimeout = 60000;
DistributedSync distributedSync = rpcManager.getTransport().getDistributedSync();
try {
if (trace) log.trace("Transaction log size is {0}", transactionLog.size());
for (int nonProgress = 0, size = transactionLog.size(); size > 0;) {
if (trace) log.trace("Tx Log remaining entries = " + size);
transactionLog.writeCommitLog(marshaller, oo);
int newSize = transactionLog.size();
// If size did not decrease then we did not make progress, and could be wasting
// our time. Limit this to the specified max.
if (newSize >= size && ++nonProgress >= maxNonProgressingLogWrites)
break;
size = newSize;
}
// Wait on incoming and outgoing threads to line-up in front of
// the distributed sync.
distributedSync.acquireProcessingLock(true, configuration.getStateRetrievalTimeout(), MILLISECONDS);
// Signal to sender that we need a flush to get a consistent view
// of the remaining transactions.
delimit(oo);
oo.flush();
if (trace) log.trace("Waiting for a distributed sync block");
distributedSync.blockUntilAcquired(flushTimeout, MILLISECONDS);
if (trace) log.trace("Distributed sync block received, proceeding with writing commit log");
// Write remaining transactions
transactionLog.writeCommitLog(marshaller, oo);
delimit(oo);
// Write all non-completed prepares
transactionLog.writePendingPrepares(marshaller, oo);
delimit(oo);
oo.flush();
}
finally {
distributedSync.releaseProcessingLock();
}
}