Package org.codelibs.fess.helper
Class CrawlerStatsHelper
java.lang.Object
org.codelibs.fess.helper.CrawlerStatsHelper
Helper class for managing crawler statistics and performance metrics.
This class provides functionality to track, record, and report statistics
about crawler operations including timing data, performance metrics, and
operational events. It uses an internal cache to maintain statistics
objects and provides methods to begin tracking, record events, and
finalize statistics collection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of predefined statistics actions that can be recorded during crawler operations.static classKey object for statistics tracking that contains an identifier and optional URL.static classStatistics data object that stores timestamped events and maintains reference counting. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longTime in milliseconds after which cache entries expire after write.protected StringName of the logger used for statistics output.protected longMaximum number of statistics objects to cache.protected com.google.common.cache.LoadingCache<String, CrawlerStatsHelper.StatsObject> Cache for storing statistics objects keyed by crawler object identifiers.protected org.apache.logging.log4j.LoggerLogger instance specifically for outputting crawler statistics. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBegins statistics tracking for the specified crawler object.voiddestroy()Cleanup method called when the helper is being destroyed.voidDiscards statistics tracking for the specified crawler object.voidMarks statistics tracking as complete for the specified crawler object.protected StringescapeValue(String action) Escapes special characters in a value string for safe logging.protected org.dbflute.optional.OptionalThing<String> getCacheKey(Object keyObj) Generates a cache key from a crawler object.protected longGets the current system time in milliseconds.protected StringExtracts the URL string from a crawler object for logging purposes.voidinit()Initializes the crawler statistics helper.protected voidlog(StringBuilder buf) Outputs a log message using the statistics logger.protected voidprintStats(Object keyObj, CrawlerStatsHelper.StatsObject data, long begin, boolean done) Outputs statistics information for a crawler object.voidRecords a custom statistics action for the specified crawler object.voidrecord(Object keyObj, CrawlerStatsHelper.StatsAction action) Records a statistics action for the specified crawler object.voidrunOnThread(Object keyObj) Increments the thread reference count for the specified crawler object.voidsetCacheExpireAfterWrite(long cacheExpireAfterWrite) Sets the cache expiration time after write in milliseconds.voidsetLoggerName(String loggerName) Sets the name of the logger used for statistics output.voidsetMaxCacheSize(long maxCacheSize) Sets the maximum number of statistics objects to cache.
-
Field Details
-
statsLogger
protected org.apache.logging.log4j.Logger statsLoggerLogger instance specifically for outputting crawler statistics. -
loggerName
Name of the logger used for statistics output. -
maxCacheSize
protected long maxCacheSizeMaximum number of statistics objects to cache. -
cacheExpireAfterWrite
protected long cacheExpireAfterWriteTime in milliseconds after which cache entries expire after write. -
statsCache
Cache for storing statistics objects keyed by crawler object identifiers.
-
-
Constructor Details
-
CrawlerStatsHelper
public CrawlerStatsHelper()Creates a new instance of CrawlerStatsHelper.
-
-
Method Details
-
init
@PostConstruct public void init()Initializes the crawler statistics helper. Sets up the statistics logger and creates the cache for storing statistics objects with the configured size and expiration settings. -
destroy
@PreDestroy public void destroy()Cleanup method called when the helper is being destroyed. Logs cache statistics and processes any remaining statistics objects in the cache before shutdown. -
begin
Begins statistics tracking for the specified crawler object. Creates a new statistics object in the cache and starts timing.- Parameters:
keyObj- the crawler object to track (UrlQueue, StatsKeyObject, String, or Number)
-
record
Records a statistics action for the specified crawler object.- Parameters:
keyObj- the crawler object being trackedaction- the statistics action to record
-
record
Records a custom statistics action for the specified crawler object.- Parameters:
keyObj- the crawler object being trackedaction- the custom action name to record
-
done
Marks statistics tracking as complete for the specified crawler object. Decrements the reference count and if it reaches zero, removes the statistics object from cache and outputs the final statistics.- Parameters:
keyObj- the crawler object to complete tracking for
-
discard
Discards statistics tracking for the specified crawler object. Removes the statistics object from cache without outputting statistics.- Parameters:
keyObj- the crawler object to discard tracking for
-
printStats
protected void printStats(Object keyObj, CrawlerStatsHelper.StatsObject data, long begin, boolean done) Outputs statistics information for a crawler object.- Parameters:
keyObj- the crawler object the statistics relate todata- the statistics data to outputbegin- the timestamp when tracking begandone- whether tracking was completed normally
-
runOnThread
Increments the thread reference count for the specified crawler object. Used when the same object is being processed on multiple threads.- Parameters:
keyObj- the crawler object running on an additional thread
-
getCurrentTimeMillis
protected long getCurrentTimeMillis()Gets the current system time in milliseconds.- Returns:
- current time in milliseconds
-
getUrl
Extracts the URL string from a crawler object for logging purposes.- Parameters:
keyObj- the crawler object to extract URL from- Returns:
- the URL string or a default value if not extractable
-
getCacheKey
Generates a cache key from a crawler object.- Parameters:
keyObj- the crawler object to generate key for- Returns:
- Optional cache key string, empty if object type not supported
-
escapeValue
Escapes special characters in a value string for safe logging.- Parameters:
action- the string value to escape- Returns:
- the escaped string with tabs replaced by spaces
-
log
Outputs a log message using the statistics logger.- Parameters:
buf- the string buffer containing the log message
-
setLoggerName
Sets the name of the logger used for statistics output.- Parameters:
loggerName- the logger name to use
-
setMaxCacheSize
public void setMaxCacheSize(long maxCacheSize) Sets the maximum number of statistics objects to cache.- Parameters:
maxCacheSize- the maximum cache size
-
setCacheExpireAfterWrite
public void setCacheExpireAfterWrite(long cacheExpireAfterWrite) Sets the cache expiration time after write in milliseconds.- Parameters:
cacheExpireAfterWrite- the expiration time in milliseconds
-