Search in sources :

Example 1 with ReadOnlyLockFailureException

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);
    }
}
Also used : OfflineLockLostException(net.sourceforge.processdash.util.lock.OfflineLockLostException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) CannotCreateLockException(net.sourceforge.processdash.util.lock.CannotCreateLockException) ResourceBundle(java.util.ResourceBundle) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Example 2 with ReadOnlyLockFailureException

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());
}
Also used : AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) Random(java.util.Random) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Aggregations

AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)2 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)2 ReadOnlyLockFailureException (net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)2 Random (java.util.Random)1 ResourceBundle (java.util.ResourceBundle)1 CannotCreateLockException (net.sourceforge.processdash.util.lock.CannotCreateLockException)1 OfflineLockLostException (net.sourceforge.processdash.util.lock.OfflineLockLostException)1