*
* @client Can only be called on the client!
*/
public void runRecovery(SubMonitor monitor) {
ISarosSession session;
synchronized (this) {
// Keep a local copy, since the session might end while we're doing
// this.
session = sarosSession;
}
if (session.isHost())
throw new IllegalStateException("Can only be called on the client");
if (!lock.tryLock()) {
log.error("Restarting Checksum Error Handling"
+ " while another operation is running");
try {
// Try to cancel currently running recovery
do {
cancelRecovery.set(true);
} while (!lock.tryLock(100, TimeUnit.MILLISECONDS));
} catch (InterruptedException e) {
log.error("Not designed to be interruptable");
return;
}
}
// Lock has been acquired
try {
cancelRecovery.set(false);
final ArrayList<SPath> pathsOfHandledFiles = new ArrayList<SPath>(
pathsWithWrongChecksums);
for (SPath path : pathsOfHandledFiles) {
if (cancelRecovery.get() || monitor.isCanceled())
return;
// Save document before asking host to resend
try {
editorManager.saveLazy(path);
} catch (FileNotFoundException e) {
// Sending the checksum error message should recreate
// this file
}
}
if (cancelRecovery.get())
return;
monitor.beginTask("Consistency recovery",
pathsOfHandledFiles.size());
final IProgressMonitor remoteProgress = remoteProgressManager
.createRemoteProgress(session, session.getRemoteUsers());
recoveryID = getNextRecoveryID();
filesRemaining.set(pathsOfHandledFiles.size());
remoteProgress.beginTask("Consistency recovery for buddy "
+ session.getLocalUser().getJID().getBase(),
filesRemaining.get());
session.sendActivity(session.getHost(), new ChecksumErrorActivity(
session.getLocalUser(), pathsOfHandledFiles, recoveryID));
try {
// block until all inconsistencies are resolved
int filesRemainingBefore = filesRemaining.get();
int filesRemainingCurrently;