KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > slaveselection > filter > MaxtransfersFilter


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 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  */
package org.drftpd.slaveselection.filter;
18
19 import java.net.InetAddress JavaDoc;
20 import java.rmi.RemoteException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import net.sf.drftpd.NoAvailableSlaveException;
25 import net.sf.drftpd.master.config.FtpConfig;
26 import net.sf.drftpd.master.usermanager.User;
27 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface;
28 import net.sf.drftpd.slave.SlaveStatus;
29 import net.sf.drftpd.slave.Transfer;
30
31 /**
32  * @author zubov
33  */

34 public class MaxtransfersFilter extends Filter {
35     private long _maxTransfers;
36
37     public MaxtransfersFilter(FilterChain ssm, int i, Properties JavaDoc p) {
38         _maxTransfers =
39             Long.parseLong(FtpConfig.getProperty(p, i + ".maxtransfers"));
40     }
41
42     public void process(
43         ScoreChart scorechart,
44         User user,
45         InetAddress JavaDoc peer,
46         char direction,
47         LinkedRemoteFileInterface dir)
48         throws NoAvailableSlaveException {
49         for (Iterator JavaDoc iter = scorechart.getSlaveScores().iterator();
50             iter.hasNext();
51             ) {
52             ScoreChart.SlaveScore slavescore =
53                 (ScoreChart.SlaveScore) iter.next();
54             SlaveStatus status;
55             try {
56                 status = slavescore.getRSlave().getStatus();
57             } catch (Exception JavaDoc e) {
58                 if (e instanceof RemoteException JavaDoc) {
59                     slavescore.getRSlave().handleRemoteException(
60                         (RemoteException JavaDoc) e);
61                 }
62                 iter.remove();
63                 continue;
64             }
65             int transfers = 0;
66             if ( direction == Transfer.TRANSFER_RECEIVING_UPLOAD)
67                     transfers = status.getTransfersReceiving();
68             else if ( direction == Transfer.TRANSFER_SENDING_DOWNLOAD)
69                     transfers = status.getTransfersSending();
70             else throw new IllegalArgumentException JavaDoc("Direction was not one of download or upload");
71             if (transfers > _maxTransfers) {
72                 iter.remove();
73             }
74         }
75     }
76 }
77
Popular Tags