use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.
the class SystemTraySWT method updateUI.
// @see UIUpdatable#updateUI()
@Override
public void updateUI(boolean is_visible) {
if (interval++ % 10 > 0) {
return;
}
if (trayItem.isDisposed()) {
uiFunctions.getUIUpdater().removeUpdater(this);
return;
}
if (core == null || !core.isStarted()) {
return;
}
if (enableTooltip) {
GlobalManagerStats stats = gm.getStats();
StringBuilder toolTip = new StringBuilder();
int seeding = 0;
int downloading = 0;
DownloadManager next_download = null;
long next_download_eta = Long.MAX_VALUE;
TagManager tm = TagManagerFactory.getTagManager();
if (tm != null && tm.isEnabled()) {
TagType tt = tm.getTagType(TagType.TT_DOWNLOAD_STATE);
if (tt != null) {
TagDownload dl_tag = (TagDownload) tt.getTag(1);
downloading = dl_tag.getTaggedCount();
seeding = tt.getTag(2).getTaggedCount();
if (enableTooltipNextETA && downloading > 0) {
for (DownloadManager dl : dl_tag.getTaggedDownloads()) {
DownloadManagerStats dl_stats = dl.getStats();
long eta = dl_stats.getSmoothedETA();
if (eta < next_download_eta) {
next_download_eta = eta;
next_download = dl;
}
}
}
}
} else {
// OMG this must be slow on 10k lists
/*
List<?> managers = gm.getDownloadManagers();
for (int i = 0; i < managers.size(); i++) {
DownloadManager manager = (DownloadManager) managers.get(i);
int state = manager.getState();
if (state == DownloadManager.STATE_DOWNLOADING)
downloading++;
if (state == DownloadManager.STATE_SEEDING)
seeding++;
}
*/
}
String seeding_text = seedingKeyVal.replaceAll("%1", "" + seeding);
String downloading_text = downloadingKeyVal.replaceAll("%1", "" + downloading);
toolTip.append(seeding_text).append(downloading_text).append("\n");
if (next_download != null) {
String dl_name = next_download.getDisplayName();
if (dl_name.length() > 80) {
dl_name = dl_name.substring(0, 77) + "...";
}
dl_name = dl_name.replaceAll("&", "&&");
toolTip.append(" ");
toolTip.append(dl_name);
toolTip.append(": ");
toolTip.append(etaKeyVal);
toolTip.append("=");
toolTip.append(DisplayFormatters.formatETA(next_download_eta));
toolTip.append("\n");
}
toolTip.append(dlAbbrKeyVal).append(" ");
toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataReceiveRate(), stats.getProtocolReceiveRate()));
toolTip.append(", ").append(ulAbbrKeyVal).append(" ");
toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataSendRate(), stats.getProtocolSendRate()));
int alerts = Alerts.getUnviewedLogAlertCount();
if (alerts > 0) {
toolTip.append("\n");
toolTip.append(alertsKeyVal.replaceAll("%1", "" + alerts));
}
trayItem.setToolTipText(toolTip.toString());
}
if (Constants.isUnix && gm != null) {
GlobalManagerStats stats = gm.getStats();
long l = (stats.getDataReceiveRate() + stats.getDataSendRate()) / 1024;
if (l != lastUnixVal) {
lastUnixVal = l;
trayItem.setMenu(menu, menuBuilder);
}
}
// Why should we refresh the image? it never changes ...
// and is a memory bottleneck for some non-obvious reasons.
// trayItem.setImage(ImageLoader.getInstance().getImage("logo16"));
trayItem.setVisible(true);
}
use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method getEffectiveUploadRateLimitBytesPerSecond.
@Override
public int getEffectiveUploadRateLimitBytesPerSecond() {
int local_max_bps = stats.getUploadRateLimitBytesPerSecond();
int rate = local_max_bps;
if (max_upload_when_busy_bps != 0) {
long now = SystemTime.getCurrentTime();
if (now < last_upload_when_busy_update || now - last_upload_when_busy_update > 5000) {
last_upload_when_busy_update = now;
// might need to impose the limit
String key = TransferSpeedValidator.getActiveUploadParameter(globalManager);
int global_limit_bps = COConfigurationManager.getIntParameter(key) * 1024;
if (global_limit_bps > 0 && max_upload_when_busy_bps < global_limit_bps) {
// we have a global limit and a valid busy limit
local_max_bps = local_max_bps == 0 ? global_limit_bps : local_max_bps;
GlobalManagerStats gm_stats = globalManager.getStats();
int actual = gm_stats.getDataSendRateNoLAN() + gm_stats.getProtocolSendRateNoLAN();
int move_by = (local_max_bps - max_upload_when_busy_bps) / 10;
if (move_by < 1024) {
move_by = 1024;
}
if (global_limit_bps - actual <= 2 * 1024) {
if (current_upload_when_busy_bps == 0) {
current_upload_when_busy_bps = local_max_bps;
}
int prev_upload_when_busy_bps = current_upload_when_busy_bps;
current_upload_when_busy_bps -= move_by;
if (current_upload_when_busy_bps < max_upload_when_busy_bps) {
current_upload_when_busy_bps = max_upload_when_busy_bps;
}
if (current_upload_when_busy_bps < prev_upload_when_busy_bps) {
last_upload_when_busy_dec_time = now;
}
} else {
if (current_upload_when_busy_bps != 0) {
if (upload_when_busy_min_secs == 0 || now < last_upload_when_busy_dec_time || now - last_upload_when_busy_dec_time >= upload_when_busy_min_secs * 1000L) {
current_upload_when_busy_bps += move_by;
if (current_upload_when_busy_bps >= local_max_bps) {
current_upload_when_busy_bps = 0;
}
}
}
}
if (current_upload_when_busy_bps > 0) {
rate = current_upload_when_busy_bps;
}
} else {
current_upload_when_busy_bps = 0;
}
} else {
if (current_upload_when_busy_bps > 0) {
rate = current_upload_when_busy_bps;
}
}
}
return (rate);
}
use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.
the class CoreImpl method checkRestartAction.
protected boolean checkRestartAction() {
if (ra_restarting) {
return (true);
}
int restart_after = COConfigurationManager.getIntParameter("Auto Restart When Idle");
if (restart_after > 0) {
List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
boolean active = false;
for (DownloadManager manager : managers) {
int state = manager.getState();
if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING) {
active = true;
break;
}
}
if (active) {
GlobalManagerStats stats = global_manager.getStats();
long totals = stats.getTotalDataBytesReceived() + stats.getTotalDataBytesSent();
long now = SystemTime.getMonotonousTime();
if (totals == ra_last_total_data) {
if (now - ra_last_data_time >= 60 * 1000 * restart_after) {
ra_restarting = true;
String message = MessageText.getString("core.restart.alert", new String[] { String.valueOf(restart_after) });
UIFunctions ui_functions = UIFunctionsManager.getUIFunctions();
if (ui_functions != null) {
ui_functions.forceNotify(UIFunctions.STATUSICON_NONE, null, message, null, new Object[0], -1);
}
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_INFORMATION, message));
new DelayedEvent("CoreRestart", 10 * 1000, new AERunnable() {
@Override
public void runSupport() {
requestRestart();
}
});
return (true);
}
} else {
ra_last_total_data = totals;
ra_last_data_time = now;
}
} else {
ra_last_total_data = -1;
}
} else {
ra_last_total_data = -1;
}
return (false);
}
use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.
the class MainStatusBar method updateUI.
@Override
public void updateUI(boolean is_visible) {
if (statusBar.isDisposed()) {
return;
}
// see if this fixes occasional issue with status bar vanishing when bringing back from taskbar/tray
boolean is_hidden = (!is_visible) || statusBar.getDisplay().getFocusControl() == null;
if (is_hidden) {
was_hidden = true;
} else {
if (was_hidden) {
statusBar.layout(true, true);
was_hidden = false;
}
}
if (!is_visible) {
return;
}
// Plugins.
Control[] plugin_elements = this.plugin_label_composite.getChildren();
for (int i = 0; i < plugin_elements.length; i++) {
if (plugin_elements[i] instanceof UpdateableCLabel) {
((UpdateableCLabel) plugin_elements[i]).checkForRefresh();
}
}
if (ipBlocked.isVisible()) {
updateIPBlocked();
}
if (srStatus.isVisible()) {
updateShareRatioStatus();
}
if (natStatus.isVisible()) {
updateNatStatus();
}
if (dhtStatus.isVisible()) {
updateDHTStatus();
}
// UL/DL Status Sections
if (CoreFactory.isCoreRunning()) {
Core core = CoreFactory.getSingleton();
GlobalManager gm = core.getGlobalManager();
GlobalManagerStats stats = gm.getStats();
int dl_limit = NetworkManager.getMaxDownloadRateBPS() / 1024;
long rec_data = stats.getDataReceiveRate();
long rec_prot = stats.getProtocolReceiveRate();
if (last_dl_limit != dl_limit || last_rec_data != rec_data || last_rec_prot != rec_prot) {
last_dl_limit = dl_limit;
last_rec_data = rec_data;
last_rec_prot = rec_prot;
statusDown.setText((dl_limit == 0 ? "" : "[" + dl_limit + "K] ") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(rec_data, rec_prot));
}
boolean auto_up = TransferSpeedValidator.isAutoSpeedActive(gm) && TransferSpeedValidator.isAutoUploadAvailable(core);
int ul_limit_norm = NetworkManager.getMaxUploadRateBPSNormal() / 1024;
String seeding_only;
if (NetworkManager.isSeedingOnlyUploadRate()) {
int ul_limit_seed = NetworkManager.getMaxUploadRateBPSSeedingOnly() / 1024;
if (ul_limit_seed == 0) {
seeding_only = "+" + Constants.INFINITY_STRING + "K";
} else {
int diff = ul_limit_seed - ul_limit_norm;
seeding_only = (diff >= 0 ? "+" : "") + diff + "K";
}
} else {
seeding_only = "";
}
int sent_data = stats.getDataSendRate();
if (imgRec != null && !imgRec.isDisposed()) {
updateGraph(statusDown, imgRec, rec_data, max_rec);
updateGraph(statusUp, imgSent, sent_data, max_sent);
}
statusUp.setText((ul_limit_norm == 0 ? "" : "[" + ul_limit_norm + "K" + seeding_only + "]") + (auto_up ? "* " : " ") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(sent_data, stats.getProtocolSendRate()));
}
}
use of com.biglybt.core.global.GlobalManagerStats in project BiglyBT by BiglySoftware.
the class MainWindowImpl method getCurrentTitleText.
private String getCurrentTitleText() {
if (core == null) {
return (null);
}
GlobalManager gm = core.getGlobalManager();
if (gm == null) {
return (null);
}
GlobalManagerStats stats = gm.getStats();
int down = stats.getDataReceiveRate() + stats.getProtocolReceiveRate();
int up = stats.getDataSendRate() + stats.getProtocolSendRate();
eta_tick_count++;
String eta_str = last_eta_str;
if (eta_str == null || last_eta < 120 || eta_tick_count % 10 == 0) {
long min_eta = Long.MAX_VALUE;
int num_downloading = 0;
List<DownloadManager> dms = gm.getDownloadManagers();
for (DownloadManager dm : dms) {
if (dm.getState() == DownloadManager.STATE_DOWNLOADING) {
num_downloading++;
long dm_eta = dm.getStats().getSmoothedETA();
if (dm_eta < min_eta) {
min_eta = dm_eta;
}
}
}
if (min_eta == Long.MAX_VALUE) {
min_eta = Constants.CRAPPY_INFINITE_AS_LONG;
}
last_eta = min_eta;
eta_str = last_eta_str = num_downloading == 0 ? "" : DisplayFormatters.formatETA(min_eta);
}
String down_str = formatRateCompact(down);
String up_str = formatRateCompact(up);
StringBuilder result = new StringBuilder(50);
result.append(MessageText.getString("ConfigView.download.abbreviated"));
result.append(" ");
result.append(down_str);
result.append(" ");
result.append(MessageText.getString("ConfigView.upload.abbreviated"));
result.append(" ");
result.append(up_str);
if (eta_str.length() > 0) {
result.append(" ");
result.append(MessageText.getString("ConfigView.eta.abbreviated"));
result.append(" ");
result.append(eta_str);
}
return (result.toString());
}
Aggregations