
Classes | |
| class | BoundedHashMap< K, V > |
Public Member Functions | |
| MultipleRepeatGuard (long interval, TimeUnit timeUnit, int maxRepetitions, Logic logic, int maxCacheSize) | |
| MultipleRepeatGuard (long interval, TimeUnit timeUnit, int maxRepetitions, Logic logic) | |
| synchronized boolean | check (String ID) |
| synchronized boolean | checkAndIncrement (String ID) |
| synchronized void | increment (String ID) |
| synchronized int | counter (String ID) |
| synchronized int | counterAtLastExecution (String ID) |
| boolean | hasRepeatGuard (String ID) |
| RepeatGuard | getRepeatGuard (String ID) |
| synchronized void | setRepeatGuard (String ID, RepeatGuard guard) |
| int | getCacheSize () |
| synchronized void | clearCache () |
| void | setCacheLimit (int maxEntries) |
Private Member Functions | |
| synchronized RepeatGuard | getOrCreateRepeatGuard (String ID) |
Private Attributes | |
| final long | defaultInterval |
| final TimeUnit | defaultTimeUnit |
| final int | defaultMaxRepetitions |
| final Logic | defaultLogic |
| final BoundedHashMap< String, RepeatGuard > | guards |
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 IDs.
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.
| alma::acs::logging::MultipleRepeatGuard::MultipleRepeatGuard | ( | long | interval, | |
| TimeUnit | timeUnit, | |||
| int | maxRepetitions, | |||
| Logic | logic, | |||
| int | maxCacheSize | |||
| ) | [inline] |
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).
| 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 IDs (as used in ..) 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 RepeatGuards will be lost and re-created. |
| IllegalArgumentException | if maxRepetitions <= 0 && interval <= 0 |
References defaultInterval, defaultLogic, defaultMaxRepetitions, defaultTimeUnit, and guards.
| alma::acs::logging::MultipleRepeatGuard::MultipleRepeatGuard | ( | long | interval, | |
| TimeUnit | timeUnit, | |||
| int | maxRepetitions, | |||
| Logic | logic | |||
| ) | [inline] |
Constructor for a MultipleRepeatGuard without a bounded RepeatGuard cache (which means that memory limits indirectly set the bound, with possible side effects).
| synchronized boolean alma::acs::logging::MultipleRepeatGuard::check | ( | String | ID | ) | [inline] |
References alma::acs::logging::RepeatGuard::check(), and getOrCreateRepeatGuard().
| synchronized boolean alma::acs::logging::MultipleRepeatGuard::checkAndIncrement | ( | String | ID | ) | [inline] |
References alma::acs::logging::RepeatGuard::checkAndIncrement(), and getOrCreateRepeatGuard().
Referenced by com::cosylab::cdb::jdal::DALImpl::logRecordNotExistWithRepeatGuard().
| synchronized void alma::acs::logging::MultipleRepeatGuard::clearCache | ( | ) | [inline] |
References guards.
| synchronized int alma::acs::logging::MultipleRepeatGuard::counter | ( | String | ID | ) | [inline] |
References alma::acs::logging::RepeatGuard::counter, and getOrCreateRepeatGuard().
| synchronized int alma::acs::logging::MultipleRepeatGuard::counterAtLastExecution | ( | String | ID | ) | [inline] |
Note that depending on the RepeatGuard cache limit, the RepeatGuard for the given ID may get re-created during this call, and thus the counter may be 0 even though the old "true" counter was > 0.
References alma::acs::logging::RepeatGuard::counterAtLastExecution, and getOrCreateRepeatGuard().
Referenced by com::cosylab::cdb::jdal::DALImpl::logRecordNotExistWithRepeatGuard().
| int alma::acs::logging::MultipleRepeatGuard::getCacheSize | ( | ) | [inline] |
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.
References guards.
| synchronized RepeatGuard alma::acs::logging::MultipleRepeatGuard::getOrCreateRepeatGuard | ( | String | ID | ) | [inline, private] |
References defaultInterval, defaultLogic, defaultMaxRepetitions, defaultTimeUnit, and guards.
Referenced by check(), checkAndIncrement(), counter(), counterAtLastExecution(), getRepeatGuard(), and increment().
| RepeatGuard alma::acs::logging::MultipleRepeatGuard::getRepeatGuard | ( | String | ID | ) | [inline] |
References getOrCreateRepeatGuard().
| boolean alma::acs::logging::MultipleRepeatGuard::hasRepeatGuard | ( | String | ID | ) | [inline] |
References guards.
| synchronized void alma::acs::logging::MultipleRepeatGuard::increment | ( | String | ID | ) | [inline] |
References getOrCreateRepeatGuard(), and alma::acs::logging::RepeatGuard::increment().
| void alma::acs::logging::MultipleRepeatGuard::setCacheLimit | ( | int | maxEntries | ) | [inline] |
References guards.
| synchronized void alma::acs::logging::MultipleRepeatGuard::setRepeatGuard | ( | String | ID, | |
| RepeatGuard | guard | |||
| ) | [inline] |
Sets a possibly modified RepeatGuard for the given ID, which allows for some RepeatGuards having different settings than those passed in MultipleRepeatGuard(long, TimeUnit, int, Logic, int).
| ID | ||
| guard |
References guards.
final long alma::acs::logging::MultipleRepeatGuard::defaultInterval [private] |
Referenced by getOrCreateRepeatGuard(), and MultipleRepeatGuard().
final Logic alma::acs::logging::MultipleRepeatGuard::defaultLogic [private] |
Referenced by getOrCreateRepeatGuard(), and MultipleRepeatGuard().
final int alma::acs::logging::MultipleRepeatGuard::defaultMaxRepetitions [private] |
Referenced by getOrCreateRepeatGuard(), and MultipleRepeatGuard().
final TimeUnit alma::acs::logging::MultipleRepeatGuard::defaultTimeUnit [private] |
Referenced by getOrCreateRepeatGuard(), and MultipleRepeatGuard().
final BoundedHashMap<String, RepeatGuard> alma::acs::logging::MultipleRepeatGuard::guards [private] |
Referenced by clearCache(), getCacheSize(), getOrCreateRepeatGuard(), hasRepeatGuard(), MultipleRepeatGuard(), setCacheLimit(), and setRepeatGuard().
1.6.2