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:
22: import org.drftpd.master.RemoteSlave;
23: import org.drftpd.remotefile.LinkedRemoteFileInterface;
24: import org.drftpd.usermanager.User;
25:
26: import java.net.InetAddress;
27:
28: import java.util.ArrayList;
29: import java.util.Iterator;
30: import java.util.Properties;
31:
32: /**
33: * Checks ScoreChart for slaves with 0 bw usage and assigns 1 extra point to the one in that has been unused for the longest time.
34: *
35: * @author mog, zubov
36: * @version $Id: CycleFilter.java 847 2004-12-02 03:32:41Z mog $
37: */
38: public class CycleFilter extends Filter {
39: public CycleFilter(FilterChain fc, int i, Properties p) {
40: }
41:
42: public void process(ScoreChart scorechart, User user,
43: InetAddress peer, char direction,
44: LinkedRemoteFileInterface dir, RemoteSlave sourceSlave)
45: throws NoAvailableSlaveException {
46: ArrayList tempList = new ArrayList(scorechart.getSlaveScores());
47:
48: while (true) {
49: if (tempList.isEmpty()) {
50: return;
51: }
52:
53: ScoreChart.SlaveScore first = (ScoreChart.SlaveScore) tempList
54: .get(0);
55: ArrayList equalList = new ArrayList();
56: equalList.add(first);
57: tempList.remove(first);
58:
59: for (Iterator iter = tempList.iterator(); iter.hasNext();) {
60: ScoreChart.SlaveScore match = (ScoreChart.SlaveScore) iter
61: .next();
62:
63: if (match.compareTo(first) == 0) {
64: equalList.add(match);
65: iter.remove();
66: }
67: }
68:
69: ScoreChart.SlaveScore leastUsed = first;
70:
71: for (Iterator iter = equalList.iterator(); iter.hasNext();) {
72: ScoreChart.SlaveScore match = (ScoreChart.SlaveScore) iter
73: .next();
74:
75: if (match.getRSlave().getLastTransferForDirection(
76: direction) < leastUsed.getRSlave()
77: .getLastTransferForDirection(direction)) {
78: leastUsed = match;
79: }
80: }
81:
82: if (leastUsed != null) {
83: leastUsed.addScore(1);
84: }
85: }
86: }
87: }
|