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.BaseFtpConnection;
22:
23: import org.apache.log4j.Logger;
24: import org.drftpd.GlobalContext;
25: import org.drftpd.master.RemoteSlave;
26: import org.drftpd.remotefile.LinkedRemoteFileInterface;
27: import org.drftpd.usermanager.NoSuchUserException;
28: import org.drftpd.usermanager.User;
29:
30: import java.net.InetAddress;
31:
32: import java.util.Iterator;
33: import java.util.Properties;
34:
35: /**
36: * @author mog
37: * @version $Id: MaxTransfersPerUserFilter.java 849 2004-12-02 05:21:41Z mog $
38: */
39: public class MaxTransfersPerUserFilter extends Filter {
40:
41: private static final Logger logger = Logger
42: .getLogger(MaxTransfersPerUserFilter.class);
43:
44: private GlobalContext _gctx;
45:
46: public MaxTransfersPerUserFilter(FilterChain ssm, int i,
47: Properties p) {
48: this (ssm.getGlobalContext());
49: }
50:
51: public MaxTransfersPerUserFilter(GlobalContext gctx) {
52: _gctx = gctx;
53: }
54:
55: public void process(ScoreChart scorechart, char direction, User user)
56: throws NoAvailableSlaveException {
57:
58: for (BaseFtpConnection conn : _gctx.getConnectionManager()
59: .getConnections()) {
60:
61: if (!conn.getDataConnectionHandler().isTransfering())
62: continue;
63: try {
64: if (!conn.getUser().equals(user))
65: continue;
66: } catch (NoSuchUserException e) {
67: continue;
68: }
69:
70: for (Iterator<ScoreChart.SlaveScore> iter2 = scorechart
71: .getSlaveScores().iterator(); iter2.hasNext();) {
72: ScoreChart.SlaveScore score = iter2.next();
73:
74: if (score.getRSlave().equals(
75: conn.getDataConnectionHandler()
76: .getTranferSlave())
77: && direction == conn.getDirection()) {
78: logger.debug("Already has a transfer for slave "
79: + score.getRSlave().getName());
80: iter2.remove();
81: }
82: }
83: }
84: if (scorechart.isEmpty())
85: throw new NoAvailableSlaveException(
86: "All slaves were unavailable cause you already had open transfers to the available slaves");
87: }
88:
89: public void process(ScoreChart scorechart, User user,
90: InetAddress peer, char direction,
91: LinkedRemoteFileInterface dir, RemoteSlave sourceSlave)
92: throws NoAvailableSlaveException {
93: process(scorechart, direction, user);
94: }
95: }
|