001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.slave;
019:
020: /**
021: * @author mog
022: * @version $Id: SlaveStatus.java 786 2004-11-11 13:31:40Z mog $
023: */
024: public class SlaveStatus {
025: private long _bytesReceived;
026: private long _bytesSent;
027: private DiskStatus _diskStatus;
028: private int _throughputReceiving;
029: private int _throughputSending;
030: private int _transfersReceiving;
031: private int _transfersSending;
032:
033: public SlaveStatus() {
034: _diskStatus = new DiskStatus(0, 0);
035: _throughputReceiving = 0;
036: _throughputSending = 0;
037:
038: _transfersSending = 0;
039: _transfersReceiving = 0;
040: _bytesReceived = 0;
041: _bytesSent = 0;
042: }
043:
044: public SlaveStatus(DiskStatus diskStatus, long bytesSent,
045: long bytesReceived, int throughputReceiving,
046: int transfersReceiving, int throughputSending,
047: int transfersSending) {
048: _diskStatus = diskStatus;
049: _bytesSent = bytesSent;
050: _bytesReceived = bytesReceived;
051: _throughputReceiving = throughputReceiving;
052: _throughputSending = throughputSending;
053:
054: _transfersSending = transfersSending;
055: _transfersReceiving = transfersReceiving;
056: }
057:
058: public SlaveStatus append(SlaveStatus arg) {
059: return new SlaveStatus(new DiskStatus(getDiskSpaceAvailable()
060: + arg.getDiskSpaceAvailable(), getDiskSpaceCapacity()
061: + arg.getDiskSpaceCapacity()), getBytesSent()
062: + arg.getBytesSent(), getBytesReceived()
063: + arg.getBytesReceived(), getThroughputReceiving()
064: + arg.getThroughputReceiving(), getTransfersReceiving()
065: + arg.getTransfersReceiving(), getThroughputSending()
066: + arg.getThroughputSending(), getTransfersSending()
067: + arg.getTransfersSending());
068: }
069:
070: public long getBytesReceived() {
071: return _bytesReceived;
072: }
073:
074: public long getBytesSent() {
075: return _bytesSent;
076: }
077:
078: public long getDiskSpaceAvailable() {
079: return _diskStatus.getBytesAvailable();
080: }
081:
082: public long getDiskSpaceCapacity() {
083: return _diskStatus.getBytesCapacity();
084: }
085:
086: public long getDiskSpaceUsed() {
087: return getDiskSpaceCapacity() - getDiskSpaceAvailable();
088: }
089:
090: public int getThroughput() {
091: return _throughputReceiving + _throughputSending;
092: }
093:
094: public int getThroughputReceiving() {
095: return _throughputReceiving;
096: }
097:
098: public int getThroughputSending() {
099: return _throughputSending;
100: }
101:
102: public int getTransfers() {
103: return _transfersReceiving + _transfersSending;
104: }
105:
106: public int getTransfersReceiving() {
107: return _transfersReceiving;
108: }
109:
110: public int getTransfersSending() {
111: return _transfersSending;
112: }
113:
114: public String toString() {
115: return "[SlaveStatus [diskSpaceAvailable: "
116: + _diskStatus.getBytesAvailable() + "][receiving: "
117: + _throughputReceiving + " bps, " + _transfersSending
118: + " streams][sending: " + _throughputSending + " bps, "
119: + _transfersReceiving + " streams]]";
120: }
121:
122: public int getThroughputDirection(char c) {
123: switch (c) {
124: case Transfer.TRANSFER_RECEIVING_UPLOAD:
125: return getThroughputReceiving();
126:
127: case Transfer.TRANSFER_SENDING_DOWNLOAD:
128: return getThroughputSending();
129:
130: case Transfer.TRANSFER_THROUGHPUT:
131: return getThroughput();
132:
133: default:
134: throw new IllegalArgumentException();
135: }
136: }
137: }
|