public static void fillEnvWithSlaveStatus(ReplacerEnvironment env, SlaveStatus status) { env.add("disktotal", Bytes.formatBytes(status.getDiskSpaceCapacity())); env.add("diskfree", Bytes.formatBytes(status.getDiskSpaceAvailable())); env.add("diskused", Bytes.formatBytes(status.getDiskSpaceUsed())); try { env.add( "slavesonline", "" + GlobalContext.getGlobalContext().getSlaveManager().getAvailableSlaves().size()); } catch (NoAvailableSlaveException e) { env.add("slavesonline", "0"); } env.add( "slavestotal", "" + GlobalContext.getGlobalContext().getSlaveManager().getSlaves().size()); if (status.getDiskSpaceCapacity() == 0) { env.add("diskfreepercent", "n/a"); env.add("diskusedpercent", "n/a"); } else { env.add( "diskfreepercent", ((status.getDiskSpaceAvailable() * 100) / status.getDiskSpaceCapacity()) + "%"); env.add( "diskusedpercent", ((status.getDiskSpaceUsed() * 100) / status.getDiskSpaceCapacity()) + "%"); } env.add("xfers", "" + status.getTransfers()); env.add("xfersdn", "" + status.getTransfersSending()); env.add("xfersup", "" + status.getTransfersReceiving()); env.add("xfersdown", "" + status.getTransfersSending()); env.add("throughput", Bytes.formatBytes(status.getThroughput()) + "/s"); env.add("throughputup", Bytes.formatBytes(status.getThroughputReceiving()) + "/s"); env.add("throughputdown", Bytes.formatBytes(status.getThroughputSending()) + "/s"); }
@Override public void process( ScoreChart scorechart, User user, InetAddress peer, char direction, LinkedRemoteFileInterface dir, RemoteSlave sourceSlave) throws NoAvailableSlaveException { ArrayList<ScoreChart.SlaveScore> lowSlaves = new ArrayList<ScoreChart.SlaveScore>(); int lownum = Integer.MAX_VALUE; for (Iterator iter = scorechart.getSlaveScores().iterator(); iter.hasNext(); ) { ScoreChart.SlaveScore slavescore = (ScoreChart.SlaveScore) iter.next(); SlaveStatus status; try { status = slavescore.getRSlave().getSlaveStatusAvailable(); } catch (Exception e) { iter.remove(); continue; } int transfers = 0; if (direction == Transfer.TRANSFER_RECEIVING_UPLOAD) { transfers = status.getTransfersReceiving(); } else if (direction == Transfer.TRANSFER_SENDING_DOWNLOAD) { transfers = status.getTransfersSending(); } else { throw new IllegalArgumentException("Direction was not one of download or upload"); } if (transfers < lownum) { lownum = transfers; lowSlaves.clear(); lowSlaves.add(slavescore); } else if (transfers == lownum) { lowSlaves.add(slavescore); } else { // transfers > lownum // nothing, you stink slave! :) } } if (lowSlaves.isEmpty()) { throw new NoAvailableSlaveException("No slaves are available"); } for (ScoreChart.SlaveScore slavescore : lowSlaves) { slavescore.addScore(1); } }