List of all members.
Detailed Description
This class can be used as a convenient map that keeps RepeatGuard objects associated with String IDs
. For example, if your application repeatedly sends an event related to the unavailability of some component, and you want to limit these events on a per-component basis, then you either need to keep and use a separate RepeatGuard object for every component instance, or alternatively you can use one instance of MultipleRepeatGuard
and take the component names as ID
s.
The additional benefit is that this class optionally offers a bounded cache for the various RepeatGuards, which limits memory consumption for cases in which the number of possible IDs is large, e.g. if the ID is the log message coming from unknown / 3rd party source. The drawback is that the least accessed RepeatGuards will be removed internally when the cache is full and will be re-created upon access, which may distort the original guarding behavior (e.g. because the first check() of the re-created RepeatGuard always returns true, even if the old RepeatGuard object would have returned false for another 100 invocations, or because RepeatGuard.counterAtLastExecution()} will not be accurate.
- Author:
- hsommer
- Since:
- ACS 8.0.0
Constructor & Destructor Documentation
alma.acs.logging.MultipleRepeatGuard.MultipleRepeatGuard |
( |
long |
interval, |
|
|
TimeUnit |
timeUnit, |
|
|
int |
maxRepetitions, |
|
|
Logic |
logic, |
|
|
int |
maxCacheSize | |
|
) |
| | |
Constructor for a MultipleRepeatGuard
with a bounded RepeatGuard cache.
The first 4 parameters are the same as in RepeatGuard#RepeatGuard(long, TimeUnit, int, Logic) and are used as defaults for all RepeatGuards created by this class. To change these values for particular RepeatGuards, use setRepeatGuard(String, RepeatGuard) using a new RepeatGuard object or the one obtained beforehand from getRepeatGuard(String).
- Parameters:
-
| interval | Time interval (in timeUnit units). |
| timeUnit | Time unit of interval parameter. |
| maxRepetitions | Maximum number of repetitions. |
| logic | Evaluation logic for interval and maxRepetitions . The logic will be "reduced" automatically if interval or maxRepetitions have a value <= 0, so as to be based only on the other positive value. |
| maxCacheSize | Number of ID s (as used in check(String)) whose repetition we'll keep track of. Setting this value higher will use more memory; setting it lower than the actual number of IDs will result in unnecessary execution of the guarded actions, as the matching RepeatGuard s will be lost and re-created. |
- Exceptions:
-
| IllegalArgumentException | if maxRepetitions <= 0 && interval <= 0 |
alma.acs.logging.MultipleRepeatGuard.MultipleRepeatGuard |
( |
long |
interval, |
|
|
TimeUnit |
timeUnit, |
|
|
int |
maxRepetitions, |
|
|
Logic |
logic | |
|
) |
| | |
Member Function Documentation
synchronized boolean alma.acs.logging.MultipleRepeatGuard.check |
( |
String |
ID |
) |
|
synchronized boolean alma.acs.logging.MultipleRepeatGuard.checkAndIncrement |
( |
String |
ID |
) |
|
synchronized void alma.acs.logging.MultipleRepeatGuard.clearCache |
( |
|
) |
|
synchronized int alma.acs.logging.MultipleRepeatGuard.counter |
( |
String |
ID |
) |
|
synchronized int alma.acs.logging.MultipleRepeatGuard.counterAtLastExecution |
( |
String |
ID |
) |
|
int alma.acs.logging.MultipleRepeatGuard.getCacheSize |
( |
|
) |
|
Gets the actual number of RepeatGuards in the internal cache, regardless of whether there is an upper limit and whether it has been reached etc.
synchronized RepeatGuard alma.acs.logging.MultipleRepeatGuard.getRepeatGuard |
( |
String |
ID |
) |
|
synchronized boolean alma.acs.logging.MultipleRepeatGuard.hasRepeatGuard |
( |
String |
ID |
) |
|
synchronized void alma.acs.logging.MultipleRepeatGuard.increment |
( |
String |
ID |
) |
|
void alma.acs.logging.MultipleRepeatGuard.setCacheLimit |
( |
int |
maxEntries |
) |
|
synchronized void alma.acs.logging.MultipleRepeatGuard.setRepeatGuard |
( |
String |
ID, |
|
|
RepeatGuard |
guard | |
|
) |
| | |
The documentation for this class was generated from the following file: