Search in sources :

Example 6 with GlobalManagerStats

use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.

the class SelectableSpeedMenu method invokeSlider.

/**
 * @param cClickedFrom
 * @since 3.0.1.7
 */
public static void invokeSlider(Control cClickedFrom, Core core, boolean isUpSpeed) {
    final String prefix = MessageText.getString(isUpSpeed ? "GeneralView.label.maxuploadspeed" : "GeneralView.label.maxdownloadspeed");
    GlobalManager gm = core.getGlobalManager();
    final String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(gm);
    boolean auto = COConfigurationManager.getBooleanParameter(configAutoKey);
    final String configKey = isUpSpeed ? TransferSpeedValidator.getActiveUploadParameter(gm) : "Max Download Speed KBs";
    int maxBandwidth = COConfigurationManager.getIntParameter(configKey);
    final boolean unlim = (maxBandwidth == 0);
    if (unlim && !isUpSpeed) {
        GlobalManagerStats stats = gm.getStats();
        int dataReceive = stats.getDataReceiveRate();
        if (dataReceive >= 1024) {
            maxBandwidth = dataReceive / 1024;
        }
    }
    SpeedScaleShell speedScale = new SpeedScaleShell() {

        @Override
        public String getStringValue(int value, String sValue) {
            if (sValue != null) {
                return prefix + ": " + sValue;
            }
            if (value == 0) {
                return MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited");
            }
            if (value == -1) {
                return MessageText.getString("ConfigView.auto");
            }
            return prefix + ": " + DisplayFormatters.formatByteCountToKiBEtcPerSec(getValue() * 1024, true);
        }
    };
    int max = unlim ? (isUpSpeed ? 100 : 800) : maxBandwidth * 5;
    if (max < 50) {
        max = 50;
    }
    speedScale.setMaxValue(max);
    speedScale.setMaxTextValue(9999999);
    final String config_prefix = "config.ui.speed.partitions.manual." + (isUpSpeed ? "upload" : "download") + ".";
    int lastValue = COConfigurationManager.getIntParameter(config_prefix + "last", -10);
    Integer[] speed_limits;
    if (COConfigurationManager.getBooleanParameter(config_prefix + "enabled", false)) {
        speed_limits = parseSpeedPartitionString(COConfigurationManager.getStringParameter(config_prefix + "values", ""));
    } else {
        speed_limits = getGenericSpeedList(6, maxBandwidth);
    }
    if (speed_limits != null) {
        for (int i = 0; i < speed_limits.length; i++) {
            int value = speed_limits[i].intValue();
            if (value > 0) {
                speedScale.addOption(DisplayFormatters.formatByteCountToKiBEtcPerSec(value * 1024, true), value);
                if (value == lastValue) {
                    lastValue = -10;
                }
            }
        }
    }
    speedScale.addOption(MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited"), 0);
    speedScale.addOption(MessageText.getString("ConfigView.auto"), -1);
    if (lastValue > 0) {
        speedScale.addOption(DisplayFormatters.formatByteCountToKiBEtcPerSec(lastValue * 1024, true), lastValue);
    }
    if (speedScale.open(cClickedFrom, auto ? -1 : maxBandwidth, true)) {
        int value = speedScale.getValue();
        if (!speedScale.wasMenuChosen() || lastValue == value) {
            COConfigurationManager.setParameter(config_prefix + "last", maxBandwidth);
        }
        if (value >= 0) {
            if (auto) {
                COConfigurationManager.setParameter(configAutoKey, false);
            }
            COConfigurationManager.setParameter(configKey, value);
            COConfigurationManager.save();
        } else {
            // autospeed
            COConfigurationManager.setParameter(configAutoKey, true);
            COConfigurationManager.save();
        }
    }
}
Also used : SpeedScaleShell(com.biglybt.ui.swt.shells.SpeedScaleShell) GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats)

Example 7 with GlobalManagerStats

use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.

the class SelectableSpeedMenu method adjustMaxBandWidth.

/**
 * @param configKey
 * @return
 *
 * @since 3.0.1.7
 */
private static int adjustMaxBandWidth(int maxBandwidth, GlobalManager globalManager, boolean up_menu, int kInB) {
    if (maxBandwidth == 0 && !up_menu) {
        GlobalManagerStats stats = globalManager.getStats();
        int dataReceive = stats.getDataReceiveRate();
        if (dataReceive < kInB) {
            maxBandwidth = 275;
        } else {
            maxBandwidth = dataReceive / kInB;
        }
    }
    return maxBandwidth;
}
Also used : GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats)

Example 8 with GlobalManagerStats

use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.

the class AllTransfersBar method refresh0.

@Override
protected void refresh0() {
    GlobalManagerStats stats = g_manager.getStats();
    this.updateSpeedLabel(down_speed, stats.getDataReceiveRate(), stats.getProtocolReceiveRate());
    this.updateSpeedLabel(up_speed, stats.getDataSendRate(), stats.getProtocolSendRate());
    long min_eta = Long.MAX_VALUE;
    int num_downloading = 0;
    List<DownloadManager> dms = g_manager.getDownloadManagers();
    for (DownloadManager dm : dms) {
        if (dm.getState() == DownloadManager.STATE_DOWNLOADING) {
            num_downloading++;
            long eta = dm.getStats().getSmoothedETA();
            if (eta < min_eta) {
                min_eta = eta;
            }
        }
    }
    if (min_eta == Long.MAX_VALUE) {
        min_eta = Constants.CRAPPY_INFINITE_AS_LONG;
    }
    next_eta.setText(num_downloading == 0 ? "" : DisplayFormatters.formatETA(min_eta));
}
Also used : GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point)

Example 9 with GlobalManagerStats

use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.

the class ViewQuickConfig method addTemporaryData.

private void addTemporaryData(Composite composite) {
    Group temp_rates = new Group(composite, SWT.NULL);
    Messages.setLanguageText(temp_rates, "label.temporary.data");
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    Utils.setLayoutData(temp_rates, gridData);
    GridLayout layout = new GridLayout(10, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    temp_rates.setLayout(layout);
    // label = new Label(temp_rates, SWT.NULL);
    // Messages.setLanguageText( label, "label.temporary.rates" );
    Label label = new Label(temp_rates, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalIndent = 4;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "label.upload.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
    final IntParameter tempULLimit = new IntParameter(temp_rates, "global.upload.limit.temp.mb", 0, Integer.MAX_VALUE);
    label = new Label(temp_rates, SWT.NULL);
    Messages.setLanguageText(label, "label.download.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
    final IntParameter tempDLLimit = new IntParameter(temp_rates, "global.download.limit.temp.mb", 0, Integer.MAX_VALUE);
    final Button activate = new Button(temp_rates, SWT.TOGGLE);
    Messages.setLanguageText(activate, "label.activate");
    final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    Utils.setLayoutData(remLabel, gridData);
    activate.addSelectionListener(new SelectionAdapter() {

        private CoreLifecycleAdapter listener;

        private TimerEventPeriodic event;

        private long end_upload;

        private long end_download;

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (activate.getSelection()) {
                listener = new CoreLifecycleAdapter() {

                    @Override
                    public void stopping(Core core) {
                        deactivate(true);
                    }
                };
                Core core = CoreFactory.getSingleton();
                core.addLifecycleListener(listener);
                Messages.setLanguageText(activate, "FileView.BlockView.Active");
                final GlobalManagerStats stats = core.getGlobalManager().getStats();
                tempULLimit.setEnabled(false);
                tempDLLimit.setEnabled(false);
                long u_limit = tempULLimit.getValue();
                if (u_limit > 0) {
                    end_upload = stats.getTotalDataProtocolBytesSent() + u_limit * DisplayFormatters.getMinB();
                } else {
                    end_upload = 0;
                }
                long d_limit = tempDLLimit.getValue();
                if (d_limit > 0) {
                    end_download = stats.getTotalDataProtocolBytesReceived() + d_limit * DisplayFormatters.getMinB();
                } else {
                    end_download = 0;
                }
                event = SimpleTimer.addPeriodicEvent("TempData", 5000, new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent e) {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                if (event == null) {
                                    return;
                                }
                                long rem_up = 0;
                                long rem_down = 0;
                                if (end_upload > 0) {
                                    rem_up = end_upload - stats.getTotalDataProtocolBytesSent();
                                }
                                if (end_download > 0) {
                                    rem_down = end_download - stats.getTotalDataProtocolBytesReceived();
                                }
                                if (end_upload > 0 && rem_up <= 0) {
                                    java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
                                    for (DownloadManager dm : dms) {
                                        if (!dm.isForceStart()) {
                                            int state = dm.getState();
                                            if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
                                                ManagerUtils.stop(dm, null);
                                                dm.setStopReason(MessageText.getString("label.temporary.data"));
                                            }
                                        }
                                    }
                                }
                                if (end_download > 0 && rem_down <= 0) {
                                    java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
                                    for (DownloadManager dm : dms) {
                                        if (!dm.isForceStart()) {
                                            int state = dm.getState();
                                            if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
                                                if (!dm.isDownloadComplete(false)) {
                                                    ManagerUtils.stop(dm, null);
                                                    dm.setStopReason(MessageText.getString("label.temporary.data"));
                                                }
                                            }
                                        }
                                    }
                                }
                                if ((rem_up <= 0 && rem_down <= 0) || composite.isDisposed()) {
                                    deactivate(false);
                                } else {
                                    remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatByteCountToKiBEtc(rem_up < 0 ? 0 : rem_up) + "/" + DisplayFormatters.formatByteCountToKiBEtc(rem_down < 0 ? 0 : rem_down));
                                    temp_rates.layout(new Control[] { remLabel.getControl() });
                                }
                            }
                        });
                    }
                });
            } else {
                deactivate(false);
            }
        }

        private void deactivate(boolean closing) {
            if (!closing) {
                if (listener != null) {
                    CoreFactory.getSingleton().removeLifecycleListener(listener);
                    listener = null;
                }
                if (!composite.isDisposed()) {
                    Messages.setLanguageText(activate, "label.activate");
                    activate.setSelection(false);
                    tempULLimit.setEnabled(true);
                    tempDLLimit.setEnabled(true);
                    remLabel.setText("");
                    temp_rates.layout(true);
                }
            }
            if (event != null) {
                event.cancel();
                event = null;
            }
        }
    });
    activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
    ParameterChangeAdapter adapter = new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
        }
    };
    tempULLimit.addChangeListener(adapter);
    tempDLLimit.addChangeListener(adapter);
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) TimerEvent(com.biglybt.core.util.TimerEvent) Core(com.biglybt.core.Core) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Example 10 with GlobalManagerStats

use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.

the class StatsWriterImpl method writeSupport.

