Package org.ametys.plugins.syndication
Class FeedCache
- java.lang.Object
 - 
- org.apache.avalon.framework.logger.AbstractLogEnabled
 - 
- org.ametys.plugins.syndication.FeedCache
 
 
 
- 
- All Implemented Interfaces:
 Initializable,Component,LogEnabled
public class FeedCache extends AbstractLogEnabled implements Component, Initializable
Feed cache, supports preloading multiple feeds in multiple concurrent threads. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFeedCache.FeedCacheLoaderThe feed cache loader, delegates the loading to the component's loadFeed method (to be easily overridable).protected classFeedCache.FeedLoadWorkerRunnable loading an URL into the cache. 
- 
Field Summary
Fields Modifier and Type Field Description protected LoadingCache<String,FeedResult>_cacheThe user information cache.static StringROLEThe component role. 
- 
Constructor Summary
Constructors Constructor Description FeedCache() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CloseableHttpClient_getHttpClient()Build a HttpClient objectFeedResultgetFeed(String feedUrl, int lifeTime)Get a feed.FeedResultgetFeedNoCache(String feedUrl)Get a feed not from the cache.voidinitialize()protected FeedResultloadFeed(String feedUrl)Retrieve a feed's content to store it into the cache.voidpreload(Collection<String> feeds)Pre-load a collection of feeds, one by thread, to avoid getting timeouts sequentially.- 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger 
 - 
 
 - 
 
- 
- 
Field Detail
- 
_cache
protected LoadingCache<String,FeedResult> _cache
The user information cache. 
 - 
 
- 
Constructor Detail
- 
FeedCache
public FeedCache()
 
 - 
 
- 
Method Detail
- 
initialize
public void initialize() throws Exception
- Specified by:
 initializein interfaceInitializable- Throws:
 Exception
 
- 
preload
public void preload(Collection<String> feeds)
Pre-load a collection of feeds, one by thread, to avoid getting timeouts sequentially.- Parameters:
 feeds- the feeds to preload.
 
- 
getFeedNoCache
public FeedResult getFeedNoCache(String feedUrl) throws IOException
Get a feed not from the cache.- Parameters:
 feedUrl- the feed.- Returns:
 - the feed result.
 - Throws:
 IOException- if an error occurs while loading the feed
 
- 
getFeed
public FeedResult getFeed(String feedUrl, int lifeTime)
Get a feed.- Parameters:
 feedUrl- the feed.lifeTime- the amount of date or time to be added to the field- Returns:
 - the feed response.
 
 
- 
_getHttpClient
protected CloseableHttpClient _getHttpClient()
Build a HttpClient object- Returns:
 - The HttpClient object
 
 
- 
loadFeed
protected FeedResult loadFeed(String feedUrl) throws IOException
Retrieve a feed's content to store it into the cache.- Parameters:
 feedUrl- the feed to load.- Returns:
 - the feed content.
 - Throws:
 IOException- if an error occurs with theHttpURLConnection
 
 - 
 
 -