All pastes #825341 Raw Edit

skalman

public text v1 · immutable
#825341 ·published 2007-12-20 14:36 UTC
rendered paste body
	public ArrayList<String> doBandwidth(String args, MessageCommand msgc) {
	    ArrayList<String> out = new ArrayList<String>();
		ReplacerEnvironment env = new ReplacerEnvironment(SiteBot.GLOBAL_ENV);
		SlaveStatus status = getGlobalContext().getSlaveManager().getAllStatus();
		SiteBot.fillEnvSlaveStatus(env, status, getGlobalContext().getSlaveManager());

		// Add a couple more variables.
		ArrayList<BaseFtpConnection> conns = new ArrayList<BaseFtpConnection>(getGlobalContext().getConnectionManager()
				.getConnections());
		int idle = conns.size() - status.getTransfersReceiving() - status.getTransfersSending();
		env.add("idle", idle);
		env.add("xfers", status.getTransfers());
		env.add("total", idle + status.getTransfers());

		long throughputReceiving = 0;
		long throughputSending = 0;
		int i = 0;
		while (true) {
			SlaveStatus tmpStatus = getGlobalContext().getSlaveManager().getAllStatus();
			long tmpThroughputReceiving = tmpStatus.getThroughputReceiving();
			long tmpThroughputSending = tmpStatus.getThroughputSending();
			if (tmpThroughputReceiving > throughputReceiving)
				throughputReceiving = tmpThroughputReceiving;
			if (tmpThroughputSending > throughputSending)
				throughputSending = tmpThroughputSending;
			if (i == 15)
				break;
			else {
				try {
					Thread.sleep(100);
				} catch (Exception ee) { }
			}
			i++;
		}
		env.add("throughputEXT", Bytes.formatBytes(throughputReceiving + throughputSending) + "/s");
		env.add("throughputmEXT", Bytes.formatBytesToMega(throughputReceiving + throughputSending));

		env.add("throughputupEXT",	Bytes.formatBytes(throughputReceiving) + "/s");
		env.add("throughputupmEXT", Bytes.formatBytesToMega(throughputReceiving));

		env.add("throughputdownEXT", Bytes.formatBytes(throughputSending) + "/s");
		env.add("throughputdownmEXT", Bytes.formatBytesToMega(throughputSending));

		out.add(ReplacerUtils.jprintf("bw", env, Bandwidth.class));
		return out;
	}