gr.iti.mklab.sfc.streams.impl.TumblrStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mklab-stream-manager Show documentation
Show all versions of mklab-stream-manager Show documentation
Monitors a set of social streams (e.g. Twitter status updates) and collects the incoming content.
The newest version!
package gr.iti.mklab.sfc.streams.impl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import gr.iti.mklab.framework.Credentials;
import gr.iti.mklab.framework.common.domain.Source;
import gr.iti.mklab.framework.common.domain.config.Configuration;
import gr.iti.mklab.framework.retrievers.impl.TumblrRetriever;
import gr.iti.mklab.sfc.streams.Stream;
import gr.iti.mklab.sfc.streams.StreamException;
import gr.iti.mklab.sfc.streams.monitors.RateLimitsMonitor;
/**
* Class responsible for setting up the connection to Tumblr API
* for retrieving relevant Tumblr content.
* @author ailiakop
*/
public class TumblrStream extends Stream {
public static final Source SOURCE = Source.Tumblr;
private String consumerKey;
private String consumerSecret;
private Logger logger = LogManager.getLogger(TumblrStream.class);
@Override
public void open(Configuration config) throws StreamException {
logger.info("#Tumblr : Open stream");
if (config == null) {
logger.error("#Tumblr : Config file is null.");
return;
}
consumerKey = config.getParameter(KEY);
consumerSecret = config.getParameter(SECRET);
if (consumerKey == null || consumerSecret==null) {
logger.error("#Tumblr : Stream requires authentication.");
throw new StreamException("Stream requires authentication.");
}
Credentials credentials = new Credentials();
credentials.setKey(consumerKey);
credentials.setSecret(consumerSecret);
maxRequests = Integer.parseInt(config.getParameter(MAX_REQUESTS));
timeWindow = Long.parseLong(config.getParameter(TIME_WINDOW));
rateLimitsMonitor = new RateLimitsMonitor(maxRequests, timeWindow);
retriever = new TumblrRetriever(credentials);
}
@Override
public String getName() {
return SOURCE.name();
}
}