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) {
shown_torrents.add( dm );
try {
ps = dm.getPeerManager().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 = AzureusCoreStats.ST_ALL;
if( args.size() > 0 ){
pattern = (String)args.get(0);
if ( pattern.equals("*")){
pattern = ".*";
}
}
if ( args.size() > 1 ){
AzureusCoreStats.setEnableAverages(((String)args.get(1)).equalsIgnoreCase( "on" ));
}
java.util.Set types = new HashSet();
types.add( pattern );
Map reply = AzureusCoreStats.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.size() > 0 );
}
catch (Exception e) {
ci.out.println("> Command 'show': Subcommand '" + subCommand + "' unknown.");
return;