r6880 - dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6880 - dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot
- Date: Thu, 8 Nov 2007 14:33:41 -0600 (CST)
Author: walters
Date: 2007-11-08 14:33:40 -0600 (Thu, 08 Nov 2007)
New Revision: 6880
Modified:
dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot/Bot.java
Log:
Move checkRateLimit into a separate function to get synchronization
around the recentConversations map.
Modified: dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot/Bot.java
===================================================================
--- dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot/Bot.java 2007-11-08 18:48:16 UTC (rev 6879)
+++ dumbhippo/trunk/imbot/src/java/com/dumbhippo/aimbot/Bot.java 2007-11-08 20:33:40 UTC (rev 6880)
@@ -190,24 +190,8 @@
if (client == null)
return;
- BuddyRecentConversation lastConversation = recentConversations.get(buddy);
- long curTime = new Date().getTime();
- if (lastConversation == null) {
- lastConversation = new BuddyRecentConversation(curTime);
- recentConversations.put(buddy, lastConversation);
- } else {
- if ((curTime - lastConversation.endTime)/1000 > RECENT_CONVERSATION_EXPIRY_SECS) {
- lastConversation = new BuddyRecentConversation(curTime);
- recentConversations.put(buddy, lastConversation);
- } else {
- lastConversation.count += 1;
- lastConversation.endTime = curTime;
- if (lastConversation.count > RECENT_CONVERSATION_CUTOFF_COUNT) {
- logger.debug("conversation count " + lastConversation.count + " is larger than cuttoff, dropping message");
- return;
- }
- }
- }
+ if (!checkRateLimit(buddy))
+ return;
/* send them the intro message if we haven't already done so recently */
sayIdentification(buddy, false);
@@ -350,6 +334,28 @@
}
}
+ private synchronized boolean checkRateLimit(Buddy buddy) {
+ BuddyRecentConversation lastConversation = recentConversations.get(buddy);
+ long curTime = new Date().getTime();
+ if (lastConversation == null) {
+ lastConversation = new BuddyRecentConversation(curTime);
+ recentConversations.put(buddy, lastConversation);
+ } else {
+ if ((curTime - lastConversation.endTime)/1000 > RECENT_CONVERSATION_EXPIRY_SECS) {
+ lastConversation = new BuddyRecentConversation(curTime);
+ recentConversations.put(buddy, lastConversation);
+ } else {
+ lastConversation.count += 1;
+ lastConversation.endTime = curTime;
+ if (lastConversation.count > RECENT_CONVERSATION_CUTOFF_COUNT) {
+ logger.debug("conversation count " + lastConversation.count + " is larger than cuttoff, dropping message");
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
private void sayBusyThinking(Buddy buddy) {
Client client = aim;
logger.debug("saying we're thinking to " + buddy.getName());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]