KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > slave > SlaveStatus


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 net.sf.drftpd.slave;
19
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * @author mog
24  * @version $Id: SlaveStatus.java,v 1.11 2004/02/23 01:14:40 mog Exp $
25  */

26 public class SlaveStatus implements Serializable JavaDoc {
27     static final long serialVersionUID = -5171512270937436414L;
28     private long _bytesReceived;
29     private long _bytesSent;
30     private long _diskSpaceAvailable;
31     private long _diskSpaceCapacity;
32
33     private int _throughputReceiving;
34     private int _throughputSending;
35     private int _transfersReceiving;
36
37     private int _transfersSending;
38     public SlaveStatus() {
39         _diskSpaceAvailable = 0;
40         _diskSpaceCapacity = 0;
41
42         _throughputReceiving = 0;
43         _throughputSending = 0;
44
45         _transfersSending = 0;
46         _transfersReceiving = 0;
47     }
48     public SlaveStatus(
49         long diskFree,
50         long diskTotal,
51         long bytesSent,
52         long bytesReceived,
53         int throughputReceiving,
54         int transfersReceiving,
55         int throughputSending,
56         int transfersSending) {
57         _diskSpaceAvailable = diskFree;
58         _diskSpaceCapacity = diskTotal;
59
60         _bytesSent = bytesSent;
61         _bytesReceived = bytesReceived;
62
63         _throughputReceiving = throughputReceiving;
64         _throughputSending = throughputSending;
65
66         _transfersSending = transfersSending;
67         _transfersReceiving = transfersReceiving;
68     }
69
70     public SlaveStatus append(SlaveStatus arg) {
71         return new SlaveStatus(
72             getDiskSpaceAvailable() + arg.getDiskSpaceAvailable(),
73             getDiskSpaceCapacity() + arg.getDiskSpaceCapacity(),
74             getBytesSent() + arg.getBytesSent(),
75             getBytesReceived() + arg.getBytesReceived(),
76             getThroughputReceiving() + arg.getThroughputReceiving(),
77             getTransfersReceiving() + arg.getTransfersReceiving(),
78             getThroughputSending() + arg.getThroughputSending(),
79             getTransfersSending() + arg.getTransfersSending());
80     }
81
82     public long getBytesReceived() {
83         return _bytesReceived;
84     }
85
86     public long getBytesSent() {
87         return _bytesSent;
88     }
89
90     public long getDiskSpaceAvailable() {
91         return _diskSpaceAvailable;
92     }
93
94     public long getDiskSpaceCapacity() {
95         return _diskSpaceCapacity;
96     }
97
98     public long getDiskSpaceUsed() {
99         return getDiskSpaceCapacity() - getDiskSpaceAvailable();
100     }
101     public int getThroughput() {
102         return _throughputReceiving + _throughputSending;
103     }
104
105     public int getThroughputReceiving() {
106         return _throughputReceiving;
107     }
108
109     public int getThroughputSending() {
110         return _throughputSending;
111     }
112
113     public int getTransfers() {
114         return _transfersReceiving + _transfersSending;
115     }
116
117     public int getTransfersReceiving() {
118         return _transfersReceiving;
119     }
120
121     public int getTransfersSending() {
122         return _transfersSending;
123     }
124
125     public String JavaDoc toString() {
126         return "[SlaveStatus [diskSpaceAvailable: "
127             + _diskSpaceAvailable
128             + "][receiving: "
129             + _throughputReceiving
130             + " bps, "
131             + _transfersSending
132             + " streams][sending: "
133             + _throughputSending
134             + " bps, "
135             + _transfersReceiving
136             + " streams]]";
137     }
138
139     public int getThroughputDirection(char c) {
140         switch (c) {
141             case Transfer.TRANSFER_RECEIVING_UPLOAD :
142                 return getThroughputReceiving();
143             case Transfer.TRANSFER_SENDING_DOWNLOAD :
144                 return getThroughputSending();
145             case Transfer.TRANSFER_THROUGHPUT :
146                 return getThroughput();
147             default :
148                 throw new IllegalArgumentException JavaDoc();
149         }
150     }
151 }
152
Popular Tags