-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged SavedKey shared between Inmemory and Hazelcast ratelimiters
- Loading branch information
Showing
6 changed files
with
45 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
ratelimitj-inmemory/src/main/java/es/moki/ratelimitj/inmemory/SavedKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package es.moki.ratelimitj.inmemory; | ||
|
||
import java.util.OptionalInt; | ||
|
||
public class SavedKey { | ||
|
||
public final long blockId; | ||
public final long blocks; | ||
public final long trimBefore; | ||
public final String countKey; | ||
public final String tsKey; | ||
|
||
public SavedKey(long now, int duration, OptionalInt precisionOpt) { | ||
|
||
int precision = precisionOpt.orElse(duration); | ||
precision = Math.min(precision, duration); | ||
|
||
this.blocks = (long) Math.ceil(duration / (double) precision); | ||
this.blockId = (long) Math.floor(now / (double) precision); | ||
this.trimBefore = blockId - blocks + 1; | ||
this.countKey = "" + duration + ':' + precision + ':'; | ||
this.tsKey = countKey + 'o'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters