本文整理汇总了Java中net.floodlightcontroller.counter.ICounter.getCounterDate方法的典型用法代码示例。如果您正苦于以下问题:Java ICounter.getCounterDate方法的具体用法?Java ICounter.getCounterDate怎么用?Java ICounter.getCounterDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.counter.ICounter
的用法示例。
在下文中一共展示了ICounter.getCounterDate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPktInRate
import net.floodlightcontroller.counter.ICounter; //导入方法依赖的package包/类
protected int getPktInRate(ICounter newCnt, Date currentTime) {
if (newCnt == null ||
newCnt.getCounterDate() == null ||
newCnt.getCounterValue() == null) {
return 0;
}
// Somehow the system time is messed up. return max packetIn rate
// to reduce the system load.
if (newCnt.getCounterDate().before(
lastPacketInCounter.getCounterDate())) {
logger.debug("Time is going backward. new {}, old {}",
newCnt.getCounterDate(),
lastPacketInCounter.getCounterDate());
return MAX_SYSTEM_LOAD_PER_SECOND;
}
long elapsedTimeInSecond = (currentTime.getTime() -
lastPacketInCounter.getCounterDate().getTime()) / 1000;
if (elapsedTimeInSecond == 0) {
// This should never happen. Check to avoid division by zero.
return 0;
}
long diff = 0;
switch (newCnt.getCounterValue().getType()) {
case LONG:
long newLong = newCnt.getCounterValue().getLong();
long oldLong = lastPacketInCounter.getCounterValue().getLong();
if (newLong < oldLong) {
// Roll over event
diff = Long.MAX_VALUE - oldLong + newLong;
} else {
diff = newLong - oldLong;
}
break;
case DOUBLE:
double newDouble = newCnt.getCounterValue().getDouble();
double oldDouble = lastPacketInCounter.getCounterValue().getDouble();
if (newDouble < oldDouble) {
// Roll over event
diff = (long)(Double.MAX_VALUE - oldDouble + newDouble);
} else {
diff = (long)(newDouble - oldDouble);
}
break;
}
return (int)(diff/elapsedTimeInSecond);
}