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 net.sf.drftpd.NoAvailableSlaveException;
21: import net.sf.drftpd.master.config.FtpConfig;
22:
23: import org.apache.log4j.Logger;
24:
25: import org.drftpd.Bytes;
26: import org.drftpd.PropertyHelper;
27: import org.drftpd.master.RemoteSlave;
28: import org.drftpd.remotefile.LinkedRemoteFileInterface;
29: import org.drftpd.slave.SlaveStatus;
30: import org.drftpd.usermanager.User;
31:
32: import java.net.InetAddress;
33:
34: import java.util.Iterator;
35: import java.util.Properties;
36:
37: /**
38: * @author zubov
39: * @version $Id: MaxbandwidthFilter.java 880 2004-12-29 04:24:27Z mog $
40: */
41: public class MaxbandwidthFilter extends Filter {
42: private static final Logger logger = Logger
43: .getLogger(MaxbandwidthFilter.class);
44: private long _maxBandwidth;
45:
46: public MaxbandwidthFilter(FilterChain ssm, int i, Properties p) {
47: _maxBandwidth = Bytes.parseBytes(PropertyHelper.getProperty(p,
48: i + ".maxbandwidth"));
49: }
50:
51: public void process(ScoreChart scorechart, User user,
52: InetAddress peer, char direction,
53: LinkedRemoteFileInterface dir, RemoteSlave sourceSlave)
54: throws NoAvailableSlaveException {
55: for (Iterator iter = scorechart.getSlaveScores().iterator(); iter
56: .hasNext();) {
57: ScoreChart.SlaveScore slavescore = (ScoreChart.SlaveScore) iter
58: .next();
59: SlaveStatus status;
60:
61: try {
62: status = slavescore.getRSlave()
63: .getSlaveStatusAvailable();
64: } catch (Exception e) {
65: iter.remove();
66: logger.debug("removed "
67: + slavescore.getRSlave().getName()
68: + " because of exception", e);
69:
70: continue;
71: }
72:
73: if (status.getThroughputDirection(direction) > _maxBandwidth) {
74: iter.remove();
75: }
76: }
77: }
78: }
|