@Component(role=Macro.class, hint="snippet") public class SnippetMacro extends AbstractMacro
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
cache
Holds the cache.
|
private boolean |
debug
Debug.
|
private static int |
HOUR |
private boolean |
ignoreDownloadError
in case of Exception during snippet download error will ignored and empty content returned.
|
private static java.util.Map<java.lang.String,java.lang.Long> |
timeCached
Holds the time cache.
|
private long |
timeout
One hour default cache.
|
| Constructor and Description |
|---|
SnippetMacro() |
| Modifier and Type | Method and Description |
|---|---|
void |
cacheSnippet(java.net.URL url,
java.lang.String id,
java.lang.String content)
Puts the given snippet into the cache.
|
void |
execute(Sink sink,
MacroRequest request)
Execute the current macro using the given MacroRequest,
and emit events into the given sink.
|
private java.lang.String |
getCachedSnippet(java.net.URL url,
java.lang.String id)
Return a snippet from the cache.
|
private java.lang.StringBuffer |
getSnippet(java.net.URL url,
java.lang.String encoding,
java.lang.String id)
Return a snippet of the given url.
|
(package private) long |
getTimeCached(java.net.URL url,
java.lang.String id)
Return the absolute value of when the snippet has been cached.
|
private java.lang.String |
globalSnippetId(java.net.URL url,
java.lang.String id)
Return a global identifier for the snippet.
|
(package private) boolean |
isCacheTimedout(java.net.URL url,
java.lang.String id)
Return true if the snippet has been cached longer than
the current timeout.
|
private void |
removeFromCache(java.net.URL url,
java.lang.String id)
Removes the snippet from the cache.
|
void |
setCacheTimeout(int time)
Set the cache timeout.
|
(package private) long |
timeInCache(java.net.URL url,
java.lang.String id)
Return the time the snippet has been cached.
|
enableLogging, getAttributesFromMap, getLog, requiredprivate static java.util.Map<java.lang.String,java.lang.String> cache
private static final int HOUR
private long timeout
private static java.util.Map<java.lang.String,java.lang.Long> timeCached
private boolean debug
private boolean ignoreDownloadError
public void execute(Sink sink, MacroRequest request) throws MacroExecutionException
sink - The sink to receive the events.request - The corresponding MacroRequest.MacroExecutionException - if an error occurred during execution.private java.lang.StringBuffer getSnippet(java.net.URL url,
java.lang.String encoding,
java.lang.String id)
throws java.io.IOException
url - The URL to parse.encoding - The encoding of the URL to parse.id - The id of the snippet.java.io.IOException - if something goes wrong.private java.lang.String getCachedSnippet(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.boolean isCacheTimedout(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.long timeInCache(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.long getTimeCached(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.private void removeFromCache(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.private java.lang.String globalSnippetId(java.net.URL url,
java.lang.String id)
url - The URL to parse.id - The id of the snippet.public void cacheSnippet(java.net.URL url,
java.lang.String id,
java.lang.String content)
url - The URL to parse.id - The id of the snippet.content - The content of the snippet.public void setCacheTimeout(int time)
time - The timeout to set.