com::cosylab::logging::engine::ACS::ACSLogRetrieval Class Reference

Inheritance diagram for com::cosylab::logging::engine::ACS::ACSLogRetrieval:
Inheritance graph
[legend]
Collaboration diagram for com::cosylab::logging::engine::ACS::ACSLogRetrieval:
Collaboration graph
[legend]

List of all members.

Classes

class  RateUpdater

Public Member Functions

 ACSLogRetrieval (ACSListenersDispatcher listenersDispatcher, boolean binFormat)
 ACSLogRetrieval (ACSListenersDispatcher listenersDispatcher, boolean binFormat, FiltersVector filters)
 ACSLogRetrieval (ACSListenersDispatcher listenersDispatcher, boolean binFormat, FiltersVector filters, IResourceChecker resCecker)
void addLog (String XMLLogStr)
void run ()
void pause (boolean pause)
void close (boolean sync)
boolean hasPendingEntries ()
int size ()
int getInputRate ()
int getOutputRate ()
int getMaxInputRate ()
void setMaxInputRate (int maxInRate)
int getMaxOutputRate ()
void setMaxOutputRate (int maxOutRate)
void enableDynamicDiscarding (int threshold, int damping, int interval)
void setDiscardLevel (LogTypeHelper newLevel)
LogTypeHelper getDiscardLevel ()

Private Member Functions

void initialize ()
void publishLog (String xmlLog, ILogEntry log)
void checkMemory (long freeMem)

Private Attributes

ACSListenersDispatcher listenersDispatcher = null
volatile boolean paused = false
volatile boolean terminateThread = false
volatile boolean closed = false
ACSLogParser parser = null
boolean binaryFormat
EngineCache cache = new EngineCache()
Thread thread
Timer timerThread
int maxInputRate = Integer.MAX_VALUE
volatile int inputRate = 0
volatile int receivedCounter
int maxOutputRate = Integer.MAX_VALUE
volatile int outputRate = 0
volatile int readCounter
int threshold
int damping
int dynamicDiscardingTime = 10
long lastDiscardingUpdateTime
LogTypeHelper userDiscardLevel = null
IResourceChecker resourceChecker = new ResourceChecker()

Static Private Attributes

static final int DELAY_NUMBER = 1000

Detailed Description

ACSLogRetrieval stores the XML string (or a String in case of binary logs) representing logs on a file when the engine is not able to follow the flow of the incoming logs The strings are stored on disk and the logs published to the listeners when there is enough CPU available.

ACSLogRetrieval allows to set the rate (i.e. number of logs per second) for the logs to receive and push in cache. All the logs received after this limit has been reached are discarded regardless of their content. This option must be used very carefully because can cause loss of logs.

It also allows to set the rate i.e. number of logs per second) for the logs read from the cache and published to listener. When the limit has been reached, no logs are pushed anymore out of the cache until the current second has elapsed. This limitation must be used very carefully because it can cause a uncontrolled growth of the cache that could lead to an out of memory.
By default, the input and output rates are unlimited (Integer.MAX_VALUE)

The available memory is checked every second. To avoid out of memory the user can enable the dynamic discarding by giving a threshold (in bytes). If a threshold is defined, the thread that checks the amount of available memory increases the discard level. To avoid oscillations, the user can define a a damping factor: the discard level is decreased when the amount of available memory is greater the the threshold plus the damping.

See also:
ACSRemoteLogListener
ACSRemoteRawLogListener
ACSLogConnectionListener

Constructor & Destructor Documentation

com::cosylab::logging::engine::ACS::ACSLogRetrieval::ACSLogRetrieval ( ACSListenersDispatcher  listenersDispatcher,
boolean  binFormat 
) [inline]

Constructor

Parameters:
listenersDispatcher The object to send messages to the listeners Can't be null
binFormat true if the lags are binary, false if XML format is used

References binaryFormat, and initialize().

com::cosylab::logging::engine::ACS::ACSLogRetrieval::ACSLogRetrieval ( ACSListenersDispatcher  listenersDispatcher,
boolean  binFormat,
FiltersVector  filters 
) [inline]

Constructor

Parameters:
listenersDispatcher The object to send messages to the listeners Can't be null
binFormat true if the lags are binary, false if XML format is used
filters The filters to apply to incoming logs If null or empty no filters are applied

References com::cosylab::logging::engine::LogMatcher::setFilters().

