use of net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException in project processdash by dtuma.
the class ProcessDashboard method tryToLockDataForWriting.
private void tryToLockDataForWriting() {
String lockOwnerName = getOwnerName();
String otherUser = null;
try {
workingDirectory.acquireWriteLock(lockMessageHandler, lockOwnerName);
return;
} catch (ReadOnlyLockFailureException ro) {
showFilesAreReadOnlyMessage(workingDirectory.getDescription(), ro);
return;
} catch (CannotCreateLockException e) {
showCannotCreateLockMessage(workingDirectory.getDescription(), e);
return;
} catch (OfflineLockLostException e) {
showLostOfflineLockMessage(workingDirectory.getDescription(), e);
return;
} catch (AlreadyLockedException e) {
otherUser = e.getExtraInfo();
} catch (LockFailureException e) {
showCannotCreateLockMessage(workingDirectory.getDescription(), e);
return;
}
ResourceBundle r = ResourceBundle.getBundle("Templates.resources.ProcessDashboard");
if (!StringUtils.hasValue(otherUser))
otherUser = r.getString("Errors.Concurrent_Use_Someone_Else");
String title = r.getString("Errors.Concurrent_Use_Title");
String message = MessageFormat.format(r.getString("Errors.Concurrent_Use_Message2_FMT"), otherUser);
if (JOptionPane.showConfirmDialog(hideSS(), message.split("\n"), title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
InternalSettings.setReadOnly(true);
} else {
System.exit(0);
}
}
use of net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException in project processdash by dtuma.
the class WBSEditor method acquireSimultaneousEditWriteLock.
private void acquireSimultaneousEditWriteLock() throws LockFailureException {
int timeoutSeconds = Integer.getInteger("teamdash.wbs.acquireLockTimeout", 60);
long timeoutTimestamp = System.currentTimeMillis() + (timeoutSeconds * 1000);
Random r = null;
AlreadyLockedException ale = null;
while (System.currentTimeMillis() < timeoutTimestamp) {
try {
workingDirectory.acquireWriteLock(this, owner);
return;
} catch (AlreadyLockedException e) {
// if someone else is holding the lock, wait for a moment to see
// if they release it. Then try again.
ale = e;
try {
// processes are attempting to get the lock at the same time
if (r == null)
r = new Random();
Thread.sleep(500 + r.nextInt(1000));
} catch (InterruptedException e1) {
}
} catch (ReadOnlyLockFailureException e) {
showSaveErrorMessage("Errors.Read_Only_Files.Message_FMT");
throw e;
} catch (LockFailureException e) {
showSaveErrorMessage("Errors.Cannot_Create_Lock.Message_FMT");
throw e;
}
}
// we were unable to secure a lock within a reasonable amount of time.
// display an error message stating who has the file locked.
showSaveErrorMessage("Errors.Concurrent_Use.Message_FMT", getOtherLockHolder(ale));
throw (ale != null ? ale : new LockFailureException());
}
Aggregations