Skip to content

Commit

Permalink
mokies#1: Method for checking if over limit w/o updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ctoomey committed Jun 15, 2017
1 parent 2cb665f commit 6a3eb38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public boolean overLimit(String key) {
// TODO support muli keys
@Override
public boolean overLimit(String key, int weight) {
return eqOrGeLimit(key, weight,false);
return eqOrGeLimit(key, weight, false);
}

@Override
public boolean geLimit(String key, int weight) {
return eqOrGeLimit(key, weight,true);
return eqOrGeLimit(key, weight, true);
}

@Override
Expand Down Expand Up @@ -82,6 +82,7 @@ private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater) {
List<SavedKey> savedKeys = new ArrayList<>(rules.size());

IMap<String, Long> hcKeyMap = getMap(key, longestDuration);
boolean geLimit = false;

// TODO perform each rule calculation in parallel
for (RequestLimitRule rule : rules) {
Expand Down Expand Up @@ -129,7 +130,7 @@ private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater) {
if (count > rule.getLimit()) {
return true; // over limit
} else if (!strictlyGreater && count == rule.getLimit()) {
return true; // at limit
geLimit = true; // at limit, do record request
}
}

Expand All @@ -145,6 +146,6 @@ private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater) {

}

return false;
return geLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean overLimit(String key) {
// TODO support muli keys
@Override
public boolean overLimit(String key, int weight) {
return eqOrGeLimit(key, weight,true);
return eqOrGeLimit(key, weight, true);
}

@Override
Expand Down

0 comments on commit 6a3eb38

Please sign in to comment.