Search in sources :

Example 1 with AlreadyLockedException

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

Example 2 with AlreadyLockedException

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

Example 3 with AlreadyLockedException

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);
    }
}
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 4 with AlreadyLockedException

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

Example 5 with AlreadyLockedException

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());
}
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)5 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)5 ReadOnlyLockFailureException (net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)3 Random (java.util.Random)2 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 ResourceBundle (java.util.ResourceBundle)1 CannotCreateLockException (net.sourceforge.processdash.util.lock.CannotCreateLockException)1 FileConcurrencyLock (net.sourceforge.processdash.util.lock.FileConcurrencyLock)1 OfflineLockLostException (net.sourceforge.processdash.util.lock.OfflineLockLostException)1