KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

18 package org.drftpd.slaveselection.filter;
19
20 import java.net.InetAddress JavaDoc;
21 import java.rmi.RemoteException JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Properties JavaDoc;
25
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  * @version $Id
34  */

35 public class ReversebandwidthFilter extends BandwidthFilter {
36     public ReversebandwidthFilter(FilterChain ssm, int i, Properties JavaDoc p) {
37         super(ssm, i, p);
38     }
39
40     public void process(
41         ScoreChart scorechart,
42         User user,
43         InetAddress JavaDoc source,
44         char direction,
45         LinkedRemoteFileInterface file) {
46         char oppositeDirection;
47         if (direction == Transfer.TRANSFER_RECEIVING_UPLOAD) {
48             oppositeDirection = Transfer.TRANSFER_SENDING_DOWNLOAD;
49         } else
50             oppositeDirection = Transfer.TRANSFER_RECEIVING_UPLOAD;
51
52         Collection JavaDoc slavescores = scorechart.getSlaveScores();
53         for (Iterator JavaDoc iter = slavescores.iterator(); iter.hasNext();) {
54             ScoreChart.SlaveScore score = (ScoreChart.SlaveScore) iter.next();
55             SlaveStatus status;
56             try {
57                 status = score.getRSlave().getStatus();
58             } catch (Exception JavaDoc e) {
59                 if (e instanceof RemoteException JavaDoc) {
60                     score.getRSlave().handleRemoteException(
61                         (RemoteException JavaDoc) e);
62                 }
63                 iter.remove();
64                 continue;
65             }
66             score.addScore(
67                 - (long)
68                     (status.getThroughputDirection(oppositeDirection)
69                         * _multiplier));
70         }
71     }
72
73 }
74
Popular Tags