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.drftpd.PropertyHelper;
24: import org.drftpd.master.RemoteSlave;
25: import org.drftpd.master.RemoteTransfer;
26:
27: import org.drftpd.remotefile.LinkedRemoteFileInterface;
28: import org.drftpd.slave.SlaveStatus;
29: import org.drftpd.slave.Transfer;
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: */
40: public class MaxtransfersFilter extends Filter {
41: private long _maxTransfers;
42:
43: public MaxtransfersFilter(FilterChain ssm, int i, Properties p) {
44: _maxTransfers = Long.parseLong(PropertyHelper.getProperty(p, i
45: + ".maxtransfers"));
46: }
47:
48: public void process(ScoreChart scorechart, User user,
49: InetAddress peer, char direction,
50: LinkedRemoteFileInterface dir, RemoteSlave sourceSlave)
51: throws NoAvailableSlaveException {
52: for (Iterator iter = scorechart.getSlaveScores().iterator(); iter
53: .hasNext();) {
54: ScoreChart.SlaveScore slavescore = (ScoreChart.SlaveScore) iter
55: .next();
56: SlaveStatus status;
57:
58: try {
59: status = slavescore.getRSlave()
60: .getSlaveStatusAvailable();
61: } catch (Exception e) {
62: iter.remove();
63:
64: continue;
65: }
66:
67: int transfers = 0;
68:
69: if (direction == Transfer.TRANSFER_RECEIVING_UPLOAD) {
70: transfers = status.getTransfersReceiving();
71: } else if (direction == Transfer.TRANSFER_SENDING_DOWNLOAD) {
72: transfers = status.getTransfersSending();
73: } else {
74: throw new IllegalArgumentException(
75: "Direction was not one of download or upload");
76: }
77:
78: if (transfers > _maxTransfers) {
79: iter.remove();
80: }
81: }
82: }
83: }
|