stateblock NetworkTotalBandwidthCounter augments RNetwork {
requires SystemTime;
addstate RNetwork.sendTimeSlice: int = 0;
addstate RNetwork.receiveTimeSlice: int = 0;
addstate RNetwork.sendByteLimit: int = 1000000;
addstate RNetwork.receiveByteLimit: int = 1000000;
addstate RNetwork.totalByteLimit: int = 1000000;
addstate RNetwork.totalBytesLeft: int = 1000000;
addstate RNetwork.totalStartTime: long = 0;
helper updateTotalTimer () {
if ((RSystem.getCurrentTime () - totalStartTime) > sendTimeSlice) {
util.Message.debugMessage ("Reset total bandwidth timer.");
totalStartTime = RSystem.getCurrentTime();
totalBytesLeft = totalByteLimit;
}
}
precode initialize () {
totalStartTime = RSystem.getCurrentTime ();
}
precode postSend (address: RNetAddress, nbytes: int) {
totalBytesLeft -= nbytes;
}
precode preSend (address: RNetAddress, nbytes: int) {
updateTotalTimer ();
}
precode postReceive (address: RNetAddress, nbytes: int) {
totalBytesLeft -= nbytes;
}
precode preReceive (address: RNetAddress, nbytes: int) {
updateTotalTimer ();
}
}
Naccio Home Page
University of Virginia, Computer Science