1 18 package net.sf.drftpd.slave; 19 20 import java.io.Serializable ; 21 22 26 public class SlaveStatus implements Serializable { 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 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 (); 149 } 150 } 151 } 152 | Popular Tags |