Classes | Public Member Functions

alma.acs.logging.MultipleRepeatGuard Class Reference

List of all members.

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)
synchronized boolean hasRepeatGuard (String ID)
synchronized RepeatGuard getRepeatGuard (String ID)
synchronized void setRepeatGuard (String ID, RepeatGuard guard)
int getCacheSize ()
synchronized void clearCache ()
void setCacheLimit (int maxEntries)

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 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.

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 IDs (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 RepeatGuards 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 
)

Constructor for a MultipleRepeatGuard without a bounded RepeatGuard cache (which means that memory limits indirectly set the bound, with possible side effects).

See also:
MultipleRepeatGuard(long, TimeUnit, int, Logic, int)

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  ) 

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.

See also:
RepeatGuard.counterAtLastExecution()

Referenced by alma.acs.nc.refactored.NCSubscriber.processEvent().

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 
)

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).

Parameters:
ID 
guard 

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties