Search in sources :

Example 1 with IMainStatusBar

use of com.biglybt.ui.swt.mainwindow.IMainStatusBar in project BiglyBT by BiglySoftware.

the class UpdateWindow method finishUpdate.

private void finishUpdate(boolean restartNow, boolean just_close) {
    // When completing, remove the link in mainWindow :
    UIFunctionsSWT functionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (functionsSWT != null) {
        IMainStatusBar mainStatusBar = functionsSWT.getMainStatusBar();
        if (mainStatusBar != null) {
            mainStatusBar.setUpdateNeeded(null);
        }
    }
    boolean bDisposeUpdateWindow = true;
    if (!just_close) {
        // If restart is required, then restart
        if (restartRequired && restartNow) {
            // this HAS to be done this way around else the restart inherits
            // the instance port listen. However, this is a general problem....
            UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
            if (uiFunctions != null && uiFunctions.dispose(true, false)) {
                bDisposeUpdateWindow = false;
            }
        } else if (hasMandatoryUpdates && !restartRequired) {
            // run a further update check as we can immediately install non-mandatory updates now
            update_monitor.requestRecheck();
        }
    }
    if (bDisposeUpdateWindow) {
        updateWindow.dispose();
    }
}
Also used : IMainStatusBar(com.biglybt.ui.swt.mainwindow.IMainStatusBar) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT)

Example 2 with IMainStatusBar

use of com.biglybt.ui.swt.mainwindow.IMainStatusBar in project BiglyBT by BiglySoftware.

the class UIUpdaterSWT method makeDebugToolTip.

private void makeDebugToolTip(Map<UIUpdatable, Long> timeMap) {
    final int IDX_AVG = 0;
    final int IDX_SIZE = 1;
    final int IDX_MAX = 2;
    final int IDX_LAST = 3;
    final int IDX_TIME = 4;
    long ttl = 0;
    for (Iterator<UIUpdatable> iter = timeMap.keySet().iterator(); iter.hasNext(); ) {
        UIUpdatable key = iter.next();
        if (!averageTimes.containsKey(key))
            averageTimes.put(key, new Long[] { 0L, 0L, 0L, 0L, System.currentTimeMillis() });
        Long[] average = averageTimes.get(key);
        long diff = timeMap.get(key).longValue();
        if (diff > 0) {
            long count = average[IDX_SIZE];
            // require storing all 20 values and averaging them each time
            if (count >= 20)
                count = 19;
            long lNewAverage = (average[IDX_AVG] * count + diff) / (count + 1);
            average[IDX_AVG] = lNewAverage;
            average[IDX_SIZE] = count + 1;
            if (diff > average[IDX_MAX])
                average[IDX_MAX] = diff;
            average[IDX_LAST] = diff;
            average[IDX_TIME] = System.currentTimeMillis();
        } else {
            average[IDX_LAST] = diff;
        }
        ttl += diff;
        averageTimes.put(key, average);
    }
    // System.out.println(SystemTime.getCurrentTime() + "] Refresh " + ttl + "ms");
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    IMainStatusBar mainStatusBar = uiFunctionsSWT == null ? null : uiFunctionsSWT.getMainStatusBar();
    if (mainStatusBar != null && mainStatusBar.isMouseOver()) {
        StringBuilder sb = new StringBuilder();
        for (Iterator iter = averageTimes.keySet().iterator(); iter.hasNext(); ) {
            Object key = iter.next();
            Object[] average = (Object[]) averageTimes.get(key);
            long lLastUpdated = ((Long) average[IDX_TIME]).longValue();
            if (System.currentTimeMillis() - lLastUpdated > 10000) {
                iter.remove();
                continue;
            }
            long lTime = ((Long) average[IDX_AVG]).longValue();
            if (lTime > 0) {
                if (sb.length() > 0)
                    sb.append("\n");
                sb.append(lTime * 100 / waitTimeMS);
                sb.append("% ");
                sb.append(lTime).append("ms avg: ");
                sb.append("[").append(((UIUpdatable) key).getUpdateUIName()).append("]");
                sb.append(average[IDX_SIZE]).append(" samples");
                sb.append("; max:").append(average[IDX_MAX]);
                sb.append("; last:").append(average[IDX_LAST]);
            }
        }
        mainStatusBar.setDebugInfo(sb.toString());
    }
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) IMainStatusBar(com.biglybt.ui.swt.mainwindow.IMainStatusBar) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT)

Aggregations

UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 IMainStatusBar (com.biglybt.ui.swt.mainwindow.IMainStatusBar)2 UIUpdatable (com.biglybt.ui.common.updater.UIUpdatable)1