1 2 23 24 package net.fenyo.gnetwatch.data; 25 26 import net.fenyo.gnetwatch.*; 27 import net.fenyo.gnetwatch.targets.*; 28 29 import java.util.*; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 34 40 41 public class EventFlood extends EventGeneric { 42 private static Log log = LogFactory.getLog(EventFlood.class); 43 44 private final long bytes_sent; 45 46 private long cache_operand_1 = 0; 47 private long cache_operand_2 = 0; 48 private int cache_result = 0; 49 50 54 public EventFlood(final long bytes_sent) { 56 this.bytes_sent = bytes_sent; 57 } 58 59 65 public int getIntValue(final java.util.List <EventGeneric> events, final int idx) { 66 if (idx == 0) return 0; 67 68 final EventFlood prev_event = (EventFlood) events.get(idx - 1); 69 70 if (getDate().getTime() - prev_event.getDate().getTime() == 0) 71 return 0; 72 73 if (getBytesSent() == cache_operand_1 && 74 getDate().getTime() - prev_event.getDate().getTime() == cache_operand_2) { 75 return cache_result; 76 } 77 78 final int ret = (int) (8 * 1000 * (double) getBytesSent() / 80 (getDate().getTime() - prev_event.getDate().getTime())); 81 82 cache_operand_1 = getBytesSent(); 83 cache_operand_2 = getDate().getTime() - prev_event.getDate().getTime(); 84 cache_result = ret; 85 86 return ret; 87 } 88 89 94 public long getBytesSent() { 96 return bytes_sent; 97 } 98 } 99 | Popular Tags |