use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.
the class Show method execute.
@Override
public void execute(String commandName, ConsoleInput ci, List args) {
if (args.isEmpty()) {
printHelp(ci.out, args);
return;
}
String subCommand = (String) args.remove(0);
if (subCommand.equalsIgnoreCase("options") || subCommand.equalsIgnoreCase("o")) {
ci.invokeCommand("set", null);
} else if (subCommand.equalsIgnoreCase("files") || subCommand.equalsIgnoreCase("f")) {
ci.invokeCommand("add", Arrays.asList(new String[] { "--list" }));
} else if (subCommand.equalsIgnoreCase("torrents") || subCommand.equalsIgnoreCase("t")) {
ci.out.println("> -----");
ci.torrents.clear();
ci.torrents.addAll(ci.getGlobalManager().getDownloadManagers());
Collections.sort(ci.torrents, new TorrentComparator());
if (ci.torrents.isEmpty()) {
ci.out.println("No Torrents");
ci.out.println("> -----");
return;
}
long totalReceived = 0;
long totalSent = 0;
long totalDiscarded = 0;
int connectedSeeds = 0;
int connectedPeers = 0;
PEPeerManagerStats ps;
boolean bShowOnlyActive = false;
boolean bShowOnlyComplete = false;
boolean bShowOnlyIncomplete = false;
boolean bShowOnlyTransferring = false;
int bShowDeadForDays = 0;
for (ListIterator<String> iter = args.listIterator(); iter.hasNext(); ) {
String arg = (String) iter.next();
if ("active".equalsIgnoreCase(arg) || "a".equalsIgnoreCase(arg)) {
bShowOnlyActive = true;
iter.remove();
} else if ("complete".equalsIgnoreCase(arg) || "c".equalsIgnoreCase(arg)) {
bShowOnlyComplete = true;
iter.remove();
} else if ("incomplete".equalsIgnoreCase(arg) || "i".equalsIgnoreCase(arg)) {
bShowOnlyIncomplete = true;
iter.remove();
} else if ("transferring".equalsIgnoreCase(arg) || "x".equalsIgnoreCase(arg)) {
bShowOnlyTransferring = true;
bShowOnlyActive = true;
iter.remove();
} else if ("dead".equalsIgnoreCase(arg) || "d".equalsIgnoreCase(arg)) {
iter.remove();
// default 1 week
bShowDeadForDays = 7;
if (iter.hasNext()) {
String days = iter.next();
try {
bShowDeadForDays = Integer.parseInt(days);
iter.remove();
} catch (Throwable e) {
iter.previous();
}
}
}
}
Iterator torrent;
if (args.size() > 0) {
List matchedTorrents = new TorrentFilter().getTorrents(ci.torrents, args);
torrent = matchedTorrents.iterator();
} else
torrent = ci.torrents.iterator();
List shown_torrents = new ArrayList();
while (torrent.hasNext()) {
DownloadManager dm = (DownloadManager) torrent.next();
DownloadManagerStats stats = dm.getStats();
boolean bDownloadCompleted = stats.getDownloadCompleted(false) == 1000;
boolean bCanShow = ((bShowOnlyComplete == bShowOnlyIncomplete) || (bDownloadCompleted && bShowOnlyComplete) || (!bDownloadCompleted && bShowOnlyIncomplete));
if (bCanShow && bShowOnlyActive) {
int dmstate = dm.getState();
bCanShow = (dmstate == DownloadManager.STATE_SEEDING) || (dmstate == DownloadManager.STATE_DOWNLOADING) || (dmstate == DownloadManager.STATE_CHECKING) || (dmstate == DownloadManager.STATE_INITIALIZING) || (dmstate == DownloadManager.STATE_ALLOCATING);
}
if (bCanShow && bShowOnlyTransferring) {
try {
ps = dm.getPeerManager().getStats();
bCanShow = ps.getDataSendRate() > 0 || ps.getDataReceiveRate() > 0;
} catch (Exception e) {
}
}
if (bCanShow && bShowDeadForDays > 0) {
int dmstate = dm.getState();
bCanShow = false;
if (dmstate == DownloadManager.STATE_SEEDING || (bDownloadCompleted && (dmstate == DownloadManager.STATE_QUEUED || dmstate == DownloadManager.STATE_STOPPED))) {
long seeding_secs = stats.getSecondsOnlySeeding();
long seeding_days = seeding_secs / (24 * 60 * 60);
if (seeding_days >= bShowDeadForDays) {
int secs_since_last_up = stats.getTimeSinceLastDataSentInSeconds();
if (secs_since_last_up == -1) {
// never uploaded
bCanShow = true;
} else {
int days_since_last_up = secs_since_last_up / (24 * 60 * 60);
if (days_since_last_up >= bShowDeadForDays) {
bCanShow = true;
}
}
}
}
}
if (bCanShow) {
shown_torrents.add(dm);
try {
PEPeerManager pm = dm.getPeerManager();
ps = pm == null ? null : pm.getStats();
} catch (Exception e) {
ps = null;
}
if (ps != null) {
totalReceived += dm.getStats().getTotalDataBytesReceived();
totalSent += dm.getStats().getTotalDataBytesSent();
totalDiscarded += ps.getTotalDiscarded();
connectedSeeds += dm.getNbSeeds();
connectedPeers += dm.getNbPeers();
}
ci.out.print(((shown_torrents.size() < 10) ? " " : "") + shown_torrents.size() + " ");
ci.out.println(getTorrentSummary(dm));
ci.out.println();
}
}
ci.torrents.clear();
ci.torrents.addAll(shown_torrents);
GlobalManager gm = ci.getGlobalManager();
ci.out.println("Total Speed (down/up): " + DisplayFormatters.formatByteCountToKiBEtcPerSec(gm.getStats().getDataReceiveRate() + gm.getStats().getProtocolReceiveRate()) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(gm.getStats().getDataSendRate() + gm.getStats().getProtocolSendRate()));
ci.out.println("Transferred Volume (down/up/discarded): " + DisplayFormatters.formatByteCountToKiBEtc(totalReceived) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalSent) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalDiscarded));
ci.out.println("Total Connected Peers (seeds/peers): " + Integer.toString(connectedSeeds) + " / " + Integer.toString(connectedPeers));
ci.out.println("> -----");
} else if (subCommand.equalsIgnoreCase("dht") || subCommand.equalsIgnoreCase("d")) {
showDHTStats(ci);
} else if (subCommand.equalsIgnoreCase("nat") || subCommand.equalsIgnoreCase("n")) {
IndentWriter iw = new IndentWriter(new PrintWriter(ci.out));
iw.setForce(true);
NetworkAdmin.getSingleton().logNATStatus(iw);
} else if (subCommand.equalsIgnoreCase("stats") || subCommand.equalsIgnoreCase("s")) {
String pattern = CoreStats.ST_ALL;
if (args.size() > 0) {
pattern = (String) args.get(0);
if (pattern.equals("*")) {
pattern = ".*";
}
}
if (args.size() > 1) {
CoreStats.setEnableAverages(((String) args.get(1)).equalsIgnoreCase("on"));
}
java.util.Set types = new HashSet();
types.add(pattern);
Map reply = CoreStats.getStats(types);
Iterator it = reply.entrySet().iterator();
List lines = new ArrayList();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
lines.add(entry.getKey() + " -> " + entry.getValue());
}
Collections.sort(lines);
for (int i = 0; i < lines.size(); i++) {
ci.out.println(lines.get(i));
}
} else if (subCommand.equalsIgnoreCase("diag") || subCommand.equalsIgnoreCase("z")) {
try {
ci.out.println("Writing diagnostics to file 'az.diag'");
FileWriter fw = new FileWriter("az.diag");
PrintWriter pw = new PrintWriter(fw);
AEDiagnostics.generateEvidence(pw);
pw.flush();
fw.close();
} catch (Throwable e) {
ci.out.println(e);
}
} else {
if ((ci.torrents == null) || (ci.torrents != null) && ci.torrents.isEmpty()) {
ci.out.println("> Command 'show': No torrents in list (try 'show torrents' first).");
return;
}
try {
int number = Integer.parseInt(subCommand);
if ((number == 0) || (number > ci.torrents.size())) {
ci.out.println("> Command 'show': Torrent #" + number + " unknown.");
return;
}
DownloadManager dm = (DownloadManager) ci.torrents.get(number - 1);
printTorrentDetails(ci.out, dm, number, args);
} catch (Exception e) {
ci.out.println("> Command 'show': Subcommand '" + subCommand + "' unknown.");
return;
}
}
}
use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.
the class SBC_LibraryView method skinObjectInitialShow.
// @see SkinView#showSupport(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(final SWTSkinObject skinObject, Object params) {
selectedContentListener = new SelectedContentListener() {
@Override
public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewId) {
selection_count = currentContent.length;
long total_size = 0;
long total_done = 0;
ArrayList<DownloadManager> dms = new ArrayList<>(currentContent.length);
for (ISelectedContent sc : currentContent) {
DownloadManager dm = sc.getDownloadManager();
if (dm != null) {
dms.add(dm);
int file_index = sc.getFileIndex();
if (file_index == -1) {
DiskManagerFileInfo[] file_infos = dm.getDiskManagerFileInfoSet().getFiles();
for (DiskManagerFileInfo file_info : file_infos) {
if (!file_info.isSkipped()) {
total_size += file_info.getLength();
total_done += file_info.getDownloaded();
}
}
} else {
DiskManagerFileInfo file_info = dm.getDiskManagerFileInfoSet().getFiles()[file_index];
if (!file_info.isSkipped()) {
total_size += file_info.getLength();
total_done += file_info.getDownloaded();
}
}
}
}
selection_size = total_size;
selection_done = total_done;
selection_dms = dms.toArray(new DownloadManager[dms.size()]);
SB_Transfers transfers = MainMDISetup.getSb_transfers();
if (transfers != null) {
transfers.triggerCountRefreshListeners();
}
}
};
SelectedContentManager.addCurrentlySelectedContentListener(selectedContentListener);
soWait = null;
try {
soWait = getSkinObject("library-wait");
soWaitProgress = getSkinObject("library-wait-progress");
soWaitTask = (SWTSkinObjectText) getSkinObject("library-wait-task");
if (soWaitProgress != null) {
soWaitProgress.getControl().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
assert e != null;
Control c = (Control) e.widget;
Point size = c.getSize();
e.gc.setBackground(ColorCache.getColor(e.display, "#23a7df"));
int breakX = size.x * waitProgress / 100;
e.gc.fillRectangle(0, 0, breakX, size.y);
e.gc.setBackground(ColorCache.getColor(e.display, "#cccccc"));
e.gc.fillRectangle(breakX, 0, size.x - breakX, size.y);
}
});
}
soLibraryInfo = (SWTSkinObjectText) getSkinObject("library-info");
if (soLibraryInfo != null) {
MainMDISetup.getSb_transfers().addCountRefreshListener(new SB_Transfers.countRefreshListener() {
final Map<Composite, ExtraInfoProvider> extra_info_map = new HashMap<>();
{
soLibraryInfo.getControl().getParent().setData("ViewUtils:ViewTitleExtraInfo", new ViewUtils.ViewTitleExtraInfo() {
@Override
public void update(Composite reporter, int count, int active) {
ExtraInfoProvider provider = getProvider(reporter);
if (provider == null) {
return;
}
if (provider.value != count || provider.active != active) {
provider.value = count;
provider.active = active;
if (viewMode == provider.view_mode && provider.enabled) {
MainMDISetup.getSb_transfers().triggerCountRefreshListeners();
}
}
}
@Override
public void setEnabled(Composite reporter, boolean enabled) {
ExtraInfoProvider provider = getProvider(reporter);
if (provider == null) {
return;
}
if (provider.enabled != enabled) {
provider.enabled = enabled;
if (viewMode == provider.view_mode) {
MainMDISetup.getSb_transfers().triggerCountRefreshListeners();
}
}
}
private ExtraInfoProvider getProvider(Composite reporter) {
synchronized (extra_info_map) {
ExtraInfoProvider provider = extra_info_map.get(reporter);
if (provider != null) {
return (provider);
}
Composite temp = reporter;
while (temp != null) {
Integer vm = (Integer) temp.getData("SBC_LibraryView:ViewMode");
if (vm != null) {
provider = new ExtraInfoProvider(vm);
extra_info_map.put(reporter, provider);
return (provider);
}
temp = temp.getParent();
}
Debug.out("No view mode found for " + reporter);
return (null);
}
}
});
}
// @see SBC_LibraryView.countRefreshListener#countRefreshed(SBC_LibraryView.stats, SBC_LibraryView.stats)
@Override
public void countRefreshed(SB_Transfers.stats statsWithLowNoise, SB_Transfers.stats statsNoLowNoise) {
SB_Transfers.stats stats = viewMode == MODE_SMALLTABLE ? statsWithLowNoise : statsNoLowNoise;
String s;
if (torrentFilterMode == TORRENTS_ALL || (datasource instanceof Tag)) {
if (datasource instanceof Category) {
Category cat = (Category) datasource;
String id = "library.category.header";
s = MessageText.getString(id, new String[] { (cat.getType() != Category.TYPE_USER) ? MessageText.getString(cat.getName()) : cat.getName() });
} else if (datasource instanceof Tag) {
Tag tag = (Tag) datasource;
String id = "library.tag.header";
s = MessageText.getString(id, new String[] { tag.getTagName(true) });
String desc = tag.getDescription();
if (desc != null) {
s += " - " + desc;
}
} else {
String id = "library.all.header";
if (stats.numComplete + stats.numIncomplete != 1) {
id += ".p";
}
s = MessageText.getString(id, new String[] { String.valueOf(stats.numComplete + stats.numIncomplete), String.valueOf(stats.numSeeding + stats.numDownloading) });
if (stats.numQueued > 0) {
s += ", " + MessageText.getString("label.num_queued", new String[] { String.valueOf(stats.numQueued) });
}
}
} else if (torrentFilterMode == TORRENTS_INCOMPLETE) {
String id = "library.incomplete.header";
if (stats.numDownloading != 1) {
id += ".p";
}
int numWaiting = Math.max(stats.numIncomplete - stats.numDownloading, 0);
s = MessageText.getString(id, new String[] { String.valueOf(stats.numDownloading), String.valueOf(numWaiting) });
} else if (torrentFilterMode == TORRENTS_UNOPENED || torrentFilterMode == TORRENTS_COMPLETE) {
// complete filtering currently uses same display text as unopened
String id = "library.unopened.header";
if (stats.numUnOpened != 1) {
id += ".p";
}
s = MessageText.getString(id, new String[] { String.valueOf(stats.numUnOpened) });
} else {
s = "";
}
synchronized (extra_info_map) {
int filter_total = 0;
int filter_active = 0;
boolean filter_enabled = false;
for (ExtraInfoProvider provider : extra_info_map.values()) {
if (viewMode == provider.view_mode) {
if (provider.enabled) {
filter_enabled = true;
filter_total += provider.value;
filter_active += provider.active;
}
}
}
if (filter_enabled) {
String extra = MessageText.getString("filter.header.matches2", new String[] { String.valueOf(filter_total), String.valueOf(filter_active) });
s += " " + extra;
}
}
SB_Transfers transfers = MainMDISetup.getSb_transfers();
if (selection_count > 1) {
s += ", " + MessageText.getString("label.num_selected", new String[] { String.valueOf(selection_count) });
String size_str = null;
String rate_str = null;
if (selection_size > 0) {
if (selection_size == selection_done) {
size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_size);
} else {
size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_done) + "/" + DisplayFormatters.formatByteCountToKiBEtc(selection_size);
}
}
DownloadManager[] dms = selection_dms;
if (transfers.header_show_rates && dms.length > 1) {
long total_data_up = 0;
long total_prot_up = 0;
long total_data_down = 0;
long total_prot_down = 0;
for (DownloadManager dm : dms) {
DownloadManagerStats dm_stats = dm.getStats();
total_prot_up += dm_stats.getProtocolSendRate();
total_data_up += dm_stats.getDataSendRate();
total_prot_down += dm_stats.getProtocolReceiveRate();
total_data_down += dm_stats.getDataReceiveRate();
}
rate_str = MessageText.getString("ConfigView.download.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_down, total_prot_down) + " " + MessageText.getString("ConfigView.upload.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_up, total_prot_up);
}
if (size_str != null || rate_str != null) {
String temp;
if (size_str == null) {
temp = rate_str;
} else if (rate_str == null) {
temp = size_str;
} else {
temp = size_str + "; " + rate_str;
}
s += " (" + temp + ")";
}
}
if (transfers.header_show_uptime && transfers.totalStats != null) {
long up_secs = (transfers.totalStats.getSessionUpTime() / 60) * 60;
String op;
if (up_secs < 60) {
up_secs = 60;
op = "<";
} else {
op = " ";
}
String up_str = TimeFormatter.format2(up_secs, false);
if (s.equals("")) {
Debug.out("eh");
}
s += "; " + MessageText.getString("label.uptime_coarse", new String[] { op, up_str });
}
soLibraryInfo.setText(s);
}
class ExtraInfoProvider {
int view_mode;
boolean enabled;
int value;
int active;
private ExtraInfoProvider(int vm) {
view_mode = vm;
}
}
});
}
} catch (Exception ignored) {
}
// Core core = CoreFactory.getSingleton();
if (!CoreFactory.isCoreRunning()) {
if (soWait != null) {
soWait.setVisible(true);
// soWait.getControl().getParent().getParent().getParent().layout(true, true);
}
final Initializer initializer = Initializer.getLastInitializer();
if (initializer != null) {
initializer.addListener(new InitializerListener() {
@Override
public void reportPercent(final int percent) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (soWaitProgress != null && !soWaitProgress.isDisposed()) {
waitProgress = percent;
soWaitProgress.getControl().redraw();
soWaitProgress.getControl().update();
}
}
});
if (percent > 100) {
initializer.removeListener(this);
}
}
@Override
public void reportCurrentTask(String currentTask) {
if (soWaitTask != null && !soWaitTask.isDisposed()) {
soWaitTask.setText(currentTask);
}
}
});
}
}
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(final Core core) {
PluginInterface pi = PluginInitializer.getDefaultInterface();
final UIManager uim = pi.getUIManager();
uim.addUIListener(new UIManagerListener() {
@Override
public void UIDetached(UIInstance instance) {
}
@Override
public void UIAttached(UIInstance instance) {
if (instance instanceof UISWTInstance) {
uim.removeUIListener(this);
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (soWait != null) {
soWait.setVisible(false);
}
if (!skinObject.isDisposed()) {
setupView(core, skinObject);
}
}
});
}
}
});
}
});
return null;
}
Aggregations