use of net.sourceforge.processdash.util.lock.AlreadyLockedException in project processdash by dtuma.
the class ResourceBridgeClient method checkForLockException.
/**
* Look at the headers from an HTTP response, and see if they specify a lock
* failure exception. If so, create an appropriate exception and throw it.
*
* If the response headers do <b>not</b> specify a lock failure, this
* method will do nothing and return.
*
* @param conn
* a connection to a URL
* @throws LockFailureException
* if the connection was an HTTP connection and if the
* response headers indicate a lock failure
* @throws IOException
* if an error occurred when attempting to examine the
* response headers
*/
private static void checkForLockException(URLConnection conn) throws IOException, LockFailureException {
if (conn instanceof HttpURLConnection) {
HttpURLConnection http = (HttpURLConnection) conn;
int code = http.getResponseCode();
if (code != HttpURLConnection.HTTP_CONFLICT)
return;
String exceptionClass = http.getHeaderField(LOCK_EXCEPTION_HEADER);
if (!StringUtils.hasValue(exceptionClass))
return;
if (exceptionClass.equals(AlreadyLockedException.class.getName())) {
String extraInfo = http.getHeaderField(ALREADY_LOCKED_HEADER);
throw new AlreadyLockedException(extraInfo);
}
LockFailureException lfe;
try {
Class clazz = Class.forName(exceptionClass);
lfe = (LockFailureException) clazz.newInstance();
} catch (Throwable t) {
lfe = new LockFailureException(exceptionClass + ", " + http.getResponseMessage());
}
throw lfe;
}
}
use of net.sourceforge.processdash.util.lock.AlreadyLockedException in project processdash by dtuma.
the class MoveProjectWorker method lockOldDataDirectory.
/*
* Methods to lock and unlock the old data directory
*/
private void lockOldDataDirectory() throws MoveProjectException {
File lockFile = new File(oldTeamDataDir, LOCK_FILE);
fileLock = new FileConcurrencyLock(lockFile);
try {
fileLock.acquireLock(null);
} catch (AlreadyLockedException ale) {
throw new MoveProjectException("teamDirInUse").append("lockOwner", ale.getExtraInfo());
} catch (LockFailureException e) {
throw new MoveProjectException("teamDirInUse");
}
}
use of net.sourceforge.processdash.util.lock.AlreadyLockedException 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.AlreadyLockedException in project processdash by dtuma.
the class WorkflowMappingAltererProjectDir method acquireWriteLock.
private void acquireWriteLock() throws LockFailureException {
long timeoutTimestamp = System.currentTimeMillis() + (LOCK_TIMEOUT_SECONDS * 1000);
Random r = null;
AlreadyLockedException ale = null;
while (System.currentTimeMillis() < timeoutTimestamp) {
try {
dir.acquireWriteLock(null, userName);
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) {
}
}
}
// we were unable to secure a lock within a reasonable amount of time.
throw (ale != null ? ale : new LockFailureException());
}
use of net.sourceforge.processdash.util.lock.AlreadyLockedException 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