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 class
FeedCache.FeedCacheLoader
The feed cache loader, delegates the loading to the component's loadFeed method (to be easily overridable).protected class
FeedCache.FeedLoadWorker
Runnable loading an URL into the cache.
-
Field Summary
Fields Modifier and Type Field Description protected LoadingCache<String,FeedResult>
_cache
The user information cache.static String
ROLE
The 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 objectFeedResult
getFeed(String feedUrl, int lifeTime)
Get a feed.FeedResult
getFeedNoCache(String feedUrl)
Get a feed not from the cache.void
initialize()
protected FeedResult
loadFeed(String feedUrl)
Retrieve a feed's content to store it into the cache.void
preload(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:
initialize
in 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
-
-