Package net.sourceforge.processdash.util

Examples of net.sourceforge.processdash.util.ProfTimer


        if (loggingEnabled() && when == SHUTDOWN)
            stopLogging();

        if (Settings.getBool("backup.enabled", true)) {
            ProfTimer pt = new ProfTimer(FileBackupManager.class,
                    "FileBackupManager.run");
            try {
                runImpl(when, who, false);
            } catch (Throwable t) {}
            pt.click("Finished backup");
        }
       
        if (loggingEnabled() && when == STARTUP)
            startLogging(workingDirectory.getDirectory());
    }
View Full Code Here


            startLogging(workingDirectory.getDirectory());
    }


    public File run() {
        ProfTimer pt = new ProfTimer(FileBackupManager.class,
            "FileBackupManager.run");
        File result = null;
        try {
            result = runImpl(RUNNING, null, true);
        } catch (Throwable t) {
            printError(t);
        }
        pt.click("Finished backup");

        return result;
    }
View Full Code Here

    public ProcessDashboard(String location, String title) {
        super();
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(this);
        ProfTimer pt = new ProfTimer(ProcessDashboard.class, "ProcessDashboard");

        // adjust the working directory if necessary.
        if (location == null)
            location = maybeFollowDataDirLinkFile();
        configureWorkingDirectory(location);

        // load app defaults and user settings.
        try {
            InternalSettings.initialize("");
        } catch (Exception e) {
            logErr("Unable to read settings file", e);
            displayStartupIOError("Errors.Read_File_Error.Settings_File",
                    e.getMessage(), e);
            System.exit(0);
        }
        propertiesFile = Settings.getFile("stateFile");
        File prop_file = new File(propertiesFile);
        try {
            prop_file = prop_file.getCanonicalFile();
        } catch (IOException ioe) {}
        propertiesFile = prop_file.getPath();
        property_directory = prop_file.getParent() + Settings.sep;
        TemplateLoader.resetTemplateURLs();
        configureSystemPropertiesFromSettings();
        pt.click("Read settings");

        DefectAnalyzer.setDataDirectory(property_directory);
        CmsDefaultConfig.setPersistenceDirectories(
            getCmsPersistenceDirs(prop_file.getParentFile()));
        ExternalResourceManager.getInstance().setDashboardContext(this);
        ExternalResourceManager.getInstance().initializeMappings(
                prop_file.getParentFile());
        try {
            default_directory = prop_file.getParentFile().getCanonicalPath();
        } catch (IOException ioe) {
            default_directory = prop_file.getParentFile().getAbsolutePath();
        }
        ImportDirectoryFactory.getInstance().setBaseDirectory(
            new File(default_directory));
        pt.click("Set default directory");

               
        // configure the writability of the data and lock if applicable
        maybeSetupHistoricalMode();
        maybeEnableReadOnlyMode();
        pt.click("Checked read only mode");
        if (!Settings.isReadOnly()) {
            tryToLockDataForWriting();
            pt.click("Tried to acquire write lock");
        }

        // check for a dataset migration import request
        DatasetAutoMigrator.maybeRun(workingDirectory,
            new DatasetAutoMigrator.DialogParentSource() {
                public Component getDialogParent() { return hideSS(); }});

        // run the backup process as soon as possible
        fileBackupManager = new FileBackupManager(workingDirectory);
        fileBackupManager.maybeRun(FileBackupManager.STARTUP, null);
        pt.click("Ran file backup");

       
        // start the http server.
        try {
            int httpPort = Settings.getInt(HTTP_PORT_SETTING, DEFAULT_WEB_PORT);
            webServer = new WebServer(httpPort);
            webServer.setDashboardContext(this);
            InternalSettings.addPropertyChangeListener
                (HTTP_PORT_SETTING, new HttpPortSettingListener());
            ScriptID.setNameResolver(new ScriptNameResolver(webServer));
        } catch (IOException ioe) {
            logErr("Couldn't start web server", ioe);
        }
        pt.click("Started web server");


        // create the data repository.
        data = new DataRepository();
        if ("true".equalsIgnoreCase(Settings.getVal("dataFreezing.disabled")))
            data.disableFreezing();
        data.addGlobalDefineDeclarations("#define AUTO_INDIV_ROOT_TAG t");
        pt.click("Created Data Repository");
        templates = TemplateLoader.loadTemplates(data);
        pt.click("Loaded templates");
        DataVersionChecker.ensureVersionsOrExit();
        aum = new AutoUpdateManager(TemplateLoader.getPackages());
        resources = Resources.getDashBundle("ProcessDashboard");
        InternalSettings.loadLocaleSpecificDefaults(resources);
        FormatUtil.setDateFormats(Settings.getVal("dateFormat"),
                Settings.getVal("dateTimeFormat"));
        Translator.init();
        LookAndFeelSettings.loadLocalizedSettings();
        pt.click("Set locale specific defaults");
        data.setDatafileSearchURLs(TemplateLoader.getTemplateURLs());
        pt.click("Set datafile search URLs");
        versionNumber = TemplateLoader.getPackageVersion("pspdash"); // legacy
        logger.info("Process Dashboard version " + versionNumber);

        setupWindowTitle(title);
       
        // initialize the content roots for the http server.
        webServer.setRoots(TemplateLoader.getTemplateURLs());
        WebServer.setOutputCharset(getWebCharset());
        pt.click("Set web server roots");

        BetaVersionSetup.runSetup(property_directory);
        pt.click("Ran beta version setup");

        // determine if corrupt Data Files are present in the pspdata directory
        // and take steps to repair them.
        brokenData = new BrokenDataFileHandler();
        brokenData.findCorruptFiles(property_directory);
        pt.click("Checked for lost data files");
        if (brokenData.repairCorruptFiles(this) == false) {

            // if the lost data files could not be repaired, exit the dashboard
            logger.severe
            ("Dashboard was terminated due to user request. " +
                    "The following bad data files were found in the "+
                    "psp data directory:\n" + brokenData.getCorruptFileStr());
            System.exit(0);
        }

        // open and load the the user's work breakdown structure
        props = new DashHierarchy(property_directory);
        Vector v = null;
        Exception saxException = null;
        if (prop_file.exists()) {
            try {
                // try to load the user's existing properties file.
                try {
                    v = props.loadXML(propertiesFile, templates);
                } catch (Exception se1) {
                    if (!safeInstanceof(se1, "org.xml.sax.SAXException"))
                        throw se1;
                    saxException = se1;
                    props.load(propertiesFile);
                    LegacySupport.fixupV13ScriptIDs(props);
                    props.saveXML(propertiesFile, null);
                    props.clear();
                    v = props.loadXML(propertiesFile, templates);
                }
            } catch (Exception e) {
                // this is a serious problem, indicating a corrupt
                // state file.  Display a warning to the user, then exit.
                if (saxException != null) e = saxException;
                propertiesFile = prop_file.getAbsolutePath();
                try {
                    propertiesFile = prop_file.getCanonicalPath();
                } catch (Exception e2) {}
                DashHierarchy.displayCorruptStateFileWarning
                    (resources, propertiesFile, e);
                System.exit(0);
            }
        } else {
            try {
                // apparently, the user doesn't already have a properties
                // file.  read the default properties file, which simply
                // contains nodes for "Project" and "Non Project".
                String state = new String
                    (FileUtils.slurpContents(getClass().getResourceAsStream
                                                 (DEFAULT_PROP_FILE), true),
                     "ISO-8859-1");
                // localize the strings "Project" and "Non Project"
                state = StringUtils.findAndReplace
                    (state, "<Project>",
                     "<"+resources.getString("Project")+">");
                state = StringUtils.findAndReplace
                    (state, "<Non Project>",
                     "<"+resources.getString("Non_Project")+">");

                v = props.load(new StringReader(state), true);
               
                // Starting with version UTF8_SUPPORT_VERSION, all new datasets
                // use UTF-8 for datafiles and XML for defects.
                DataRepository.enableUtf8Encoding();
                DefectLog.enableXmlStorageFormat();

                if (Settings.isTeamMode() == false)
                    displayFirstTimeUserHelp();
            } catch (Exception e) {
                logErr("Couldn't read default state file", e);
            }
        }
        data.setNodeComparator(props);
        registerHierarchyDataElement();
        data.pinElement(DashHierarchy.DATA_REPOSITORY_NAME);
        activeTaskModel = new DefaultActiveTaskModel(props);
        pt.click("Loaded dashboard hierarchy");

        // Make certain we know whether this dashboard is operating as a
        // team dashboard or a personal dashboard.
        configureTeamOrPersonalDatasetMode();

        // create the database plugin
        if (createDatabasePlugin())
            pt.click("Created and started the database plugin");

        // create the time log
        try {
            this.timeLog = new DashboardTimeLog(new File(property_directory), data, props);
            this.timeLog.getTimeLoggingModel().setActiveTaskModel(activeTaskModel);
            DashboardTimeLog.setDefault(this.timeLog);
        } catch (IOException e1) {
            logErr("Unable to read time log", e1);
            displayStartupIOError("Errors.Read_File_Error.Time_Log",
                    property_directory + WorkingTimeLog.TIME_LOG_FILENAME, e1);
            System.exit(0);
        }
        pt.click("Initialized time log");

        // possibly reload cached data definitions.
        File serializedDefinitions = new File(property_directory, "defns.ser");
        if (serializedDefinitions.exists() &&
            (serializedDefinitions.lastModified() >
             TemplateLoader.getTemplateTimestamp()))
            try {
                data.loadDefinitions(new FileInputStream
                    (serializedDefinitions));
            } catch (Exception e) {}

        // open all the datafiles that were specified in the properties file.
        data.startInconsistency();
        try {
          if (v != null) {
            String a[];
            for (int i = 0; i < v.size(); i++) {
              a = (String[])v.elementAt (i);
              openDatafile(a[0], a[1]);
            }
          }
        }catch (Exception e) { logErr("open datafiles failed!", e); };

        // open the global data file.
        try {
            data.openDatafile("", property_directory + "global.dat");
        } catch (FileNotFoundException exc) {
            // if the user doesn't have a global data file, create one
            // for them from the default template.
          HierarchyEditor.createDataFile (property_directory + "global.dat",
                                        "dataFile.txt", null);
          openDatafile("", "global.dat");

        } catch (Exception exc) {
          logErr("when generating default datafile, caught exception", exc);
        }
        registerEnvironmentalData();
        pt.click("Opened data files");
        data.fixMisparentedData();
        pt.click("Fixed misparented data");
        timeLog.setTimingForbiddenPaths(getBrokenDataPaths());
        SizeEstimatingTemplate.migrateLegacyData(props, data);

        try {
            objectCache =
                new FileObjectCache(new File(property_directory), ".obj");
        } catch (IOException ioe) {
            // not possible?
            ioe.printStackTrace();
        }

        webServer.setData(data);
        webServer.setProps(props);
        webServer.setCache(objectCache);
        pt.click("Set web server context objects");
       
        MessageDispatcher.init(this);
        ImportManager.init(data);
        InternalSettings.addPropertyChangeListener(ImportManager.SETTING_NAME,
            EventHandler.create(PropertyChangeListener.class, this,
                "flushWorkingData"));
        pt.click("Initialized import manager");
        data.finishInconsistency();
        ExportManager.init(data, this);
        pt.click("Initialized export manager");
        try {
            data.maybeSaveDefinitions(serializedDefinitions);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RepairDefectCounts.maybeRun(this, property_directory);
        timeLog.refreshMetrics();
        pt.click("Refreshed time log metrics");

        EVTaskDependencyResolver.init(this);
        WBSTaskOrderComparator.init(this);

        configure_button = new ConfigureButton(this);
        PCSH.enableHelpKey(this, "QuickOverview");
        pt.click("Created configure button");
        pause_button = new PauseButton(timeLog.getTimeLoggingModel());
        pt.click("Created play/pause button");

        if (Settings.isPersonalMode())
            buildPersonalUI(pt);
        else
            buildTeamUI(pt);

        props.addHierarchyListener(new DashHierarchy.PrePostListener() {
                public void hierarchyWillChange(Event e) {
                    if (!Settings.isFollowMode())
                        fireApplicationEvent(
                            ApplicationEventListener.APP_EVENT_SAVE_ALL_DATA);
                }
                public void hierarchyChanged(Event e) {
                    saveHierarchy();
                    registerHierarchyDataElement();
                    if (!e.isAdjusting() && !Settings.isFollowMode())
                        timeLog.refreshMetrics();
                }});

        brokenData.showMissingDataFileWarnings();
        TemplateLoader.showTemplateErrors();
        ExternalResourceManager.getInstance().cleanupBogusExtResDirectory(
                prop_file.getParentFile());
        DashController.setDashboard(this);
        BackgroundTaskManager.initialize(this);
        SystemTrayManagement.getIcon().initialize(this);
        AlwaysOnTopManager.initialize(this);
        initializeOsHelper();
        maybeRecordRecentDataset();
        RuntimeUtils.addPropagatedSystemProperty(UsageLogger.FILE_SETTING, null);
        RuntimeUtils.autoregisterPropagatedSystemProperties();
        if (Settings.isFollowMode())
            new FollowModeManager(workingDirectory, props, prop_file,
                    templates, data, timeLog);
        fireApplicationEvent(ApplicationEventListener.APP_EVENT_STARTED);
        pt.click("Finished initializing Process Dashboard object");
    }
View Full Code Here

    public synchronized boolean syncDown() throws IOException {
        return syncDown(null);
    }

    public synchronized boolean syncDown(SyncFilter filter) throws IOException {
        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.syncDown["
                + remoteUrl + "]");
        // compare hashcodes to see if the local and remote directories have
        // identical contents
        if (hashesMatch()) {
            pt.click("checked hashes - match");
            return false;
        }
        pt.click("checked hashes - mismatch");

        // as an optimization, download any files from the server that were
        // created/modified after our most recently changed file.
        long mostRecentLocalModTime = getMostRecentLocalModTime();
        downloadFiles(makeGetRequest(DOWNLOAD_ACTION,
            ResourceFilterFactory.LAST_MOD_PARAM, mostRecentLocalModTime));

        // now make a complete comparison of local-vs-remote changes.
        ResourceCollectionDiff diff = getDiff();
        applySyncFilter(diff, filter);
        pt.click("Computed local-vs-remote diff");
        if (diff == null || diff.noDifferencesFound())
            return false;

        // if any files are present only in our local collection (but not in
        // the remote collection), delete the local files.
        for (String resourceName : diff.getOnlyInA()) {
            logger.fine("deleting local resource " + resourceName);
            localCollection.deleteResource(resourceName);
        }

        // copy down files that are only present in the remote collection, as
        // well as any files that have changed
        List filesToDownload = new ArrayList();
        filesToDownload.addAll(diff.getOnlyInB());
        filesToDownload.addAll(diff.getDiffering());
        downloadFilesNamed(filesToDownload);

        pt.click("Copied down changes");
        return true;
    }
View Full Code Here

    public synchronized boolean syncUp(SyncFilter filter) throws IOException,
            LockFailureException {
        if (userName == null)
            throw new NotLockedException();

        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.syncUp["
                + remoteUrl + "]");
        ResourceCollectionDiff diff = getDiff();
        applySyncFilter(diff, filter);
        pt.click("Computed local-vs-remote diff");
        if (diff == null || diff.noDifferencesFound()) {
            logger.finer("no changes to sync up");
            return false;
        }

        boolean madeChange = false;
        List<String> filesToDownload = new ArrayList<String>();

        // decide what to do for each file that is present only in the remote
        // collection (but not in our local collection)
        if (!diff.getOnlyInB().isEmpty()) {
            List<String> params = new ArrayList<String>();
            for (String resourceName : diff.getOnlyInB()) {
                if (isSyncDownOnly(resourceName)) {
                    filesToDownload.add(resourceName);
                } else {
                    logger.fine("deleting remote resource " + resourceName);
                    params.add(DELETE_FILE_PARAM);
                    params.add(resourceName);
                }
            }
            if (!params.isEmpty()) {
                doPostRequest(DELETE_ACTION, (Object[]) params.toArray());
                pt.click("Deleted remote resources");
                madeChange = true;
            }
        }

        // upload files that need to be created or updated in the remote
        // collection
        if (!diff.getOnlyInA().isEmpty() || !diff.getDiffering().isEmpty()) {
            List params = new ArrayList();
            for (String resourceName : diff.getOnlyInA()) {
                if (isSyncDownOnly(resourceName)) {
                    logger.fine("deleting local resource " + resourceName);
                    localCollection.deleteResource(resourceName);
                    madeChange = true;
                } else {
                    logger.fine("uploading new resource " + resourceName);
                    addFileUploadParamsWithBatching(params, resourceName);
                    madeChange = true;
                }
            }
            for (String resourceName : diff.getDiffering()) {
                if (isSyncDownOnly(resourceName)) {
                    filesToDownload.add(resourceName);
                } else {
                    logger.fine("uploading modified resource " + resourceName);
                    addFileUploadParamsWithBatching(params, resourceName);
                    madeChange = true;
                }
            }
            if (!params.isEmpty()) {
                doPostRequest(UPLOAD_ACTION, (Object[]) params.toArray());
                pt.click("Uploaded new/modified resources");
                madeChange = true;
            }
        }
       
        if (!filesToDownload.isEmpty()) {
View Full Code Here

            logger.fine("Uploaded default excluded files");
        }
    }

    public synchronized URL doBackup(String qualifier) throws IOException {
        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.doBackup["
                + remoteUrl + "]");
        try {
            doPostRequest(BACKUP_ACTION, BACKUP_QUALIFIER_PARAM, qualifier);
            pt.click("backup finished, qualifer = " + qualifier);
        } catch (LockFailureException e) {
            // shouldn't happen
            logger.log(Level.SEVERE, "Received unexpected exception", e);
            pt.click("backup failed");
        }
        StringBuffer result = new StringBuffer(remoteUrl);
        HTMLUtils.appendQuery(result, VERSION_PARAM, CLIENT_VERSION);
        HTMLUtils.appendQuery(result, ACTION_PARAM, GET_BACKUP_ACTION);
        return new URL(result.toString());
View Full Code Here

        HTMLUtils.appendQuery(result, ACTION_PARAM, GET_BACKUP_ACTION);
        return new URL(result.toString());
    }

    public synchronized void acquireLock(String userName) throws LockFailureException {
        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.acquireLock["
                + remoteUrl + "]");
        try {
            this.userName = userName;
            doLockPostRequest(ACQUIRE_LOCK_ACTION);
            pt.click("Acquired bridged lock");
        } catch (LockFailureException lfe) {
            this.userName = null;
            throw lfe;
        } catch (Exception e) {
            this.userName = null;
View Full Code Here

    public synchronized void resumeOfflineLock(String userName)
            throws LockFailureException {
        if (!StringUtils.hasValue(extraLockData))
            throw new IllegalStateException("No extra lock data has been set");

        ProfTimer pt = new ProfTimer(logger,
                "ResourceBridgeClient.resumeOfflineLock[" + remoteUrl + "]");
        try {
            this.userName = userName;
            doLockPostRequest(ASSERT_LOCK_ACTION);
            pt.click("Resumed offline bridged lock");
        } catch (LockFailureException lfe) {
            this.userName = null;
            throw lfe;
        } catch (Exception e) {
            // when operating in offline mode, it is not unusual for the server
View Full Code Here

    public synchronized void pingLock() throws LockFailureException {
        if (userName == null)
            throw new NotLockedException();

        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.pingLock["
                + remoteUrl + "]");
        try {
            doLockPostRequest(PING_LOCK_ACTION);
            pt.click("Pinged bridged lock");
        } catch (LockFailureException lfe) {
            throw lfe;
        } catch (Exception e) {
            throw new LockUncertainException(e);
        }
View Full Code Here

    private synchronized void doAssertLock(String action)
            throws LockFailureException {
        if (userName == null)
            throw new NotLockedException();

        ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient." + action
                + "[" + remoteUrl + "]");
        try {
            doLockPostRequest(action);
            pt.click("Asserted bridged lock");
        } catch (LockFailureException lfe) {
            throw lfe;
        } catch (Exception e) {
            throw new LockUncertainException(e);
        }
View Full Code Here

TOP

Related Classes of net.sourceforge.processdash.util.ProfTimer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.