Search in sources :

Example 11 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException 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 12 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class WBSEditor method createAndShowEditor.

public static WBSEditor createAndShowEditor(String[] locations, boolean bottomUp, boolean indivMode, String initials, boolean showTeamList, String syncURL, boolean exitOnClose, boolean forceReadOnly, String itemHref, String owner) {
    LargeFontsHelper.maybeInitialize();
    try {
        HttpAuthenticator.maybeInitialize("WBS Editor");
    } catch (Exception e) {
    }
    TamperDeterrent.init();
    String message = (showTeamList ? "Opening Team Member List..." : "Opening Work Breakdown Structure...");
    JFrame waitFrame = null;
    if (!isDumpAndExitMode()) {
        waitFrame = createWaitFrame(message);
        waitFrame.setVisible(true);
    }
    LockMessageDispatcher dispatch;
    WorkingDirectory workingDirectory;
    File dir;
    TeamProject proj;
    if (bottomUp) {
        proj = new TeamProjectBottomUp(locations, "Team Project");
        dir = proj.getStorageDirectory();
        if (!dir.isDirectory()) {
            waitFrame.dispose();
            showCannotOpenError(locations[locations.length - 1]);
            return null;
        }
        workingDirectory = null;
        dispatch = null;
    } else // if not bottom up
    {
        String intent;
        if (showTeamList)
            intent = INTENT_TEAM_EDITOR;
        else if (StringUtils.hasValue(itemHref))
            intent = INTENT_SHOW_ITEM + itemHref;
        else
            intent = INTENT_WBS_EDITOR;
        dispatch = new LockMessageDispatcher();
        workingDirectory = configureWorkingDirectory(locations, intent, dispatch);
        if (workingDirectory == null) {
            waitFrame.dispose();
            return null;
        }
        dir = workingDirectory.getDirectory();
        proj = new TeamProject(dir, "Team Project");
        if (workingDirectory instanceof CompressedWorkingDirectory) {
            if (!((CompressedWorkingDirectory) workingDirectory).getTargetZipFile().canWrite())
                forceReadOnly = true;
        }
    }
    try {
        if (!isDumpAndExitMode()) {
            UserGroupManagerWBS.init(proj);
            WBSPermissionManager.init(workingDirectory, proj);
        }
    } catch (HttpException.Unauthorized he) {
        displayStartupPermissionError("Unauthorized");
        waitFrame.dispose();
        return null;
    }
    if (indivMode && proj.getBoolUserSetting(MEMBERS_CANNOT_EDIT_SETTING))
        forceReadOnly = true;
    if (forceReadOnly)
        proj.setReadOnly(true);
    else
        owner = getOwnerName(owner, true);
    if (!indivMode)
        initials = null;
    try {
        WBSEditor w = new WBSEditor(workingDirectory, proj, owner, initials);
        w.setExitOnClose(exitOnClose);
        w.setSyncURL(syncURL);
        w.setIndivMode(indivMode);
        if (showTeamList) {
            w.showTeamListEditorWithSaveButton();
        } else {
            w.show();
            w.showApplicableStartupMessages();
            if (itemHref != null)
                w.showHyperlinkedItem(itemHref);
        }
        HttpAuthenticator.setParentComponent(w.tabPanel);
        if (dispatch != null)
            dispatch.setEditor(w);
        waitFrame.dispose();
        return w;
    } catch (LockFailureException e) {
        workingDirectory.releaseLocks();
        if (exitOnClose)
            System.exit(0);
        waitFrame.dispose();
        return null;
    }
}
Also used : BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) LockUncertainException(net.sourceforge.processdash.util.lock.LockUncertainException) CannotCreateLockException(net.sourceforge.processdash.util.lock.CannotCreateLockException) IOException(java.io.IOException) SentLockMessageException(net.sourceforge.processdash.util.lock.SentLockMessageException) HeadlessException(java.awt.HeadlessException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) LoadTabsException(teamdash.wbs.WBSTabPanel.LoadTabsException) HttpException(net.sourceforge.processdash.util.HttpException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException) JFrame(javax.swing.JFrame) HttpException(net.sourceforge.processdash.util.HttpException) File(java.io.File)

Example 13 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException 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)

Example 14 with LockFailureException

use of net.sourceforge.processdash.util.lock.LockFailureException in project processdash by dtuma.

the class WBSEditor method configureWorkingDirectory.

private static WorkingDirectory configureWorkingDirectory(String[] locations, String intent, LockMessageHandler handler) {
    DashboardBackupFactory.setKeepBackupsNumDays(30);
    WorkingDirectory workingDirectory = WorkingDirectoryFactory.getInstance().get(WorkingDirectoryFactory.PURPOSE_WBS, locations);
    try {
        workingDirectory.acquireProcessLock(intent, handler);
    } catch (SentLockMessageException s) {
        // another WBS Editor is running, and it handled the request for us.
        maybeDumpStartupError("Process Conflict", new Object[] { //
        "Another process on this computer has already locked", "the WBS Editor for this team project." });
        return null;
    } catch (LockFailureException e) {
        e.printStackTrace();
        showLockFailureError();
        return null;
    }
    boolean workingDirIsGood = false;
    try {
        workingDirectory.prepare();
        File dir = workingDirectory.getDirectory();
        if (workingDirectory instanceof CompressedWorkingDirectory) {
            workingDirIsGood = new File(dir, WBS_FILENAME).isFile();
        } else {
            workingDirIsGood = dir.isDirectory();
        }
    } catch (HttpException.Unauthorized e) {
        displayStartupPermissionError("Unauthorized");
        return null;
    } catch (HttpException.Forbidden e) {
        displayStartupPermissionError("Forbidden");
        return null;
    } catch (IOException e) {
    // do nothing.  An exception means that "workingDirIsGood" will
    // remain false, so we will display an error message below.
    }
    if (workingDirIsGood) {
        return workingDirectory;
    } else {
        showCannotOpenError(workingDirectory);
        return null;
    }
}
Also used : SentLockMessageException(net.sourceforge.processdash.util.lock.SentLockMessageException) BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) WorkingDirectory(net.sourceforge.processdash.tool.bridge.client.WorkingDirectory) CompressedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory) HttpException(net.sourceforge.processdash.util.HttpException) IOException(java.io.IOException) File(java.io.File) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) ReadOnlyLockFailureException(net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)

Aggregations

LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)14 AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)10 IOException (java.io.IOException)8 HttpException (net.sourceforge.processdash.util.HttpException)7 ReadOnlyLockFailureException (net.sourceforge.processdash.util.lock.ReadOnlyLockFailureException)6 File (java.io.File)5 ProfTimer (net.sourceforge.processdash.util.ProfTimer)5 LockUncertainException (net.sourceforge.processdash.util.lock.LockUncertainException)5 NotLockedException (net.sourceforge.processdash.util.lock.NotLockedException)4 BridgedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory)3 SentLockMessageException (net.sourceforge.processdash.util.lock.SentLockMessageException)3 Random (java.util.Random)2 CompressedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.CompressedWorkingDirectory)2 WorkingDirectory (net.sourceforge.processdash.tool.bridge.client.WorkingDirectory)2 CannotCreateLockException (net.sourceforge.processdash.util.lock.CannotCreateLockException)2 HeadlessException (java.awt.HeadlessException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1