01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.drftpd.slaveselection.filter;
19:
20: import org.drftpd.master.RemoteSlave;
21: import org.drftpd.master.RemoteTransfer;
22:
23: import org.drftpd.remotefile.LinkedRemoteFileInterface;
24: import org.drftpd.slave.SlaveStatus;
25: import org.drftpd.slave.Transfer;
26: import org.drftpd.usermanager.User;
27:
28: import java.net.InetAddress;
29:
30: import java.util.Collection;
31: import java.util.Iterator;
32: import java.util.Properties;
33:
34: /*
35: * @author zubov
36: * @version $Id: ReversebandwidthFilter.java 879 2004-12-29 03:39:22Z mog $
37: */
38: public class ReversebandwidthFilter extends BandwidthFilter {
39: public ReversebandwidthFilter(FilterChain ssm, int i, Properties p) {
40: super (ssm, i, p);
41: }
42:
43: public void process(ScoreChart scorechart, User user,
44: InetAddress source, char direction,
45: LinkedRemoteFileInterface file, RemoteSlave sourceSlave) {
46: char oppositeDirection;
47:
48: if (direction == Transfer.TRANSFER_RECEIVING_UPLOAD) {
49: oppositeDirection = Transfer.TRANSFER_SENDING_DOWNLOAD;
50: } else {
51: oppositeDirection = Transfer.TRANSFER_RECEIVING_UPLOAD;
52: }
53:
54: Collection slavescores = scorechart.getSlaveScores();
55:
56: for (Iterator iter = slavescores.iterator(); iter.hasNext();) {
57: ScoreChart.SlaveScore score = (ScoreChart.SlaveScore) iter
58: .next();
59: SlaveStatus status;
60:
61: try {
62: status = score.getRSlave().getSlaveStatusAvailable();
63: } catch (Exception e) {
64: iter.remove();
65:
66: continue;
67: }
68:
69: score
70: .addScore(-(long) (status
71: .getThroughputDirection(oppositeDirection) * _multiplier));
72: }
73: }
74: }
|