use of net.sourceforge.processdash.util.lock.LockFailureException 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.LockFailureException 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.LockFailureException in project processdash by dtuma.
the class ProcessDashboard method configureWorkingDirectory.
private void configureWorkingDirectory(String location) {
workingDirectory = WorkingDirectoryFactory.getInstance().get(location, WorkingDirectoryFactory.PURPOSE_DASHBOARD);
if (JnlpRelauncher.maybeRelaunch(workingDirectory))
System.exit(0);
String locationDescr = workingDirectory.getDescription();
try {
lockMessageHandler = new LockMsgHandler();
workingDirectory.acquireProcessLock(ACTIVATE_MESSAGE, lockMessageHandler);
} catch (SentLockMessageException e) {
System.exit(0);
} catch (LockFailureException e) {
displaySharingError(locationDescr);
System.exit(1);
}
try {
workingDirectory.prepare();
} catch (HttpException.Unauthorized e) {
displayStartupPermissionError("Unauthorized");
System.exit(1);
} catch (HttpException.Forbidden e) {
displayStartupPermissionError("Forbidden");
System.exit(1);
} catch (IOException e) {
String resKey;
if (workingDirectory instanceof BridgedWorkingDirectory) {
resKey = "Errors.Read_File_Error.Data_Server";
} else {
resKey = "Errors.Read_File_Error.Data_Directory";
}
displayStartupIOError(resKey, locationDescr, e);
System.exit(1);
}
// Check to see if a legacy shortcut is being used to launch a dataset
// that is now hosted on a team server. If so, possibly configure the
// team server URL as the "default team server."
TeamServerSelector.maybeSetDefaultTeamServerUrl(workingDirectory);
File cwd = workingDirectory.getDirectory();
System.setProperty("user.dir", cwd.getAbsolutePath());
}
use of net.sourceforge.processdash.util.lock.LockFailureException 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.LockFailureException in project processdash by dtuma.
the class PermissionsManager method saveUsers.
/**
* Save in-memory user information to disk.
*/
private void saveUsers() {
try {
if (Settings.isReadOnly() || Settings.isPersonalMode())
return;
// open a file to save the users
File tmp = TempFileFactory.get().createTempFile("users", ".dat");
OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
// start an XML document
XmlSerializer xml = XMLUtils.getXmlSerializer(true);
xml.setOutput(out, "UTF-8");
xml.startDocument("UTF-8", null);
xml.startTag(null, USERS_TAG);
if (usersTimestamp != null)
xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(usersTimestamp));
// write XML for each user
for (User u : getAllUsers()) {
writeUser(xml, u);
}
// end the document and close the file
xml.endTag(null, USERS_TAG);
xml.ignorableWhitespace(System.lineSeparator());
xml.endDocument();
out.close();
// add a tamper-deterrent thumbprint to the file
TamperDeterrent.getInstance().addThumbprint(tmp, usersFile, TamperDeterrent.FileType.XML);
tmp.delete();
// from now forward, require a version of the dashboard that
// understands and enforces users, roles and permissions
DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
// flush data so the PDES can update server-side permissions
if (bridgedUrl != null)
workingDir.flushData();
this.usersDirty = false;
} catch (IOException ioe) {
logger.log(Level.WARNING, "Could not save users to " + usersFile, ioe);
} catch (LockFailureException lfe) {
logger.log(Level.WARNING, "Could not flush user data to server", lfe);
}
}
Aggregations