com::cosylab::logging::engine::ACS::ACSLogRetrieval::ACSLogRetrieval ( ACSListenersDispatcher  listenersDispatcher,
boolean  binFormat,
FiltersVector  filters,
IResourceChecker  resCecker 
) [inline]

A construct that allow passing a ResourceChecker.

This is mostly intended for testing purposes to simulate overloading or memory consumption.

Parameters:
listenersDispatcher The object to send messages to the listeners Can't be null
binFormat true if the lags are binary, false if XML format is used
filters The filters to apply to incoming logs If null or empty no filters are applied
roCecher 

References binaryFormat, initialize(), resourceChecker, and com::cosylab::logging::engine::LogMatcher::setFilters().


Member Function Documentation

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::addLog ( String  XMLLogStr  )  [inline]
void com::cosylab::logging::engine::ACS::ACSLogRetrieval::checkMemory ( long  freeMem  )  [inline, private]

Check the available memory against the threshold and the damping factor to increase/decrease the discard level.

Parameters:
freeMem The amount of available memory to the application in bytes.

References com::cosylab::logging::engine::LogMatcher::actualDiscardLevel, damping, dynamicDiscardingTime, lastDiscardingUpdateTime, threshold, and userDiscardLevel.

Referenced by com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::close ( boolean  sync  )  [inline]
void com::cosylab::logging::engine::ACS::ACSLogRetrieval::enableDynamicDiscarding ( int  threshold,
int  damping,
int  interval 
) [inline]

Enable dynamic discarding of incoming logs.

Parameters:
threashold The discard level is increased when the available memory for the application is less then the threshold (in bytes). Integer.MAX_VALUE disables this feature.
damping The damping factor is used to avoid oscillations The discard level is decreased when the free memory is is greater then the threshold plus the dumping.
interval The time (in seconds) between two adjustments of the dynamic discard level. interval defaults to 10.
See also:
setDiscardLevel(LogTypeHelper newLevel)

References dynamicDiscardingTime.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::enableDynamicDiscarding(), and alma::acs::jlog::test::LogDispatcherTest::testDynamicDiscardLevel().

LogTypeHelper com::cosylab::logging::engine::ACS::ACSLogRetrieval::getDiscardLevel (  )  [inline]

Return the discard level set by the user

Returns:
the discardLevel
See also:
etDiscardLevel(LogTypeHelper newLevel)

References userDiscardLevel.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::getDiscardLevel(), alma::acs::jlog::test::LogDispatcherTest::testDynamicDiscardLevel(), and alma::acs::jlog::test::LogDispatcherTest::testGetSetDiscardLevel().

int com::cosylab::logging::engine::ACS::ACSLogRetrieval::getInputRate (  )  [inline]

Return the number of strings received in the last second. Note that the number of received strings can be greater then the max number of input strings.

Returns:
The number of strings received in the last second

References inputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::getActualInputRate().

int com::cosylab::logging::engine::ACS::ACSLogRetrieval::getMaxInputRate (  )  [inline]
Returns:
The max number of strings pushed in the cache per second

References maxInputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::getMaxInputRate().

int com::cosylab::logging::engine::ACS::ACSLogRetrieval::getMaxOutputRate (  )  [inline]
Returns:
The maximum number of logs published per second

References maxOutputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::getMaxOutputRate().

int com::cosylab::logging::engine::ACS::ACSLogRetrieval::getOutputRate (  )  [inline]

Return the number of strings read from the cache in the last second limited. It can never be greater then the max rate.

Returns:
The number of strings read from the cache in the last second

References outputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::getActualOutputRate().

boolean com::cosylab::logging::engine::ACS::ACSLogRetrieval::hasPendingEntries (  )  [inline]

Check if there are logs to be published in the cache.

Returns:
true if there are logs to be processed in the file

References cache, and com::cosylab::logging::engine::cache::EngineCache::size().

Referenced by alma::acs::jlog::test::EngineAudienceTest::waitForLogs().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::initialize (  )  [inline, private]

Init the file and the parser

References binaryFormat, parser, thread, and timerThread.

Referenced by ACSLogRetrieval().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::pause ( boolean  pause  )  [inline]

Pause/unpause the thread that publishes logs

Parameters:
pause 

