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.SlaveUnavailableException;
21: import net.sf.drftpd.master.config.FtpConfig;
22:
23: import org.drftpd.Bytes;
24: import org.drftpd.PropertyHelper;
25: import org.drftpd.master.RemoteSlave;
26: import org.drftpd.remotefile.LinkedRemoteFileInterface;
27: import org.drftpd.usermanager.User;
28:
29: import java.net.InetAddress;
30:
31: import java.util.Iterator;
32: import java.util.Properties;
33:
34: /**
35: * Example slaveselection.conf entry:
36: * <pre>
37: * <n>.filter=minfreespace
38: * <n>.multiplier=1
39: * <n>.minfreespace=1GB
40: * </pre>
41: *
42: * Works like this:
43: * if(diskfree > minfreespace) {
44: * addScore((minfreespace - diskfree) * multiplier)
45: * }
46: * @author mog
47: * @version $Id: MinfreespaceFilter.java 847 2004-12-02 03:32:41Z mog $
48: */
49: public class MinfreespaceFilter extends Filter {
50: private long _minfreespace;
51: private float _multiplier;
52:
53: public MinfreespaceFilter(FilterChain ssm, int i, Properties p) {
54: //_multiplier = -Integer.parseInt(FtpConfig.getProperty(p, i + ".multiplier"));
55: _multiplier = BandwidthFilter.parseMultiplier(PropertyHelper
56: .getProperty(p, i + ".multiplier"));
57: _minfreespace = Bytes.parseBytes(PropertyHelper.getProperty(p,
58: i + ".minfreespace"));
59: }
60:
61: public void process(ScoreChart scorechart, User user,
62: InetAddress source, char direction,
63: LinkedRemoteFileInterface file, RemoteSlave sourceSlave) {
64: for (Iterator iter = scorechart.getSlaveScores().iterator(); iter
65: .hasNext();) {
66: ScoreChart.SlaveScore score = (ScoreChart.SlaveScore) iter
67: .next();
68: long df;
69:
70: try {
71: df = score.getRSlave().getSlaveStatusAvailable()
72: .getDiskSpaceAvailable();
73:
74: if (df < _minfreespace) {
75: if (_multiplier == 0) {
76: iter.remove();
77: } else {
78: score
79: .addScore(-(long) ((_minfreespace - df) * _multiplier));
80: }
81: }
82: } catch (SlaveUnavailableException e) {
83: iter.remove();
84: }
85: }
86: }
87: }
|