protected void writeSupport() {
    writeLineRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    boolean export_peer_stats = COConfigurationManager.getBooleanParameter("Stats Export Peer Details");
    boolean export_file_stats = COConfigurationManager.getBooleanParameter("Stats Export File Details");
    String xsl = COConfigurationManager.getStringParameter("Stats XSL File");
    if (xsl.length() > 0) {
        writeLineRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + xsl + "\"?>");
    }
    writeLineRaw("<STATS>");
    GlobalManager global = core.getGlobalManager();
    try {
        indent();
        writeTag("AZUREUS_VERSION", Constants.AZUREUS_VERSION);
        writeLineRaw("<GLOBAL>");
        try {
            indent();
            GlobalManagerStats gm_stats = global.getStats();
            writeRawCookedAverageTag("DOWNLOAD_SPEED", gm_stats.getDataReceiveRate() + gm_stats.getProtocolReceiveRate());
            writeRawCookedAverageTag("UPLOAD_SPEED", gm_stats.getDataSendRate() + gm_stats.getProtocolSendRate());
        } finally {
            exdent();
        }
        writeLineRaw("</GLOBAL>");
        writeLineRaw("<DOWNLOADS>");
        try {
            indent();
            List _dms = global.getDownloadManagers();
            DownloadManager[] dms = new DownloadManager[_dms.size()];
            // sort by position, downloads then seeders
            _dms.toArray(dms);
            Arrays.sort(dms, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    DownloadManager d1 = (DownloadManager) o1;
                    DownloadManager d2 = (DownloadManager) o2;
                    int d1_index = d1.getPosition();
                    int d2_index = d2.getPosition();
                    if (d1.isDownloadComplete(false)) {
                        d1_index += 1000000;
                    }
                    if (d2.isDownloadComplete(false)) {
                        d2_index += 1000000;
                    }
                    return (d1_index - d2_index);
                }
            });
            for (int i = 0; i < dms.length; i++) {
                DownloadManager dm = (DownloadManager) dms[i];
                DownloadManagerStats dm_stats = dm.getStats();
                writeLineRaw("<DOWNLOAD>");
                try {
                    indent();
                    writeLineRaw("<TORRENT>");
                    // torrent can be null if broken torrent!
                    TOTorrent torrent = dm.getTorrent();
                    try {
                        indent();
                        writeTag("NAME", dm.getDisplayName());
                        writeTag("TORRENT_FILE", dm.getTorrentFileName());
                        if (torrent != null) {
                            writeTag("HASH", TorrentUtils.nicePrintTorrentHash(torrent, true));
                            writeRawCookedTag("SIZE", torrent.getSize());
                            writeTag("PIECE_LENGTH", torrent.getPieceLength());
                            writeTag("PIECE_COUNT", torrent.getNumberOfPieces());
                            writeTag("FILE_COUNT", torrent.getFiles().length);
                            writeTag("COMMENT", dm.getTorrentComment());
                            writeTag("CREATED_BY", dm.getTorrentCreatedBy());
                            writeTag("CREATION_DATE", torrent.getCreationDate());
                        }
                    } finally {
                        exdent();
                    }
                    writeLineRaw("</TORRENT>");
                    writeTag("DOWNLOAD_STATUS", DisplayFormatters.formatDownloadStatusDefaultLocale(dm));
                    writeTag("DOWNLOAD_DIR", dm.getSaveLocation().toString());
                    if (torrent != null) {
                        if (torrent.isSimpleTorrent()) {
                            writeTag("TARGET_FILE", dm.getSaveLocation().toString());
                        } else {
                            writeTag("TARGET_DIR", dm.getSaveLocation().toString());
                        }
                    }
                    writeTag("TRACKER_STATUS", dm.getTrackerStatus());
                    writeTag("COMPLETED", dm_stats.getCompleted());
                    writeTag("NON_DND_COMPLETED", dm.isDownloadComplete(false));
                    writeRawCookedTag("DOWNLOADED", dm_stats.getTotalDataBytesReceived());
                    writeRawCookedTag("UPLOADED", dm_stats.getTotalDataBytesSent());
                    writeRawCookedTag("DISCARDED", dm_stats.getDiscarded());
                    writeRawCookedAverageTag("DOWNLOAD_SPEED", dm_stats.getDataReceiveRate());
                    writeRawCookedAverageTag("UPLOAD_SPEED", dm_stats.getDataSendRate());
                    writeRawCookedAverageTag("TOTAL_SPEED", dm_stats.getTotalAverage());
                    writeRawCookedAverageTag("DOWNLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataReceiveRate());
                    writeRawCookedAverageTag("UPLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataSendRate());
                    writeTag("ELAPSED", dm_stats.getElapsedTime());
                    writeTag("ETA", DisplayFormatters.formatETA(dm_stats.getSmoothedETA()));
                    writeTag("HASH_FAILS", dm_stats.getHashFailCount());
                    writeTag("SHARE_RATIO", dm_stats.getShareRatio());
                    writeTag("TOTAL_SEEDS", dm.getNbSeeds());
                    writeTag("TOTAL_LEECHERS", dm.getNbPeers());
                    if (export_file_stats) {
                        try {
                            writeLineRaw("<FILES>");
                            indent();
                            DiskManagerFileInfo[] files = dm.getDiskManagerFileInfo();
                            for (int j = 0; j < files.length; j++) {
                                DiskManagerFileInfo file = files[j];
                                try {
                                    writeLineRaw("<FILE>");
                                    indent();
                                    writeTag("NAME", file.getTorrentFile().getRelativePath());
                                    writeTag("DND", file.isSkipped());
                                    writeRawCookedTag("SIZE", file.getLength());
                                    writeRawCookedTag("DOWNLOADED", file.getDownloaded());
                                } finally {
                                    exdent();
                                    writeLineRaw("</FILE>");
                                }
                            }
                        } finally {
                            exdent();
                            writeLineRaw("</FILES>");
                        }
                    }
                    if (export_peer_stats) {
                        try {
                            writeLineRaw("<PEERS>");
                            indent();
                            PEPeerManager pm = dm.getPeerManager();
                            if (pm != null) {
                                List peers = pm.getPeers();
                                for (int j = 0; j < peers.size(); j++) {
                                    PEPeer peer = (PEPeer) peers.get(j);
                                    PEPeerStats peer_stats = peer.getStats();
                                    byte[] id = peer.getId();
                                    if (id == null) {
                                        continue;
                                    }
                                    try {
                                        String peer_id = PeerClassifier.getPrintablePeerID(id);
                                        peer_id = escapeXML(peer_id);
                                        String type = escapeXML(peer.getClient());
                                        writeLineRaw("<PEER hex_id=\"" + ByteFormatter.encodeString(id) + "\" printable_id=\"" + peer_id + "\" type=\"" + type + "\">");
                                        indent();
                                        writeTag("IP", peer.getIp());
                                        writeTag("IS_SEED", peer.isSeed());
                                        writeRawCookedTag("DOWNLOADED", peer_stats.getTotalDataBytesReceived());
                                        writeRawCookedTag("UPLOADED", peer_stats.getTotalDataBytesSent());
                                        writeRawCookedAverageTag("DOWNLOAD_SPEED", peer_stats.getDataReceiveRate());
                                        writeRawCookedAverageTag("UPLOAD_SPEED", peer_stats.getDataSendRate());
                                    } catch (Throwable e) {
                                        Debug.printStackTrace(e);
                                    } finally {
                                        exdent();
                                        writeLineRaw("</PEER>");
                                    }
                                }
                            }
                        } finally {
                            exdent();
                            writeLineRaw("</PEERS>");
                        }
                    }
                } finally {
                    exdent();
                }
                writeLineRaw("</DOWNLOAD>");
            }
        } finally {
            exdent();
        }
        writeLineRaw("</DOWNLOADS>");
    } finally {
        exdent();
    }
    writeLineRaw("</STATS>");
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) PEPeer(com.biglybt.core.peer.PEPeer) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) PEPeerStats(com.biglybt.core.peer.PEPeerStats) DownloadManager(com.biglybt.core.download.DownloadManager) Comparator(java.util.Comparator) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) List(java.util.List) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Aggregations

GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)10 DownloadManager (com.biglybt.core.download.DownloadManager)6 GlobalManager (com.biglybt.core.global.GlobalManager)4 Core (com.biglybt.core.Core)2 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)2 Point (org.eclipse.swt.graphics.Point)2 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 LogAlert (com.biglybt.core.logging.LogAlert)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 PEPeerStats (com.biglybt.core.peer.PEPeerStats)1 TagDownload (com.biglybt.core.tag.TagDownload)1 TagManager (com.biglybt.core.tag.TagManager)1 TagType (com.biglybt.core.tag.TagType)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TimerEvent (com.biglybt.core.util.TimerEvent)1 TimerEventPerformer (com.biglybt.core.util.TimerEventPerformer)1 TimerEventPeriodic (com.biglybt.core.util.TimerEventPeriodic)1 UIFunctions (com.biglybt.ui.UIFunctions)1