Add the reception of the given message to time-limited count.
CountData data = (CountData)message_counts.get( message_id );
if( data == null ) { //new message
data = new CountData( max_counts, time_limit_ms );
message_counts.put( message_id, data );
}
long now = SystemTime.getCurrentTime();
data.counts.addLast( new Long( now ) );
if( data.counts.size() > data.max_counts ) { //we've potentially reached our count limit
long cutoff = now - data.time_limit;
//prune out any expired counts
for( Iterator it = data.counts.iterator(); it.hasNext(); ) {
long time = ((Long)it.next()).longValue();
if( time < cutoff ) { //this count is older than the limit allows
it.remove(); //drop it
}
else { //still within limit
break;
}
}
if( data.counts.size() > data.max_counts ) { //too many counts within the time limit
return false; //return error
}
}
return true;