References paused.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::setPaused().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::publishLog ( String  xmlLog,
ILogEntry  log 
) [inline, private]
void com::cosylab::logging::engine::ACS::ACSLogRetrieval::run (  )  [inline]
void com::cosylab::logging::engine::ACS::ACSLogRetrieval::setDiscardLevel ( LogTypeHelper  newLevel  )  [inline]

Set the discard level

Note: if dynamic filtering by memory is enabled then the discard level effectively used can be greater then this value.

Parameters:
newLevel The new discard level (null means no discard level).
See also:
enableDynamicDiscarding(int threashold)
getDiscardLevel()

Reimplemented from com::cosylab::logging::engine::LogMatcher.

References com::cosylab::logging::engine::LogMatcher::actualDiscardLevel, and userDiscardLevel.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::setDiscardLevel(), alma::acs::jlog::test::LogDispatcherTest::testDynamicDiscardLevel(), and alma::acs::jlog::test::LogDispatcherTest::testGetSetDiscardLevel().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::setMaxInputRate ( int  maxInRate  )  [inline]

Set the max number of logs to process per second.

All the logs in a second read after this number has been reached are discarded i.e. never pushed in the cache.

Parameters:
maxInRate The max number of logs per second to push in cache. Integer.MAX_VALUE means unlimited

References maxInputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::setMaxInputRate().

void com::cosylab::logging::engine::ACS::ACSLogRetrieval::setMaxOutputRate ( int  maxOutRate  )  [inline]

Set the max number of logs to read from the cache per second.

All the logs in a second read after this number has been reached are discarded i.e. never published to listeners.

Parameters:
maxOutRate The max number of logs per second to read from cache. Integer.MAX_VALUE means unlimited

References maxOutputRate.

Referenced by com::cosylab::logging::engine::ACS::LCEngine::setMaxOutputRate().

int com::cosylab::logging::engine::ACS::ACSLogRetrieval::size (  )  [inline]

Return the number of entries in the cache

Returns:
the number of entries in the cache

References cache, and com::cosylab::logging::engine::cache::EngineCache::size().

Referenced by alma::acs::jlog::test::EngineAudienceTest::waitForLogs(), and com::cosylab::logging::engine::ACS::LCEngine::waitingLogsNumber().


Member Data Documentation

Referenced by ACSLogRetrieval(), initialize(), and run().

Referenced by addLog(), and close().

damping is used to avoid oscillations in the discard level.

When the available memory is below the threshold, the discard level is immediately increased. To decrease the discard level instead the free memory must be greater then threshold+damping.

damping must be greater or equal to 0.

Referenced by checkMemory().

The time (in seconds) between two adjustments of the dynamic discard level.

Referenced by checkMemory(), and enableDynamicDiscarding().

The number of logs per second pushed in the cache.

This is changed by the thread every second to be equal to receivedCounter

Referenced by getInputRate(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

The time when the dynamic discard level has been updated the last time (msec)

Referenced by checkMemory().

Referenced by addLog(), publishLog(), and run().

The max input rate (i.e. the max number of strings to push in the cache per second.

If the number of logs received in the current second is greater then this number, then the strings are discarded.

Note: maxinputRate should be used carefully because it causes the loss of information

Referenced by addLog(), getMaxInputRate(), and setMaxInputRate().

The max output rate (i.e. the max number of strings to read from in the cache per second).

If the number of logs received in the current second is greater then this number, then the strings are removed from the cache but discarded without being sent to the listener

Note: maxOutputRate should be used carefully because it causes the loss of information

Referenced by getMaxOutputRate(), run(), and setMaxOutputRate().

The number of logs per second popped from the cache

This is changed by the thread every second to be equal to readCounter

Referenced by getOutputRate(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

Referenced by initialize(), and run().

Referenced by pause(), and run().

Counts the number of logs popped every second

Referenced by run(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

Counts the number of logs received every second

Referenced by addLog(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

resourceChecker gets the details of the memory allocation

Referenced by ACSLogRetrieval(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

Referenced by close(), and run().

Referenced by close(), and initialize().

The threshold, in bytes, to dynamically increase the discard level.

The discard level is increased of one step whenever the available memory for the application is greater then this number.

Referenced by checkMemory(), and com::cosylab::logging::engine::ACS::ACSLogRetrieval::RateUpdater::run().

The timer to update the input and output rates

Referenced by close(), and initialize().

The discard level set by the user

Referenced by checkMemory(), getDiscardLevel(), and setDiscardLevel().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2